{"id":5015,"date":"2014-03-30T17:57:08","date_gmt":"2014-03-30T17:57:08","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/local-variable-needs-to-be-declared-final-collection-of-common-programming-errors\/"},"modified":"2014-03-30T17:57:08","modified_gmt":"2014-03-30T17:57:08","slug":"local-variable-needs-to-be-declared-final-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/local-variable-needs-to-be-declared-final-collection-of-common-programming-errors\/","title":{"rendered":"Local variable needs to be declared final-Collection of common programming errors"},"content":{"rendered":"<p>I&#8217;m receiving the error &#8220;local variable box is accessed from within inner class; needs to be declared final&#8221;. That seems alright, but I don&#8217;t really think it&#8217;s the best solution, so I was hoping maybe someone else can help me out. Here is my code:<\/p>\n<pre><code>public void showPublisherBox(JComboBox box) {\n    if (publisherBox == null) {\n        publisherBox = new AddPublisherForm();\n        publisherBox.setLocationRelativeTo(this);\n    }\n    publisherBox.addWindowListener(new WindowAdapter()\n    {\n    public void windowClosing(WindowEvent we)\n    {\n        this.populatePublishers(box);\n    }\n\n        private void populatePublishers(JComboBox box){\n            box.setModel(db.getPublishers());\n        }\n    });\n    publisherBox.setVisible(true);\n}\n<\/code><\/pre>\n<p>Publisher form is just a new JFrame that opens up and takes in some information, and when it&#8217;s closed I want the JComboBox to be repopulated via setting the model from my db.getPublishers() method.<\/p>\n<p>So is there a better way to do what I&#8217;m doing here, or am I going to have to declare something as final?<\/p>\n<p>Thanks<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m receiving the error &#8220;local variable box is accessed from within inner class; needs to be declared final&#8221;. That seems alright, but I don&#8217;t really think it&#8217;s the best solution, so I was hoping maybe someone else can help me out. Here is my code: public void showPublisherBox(JComboBox box) { if (publisherBox == null) { [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-5015","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5015","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=5015"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5015\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=5015"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=5015"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=5015"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}