{"id":9269,"date":"2020-04-21T10:02:45","date_gmt":"2020-04-21T04:32:45","guid":{"rendered":"https:\/\/java2blog.com\/?p=9269"},"modified":"2023-11-25T18:38:47","modified_gmt":"2023-11-25T13:08:47","slug":"cannot-find-symbol-java","status":"publish","type":"post","link":"https:\/\/java2blog.com\/cannot-find-symbol-java\/","title":{"rendered":"Cannot find symbol Java"},"content":{"rendered":"<p>In this post, we will see how to solve <code>Cannot find symbol<\/code> in java.<\/p>\n<p>You will get this error when you have declared something that compiler does not understand. The compiler creates list of identifiers when you compile any program. If compile can not understand any of the identifiers, you will get this error.<\/p>\n<p>This error generally means the compiler does not recognize any identifier and can not figure out what it means.<\/p>\n<p>Let&#8217;s understand with a very basic example.<\/p>\n<pre class=\"lang:java nums:true decode:1 \"> \npackage org.arpit.java2blog;\n\npublic class CannotFindSymbolMain {\n\n    public static void main(String[] args)\n    {\n        int a = 10;\n        int b = 2;\n\n      division = a\/ b;\n        System.out.println(division);\n    }\n}\n<\/pre>\n<p>You will get below compilation error.<\/p>\n<div class=\"content-box-purple\">\nCannotFindSymbolMain.java:11: error: cannot find symbol<br \/>\n            division = a\/ b;<br \/>\n  symbol:   variable division<br \/>\n  location: class CannotFindSymbolMain<br \/>\nCannotFindSymbolMain.java:12: error: cannot find symbol<br \/>\n            System.out.println(division);<br \/>\n  symbol:   variable division<br \/>\n  location: class CannotFindSymbolMain<br \/>\n2 errors\n<\/div>\n<p><strong>Did you understand the issue?<\/strong><br \/>\nWe are getting this error because we did not declare <code>division<\/code> before using it.<br \/>\nYou need to change line 11 to:<\/p>\n<pre class=\"lang:java decode:1 \"> \nint division = a\/ b;\n<\/pre>\n<p>This will resolve above compilation error.<\/p>\n<p>There can be multiple reasons for this error.<\/p>\n<ol>\n<li>You forgot to declare any <a href=\"https:\/\/java2blog.com\/variables-java\/\" rel=\"noopener noreferrer\" target=\"_blank\">variable<\/a><\/li>\n<li>You misspelled any <code>methodname<\/code>, <a href=\"https:\/\/java2blog.com\/object-class-java\/\" rel=\"noopener noreferrer\" target=\"_blank\">class<\/a>, variable or <a href=\"https:\/\/java2blog.com\/interface-in-java-with-example\/\" rel=\"noopener noreferrer\" target=\"_blank\">interface<\/a>. Please note that java is case sensitive language, so <code>division<\/code> and <code>Division<\/code> will be not be considered same.<\/li>\n<li>You did not import any class correctly<\/li>\n<li>You forgot <code>new<\/code> keyword while initializing an object.\n<pre class=\"lang:java decode:1 \">\nInteger i = Integer();\n<\/pre>\n<p>We forgot to use <code>new<\/code>, so it should be<\/p>\n<pre class=\"lang:java decode:1 \">\nInteger i = new Integer();\n<\/pre>\n<\/li>\n<li>There can be an issue with <code>source file encoding<\/code>. Even though Identifier looks exactly same, but there can hidden characters<\/li>\n<\/ol>\n<p>As you can see, there can be multiple reasons for this error. You need to figure out what can be the reason for this error in your program. In most of the cases, this error is due to either the <code>undeclared variable<\/code> or <code>misspelled identifier<\/code>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this post, we will see how to solve Cannot find symbol in java. You will get this error when you have declared something that compiler does not understand. The compiler creates list of identifiers when you compile any program. If compile can not understand any of the identifiers, you will get this error. This [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"_mi_skip_tracking":false},"categories":[173],"tags":[],"_links":{"self":[{"href":"https:\/\/java2blog.com\/wp-json\/wp\/v2\/posts\/9269"}],"collection":[{"href":"https:\/\/java2blog.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/java2blog.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/java2blog.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/java2blog.com\/wp-json\/wp\/v2\/comments?post=9269"}],"version-history":[{"count":1,"href":"https:\/\/java2blog.com\/wp-json\/wp\/v2\/posts\/9269\/revisions"}],"predecessor-version":[{"id":25928,"href":"https:\/\/java2blog.com\/wp-json\/wp\/v2\/posts\/9269\/revisions\/25928"}],"wp:attachment":[{"href":"https:\/\/java2blog.com\/wp-json\/wp\/v2\/media?parent=9269"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/java2blog.com\/wp-json\/wp\/v2\/categories?post=9269"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/java2blog.com\/wp-json\/wp\/v2\/tags?post=9269"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}