<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-4816987417907886548</id><updated>2011-11-28T06:59:11.710+06:00</updated><category term='Abstract'/><category term='Package'/><category term='overriding'/><category term='Color'/><category term='Constructor'/><category term='JPA'/><category term='return type'/><category term='Array'/><category term='access modifier'/><category term='Selection'/><category term='Expression'/><category term='Loop'/><category term='Super class'/><category term='Subclass'/><category term='Method'/><category term='Enum'/><category term='Interface'/><category term='Static'/><category term='Inheritance'/><category term='Data Type'/><category term='Variable'/><category term='JDBC'/><category term='Class'/><title type='text'>Java Error Messages and Solutions</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://java-error-messages.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://java-error-messages.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Shamsuddin Ahammad</name><uri>http://www.blogger.com/profile/09496582775045632128</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/__0uCsTbc98U/S8WC0wZGIZI/AAAAAAAAFMs/8dRnDoXS7Rs/S220/Shamsuddin+Ahammad.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>41</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4816987417907886548.post-705761258514094065</id><published>2011-05-20T00:30:00.002+06:00</published><updated>2011-08-15T10:04:34.345+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='return type'/><category scheme='http://www.blogger.com/atom/ns#' term='overriding'/><title type='text'>attempting to use incompatible return type</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;We may encounter this error message when we override a superclass method in the subclass with a wrong return type in the subclass method. To understand this, let's see the following two classes.&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;public class SuperClass&lt;br /&gt;{&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;public &lt;b&gt;double&lt;/b&gt; sum(double a,double b)&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;{&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;return (a+b);&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;}&lt;br /&gt;}&lt;/blockquote&gt;&lt;br /&gt;&lt;blockquote&gt;public class Subclass extends SuperClass&lt;br /&gt;{&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;public &lt;b&gt;long&lt;/b&gt; sum(double a,double b)&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;{&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;return Math.round(a+b);&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;}&lt;br /&gt;}&lt;/blockquote&gt;&lt;br /&gt;In the above example code, the super class method sum has double return type and in the subclass we have overridden this method where return type is long which is not compatible with double.&lt;br /&gt;What should we do now to remove the error? We should either declare the return type of the subclass as double or change the parameter type.&lt;br /&gt;&lt;br /&gt;See the correct code of the subclass below:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;public class Subclass extends SuperClass&lt;br /&gt;{&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;public double sum(double a,double b)&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;{&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;return Math.round(a+b);&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;}&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;public long sum(long a,long b)&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;{&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;return (a+b);&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;}&lt;br /&gt;}&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4816987417907886548-705761258514094065?l=java-error-messages.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-error-messages.blogspot.com/feeds/705761258514094065/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-error-messages.blogspot.com/2011/05/attempting-to-use-incompatible-return.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/705761258514094065'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/705761258514094065'/><link rel='alternate' type='text/html' href='http://java-error-messages.blogspot.com/2011/05/attempting-to-use-incompatible-return.html' title='attempting to use incompatible return type'/><author><name>Shamsuddin Ahammad</name><uri>http://www.blogger.com/profile/09496582775045632128</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/__0uCsTbc98U/S8WC0wZGIZI/AAAAAAAAFMs/8dRnDoXS7Rs/S220/Shamsuddin+Ahammad.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4816987417907886548.post-7491375725980137295</id><published>2011-05-19T23:59:00.008+06:00</published><updated>2011-08-15T10:30:27.551+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Interface'/><category scheme='http://www.blogger.com/atom/ns#' term='Abstract'/><category scheme='http://www.blogger.com/atom/ns#' term='overriding'/><title type='text'>is not abstract and does not override abstract method</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;See the code below:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;import javax.swing.JFrame;&lt;br /&gt;import javax.swing.JButton;&lt;br /&gt;import java.awt.Container;&lt;br /&gt;import java.awt.FlowLayout;&lt;br /&gt;import java.awt.event.ActionEvent;&lt;br /&gt;import java.awt.event.ActionListener;&lt;br /&gt;&lt;br /&gt;public class MyFrame extends JFrame &lt;b&gt;implements ActionListener&lt;/b&gt;{&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;private JButton exitButton = new JButton("Exit");&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;public MyFrame()&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;{&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;Container container = getContentPane();&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;container.setLayout(new FlowLayout());&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;container.add(exitButton);&lt;br /&gt;&amp;nbsp; exitButton.addActionListener(this);&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;setSize(300,200);&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;}&lt;br /&gt;}&lt;/blockquote&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;If this code is compiled, we will see the error "MyFrame is not abstract and does not override abstract method actionPerformed(java.awt.event.ActionEvent) in java.awt.event.ActionListener"&lt;/div&gt;&lt;br /&gt;&lt;div&gt;Why? When we implement an interface(ActionListener in this example) or extend an abstract class in a concrete class, we must override the abstract method(s). In the above example we have implemented ActionListener but have not overridden the abstract method actionPerformed.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The correct code of the above is:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;blockquote&gt;import javax.swing.JFrame;&lt;br /&gt;import javax.swing.JButton;&lt;br /&gt;import java.awt.Container;&lt;br /&gt;import java.awt.FlowLayout;&lt;br /&gt;import java.awt.event.ActionEvent;&lt;br /&gt;import java.awt.event.ActionListener;&lt;br /&gt;&lt;br /&gt;public class MyFrame extends JFrame implements ActionListener&lt;br /&gt;{&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;private JButton exitButton = new JButton("Exit");&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;public MyFrame()&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;{&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;Container container = getContentPane();&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;container.setLayout(new FlowLayout());&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;container.add(exitButton);&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;exitButton.addActionListener(this);&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;setSize(300,200);&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;}&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;b&gt;public void actionPerformed(ActionEvent ae)&lt;/b&gt;&lt;br /&gt;&lt;b&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;{&lt;/b&gt;&lt;br /&gt;&lt;b&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;System.exit(0);&lt;/b&gt;&lt;br /&gt;&lt;b&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;}&lt;/b&gt;&lt;br /&gt;}&lt;/blockquote&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;Sometimes it happens that we override the abstract method with wrong name spelling or wrong signature, then also we see the same error message. Note that Java is a case sensitive language; most often we write the method name with wrong case (example, actionperformed/ActionPerformed instead of actionPerformed) and see this error message.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;For implementing an interface or extending an abstract class, we must override all of the abstract methods (if more than one), though we do not need all. For example, if we implement KeyListener we must override each of the three abstract methods keyPressed, keyTyped and keyReleased though we may not need all of them. In that case, method body can be kept blank. Instead of interface, we can use adapter class (if available) to get rid of overriding all abstract methods.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;In summary, override the abstract method with correct name spelling and signature to remove the error.&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4816987417907886548-7491375725980137295?l=java-error-messages.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-error-messages.blogspot.com/feeds/7491375725980137295/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-error-messages.blogspot.com/2011/05/is-not-abstract-and-does-not-override.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/7491375725980137295'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/7491375725980137295'/><link rel='alternate' type='text/html' href='http://java-error-messages.blogspot.com/2011/05/is-not-abstract-and-does-not-override.html' title='is not abstract and does not override abstract method'/><author><name>Shamsuddin Ahammad</name><uri>http://www.blogger.com/profile/09496582775045632128</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/__0uCsTbc98U/S8WC0wZGIZI/AAAAAAAAFMs/8dRnDoXS7Rs/S220/Shamsuddin+Ahammad.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4816987417907886548.post-5338963851771963482</id><published>2011-05-19T23:11:00.002+06:00</published><updated>2011-08-15T10:30:53.456+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='access modifier'/><category scheme='http://www.blogger.com/atom/ns#' term='overriding'/><title type='text'>attempting to assign weaker access privileges</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Java error "attempting to assign weaker access privileges" can happen when we override a superclass method in the subclass if the access modifier is not correctly chosen.&lt;br /&gt;&lt;br /&gt;See the sample code below:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;public class SuperClass&lt;br /&gt;{&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;b&gt;public&lt;/b&gt; void display()&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;{&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;System.out.println("this is super class");&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;}&lt;br /&gt;}&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;public class Subclass extends SuperClass&lt;br /&gt;{&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;b&gt;private&lt;/b&gt; void display()&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;{&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;System.out.println("this is subclass");&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;}&lt;br /&gt;}&lt;/blockquote&gt;&lt;br /&gt;If the above Subclass is compiled the error message will be:&lt;br /&gt;display() in Subclass cannot override display() in SuperClass; attempting to assign weaker access privileges; was public&lt;br /&gt;&lt;br /&gt;Let's understand the error message:&lt;br /&gt;The method display has public access in the SuperClass and private access in the Subclass, that means when overriding this method, a weaker access privilege is going to be set (private is weaker access privilege than public).&lt;br /&gt;&lt;br /&gt;So we need to know the allowed access modifier in the subclass for method overriding. The table below shows this:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-border-insideh: .5pt solid windowtext; mso-border-insidev: .5pt solid windowtext; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 480;"&gt;&lt;tbody&gt;&lt;tr style="mso-yfti-firstrow: yes; mso-yfti-irow: 0;"&gt;   &lt;td style="border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 221.4pt;" valign="top" width="295"&gt;&lt;div class="MsoNormal"&gt;Access modifier in super class method&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;&lt;/td&gt;   &lt;td style="border-left: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 221.4pt;" valign="top" width="295"&gt;&lt;div class="MsoNormal"&gt;Allowed access modifier for overriding&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;&lt;tr style="mso-yfti-irow: 1;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 221.4pt;" valign="top" width="295"&gt;&lt;div class="MsoNormal"&gt;private&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 221.4pt;" valign="top" width="295"&gt;&lt;div class="MsoNormal"&gt;private, package, protected, public&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;&lt;tr style="mso-yfti-irow: 2;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 221.4pt;" valign="top" width="295"&gt;&lt;div class="MsoNormal"&gt;package&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 221.4pt;" valign="top" width="295"&gt;&lt;div class="MsoNormal"&gt;package, protected, public&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;&lt;tr style="mso-yfti-irow: 3;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 221.4pt;" valign="top" width="295"&gt;&lt;div class="MsoNormal"&gt;protected&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 221.4pt;" valign="top" width="295"&gt;&lt;div class="MsoNormal"&gt;protected, public&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;&lt;tr style="mso-yfti-irow: 4; mso-yfti-lastrow: yes;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 221.4pt;" valign="top" width="295"&gt;&lt;div class="MsoNormal"&gt;public&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 221.4pt;" valign="top" width="295"&gt;&lt;div class="MsoNormal"&gt;public&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4816987417907886548-5338963851771963482?l=java-error-messages.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-error-messages.blogspot.com/feeds/5338963851771963482/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-error-messages.blogspot.com/2011/05/attempting-to-assign-weaker-access.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/5338963851771963482'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/5338963851771963482'/><link rel='alternate' type='text/html' href='http://java-error-messages.blogspot.com/2011/05/attempting-to-assign-weaker-access.html' title='attempting to assign weaker access privileges'/><author><name>Shamsuddin Ahammad</name><uri>http://www.blogger.com/profile/09496582775045632128</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/__0uCsTbc98U/S8WC0wZGIZI/AAAAAAAAFMs/8dRnDoXS7Rs/S220/Shamsuddin+Ahammad.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4816987417907886548.post-8305073200388076950</id><published>2011-05-19T22:43:00.004+06:00</published><updated>2011-08-15T10:31:24.406+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='access modifier'/><title type='text'>modifier private not allowed here</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Java error "modifier private not allowed here" can occur for any of the following reasons:&lt;br /&gt;&lt;br /&gt;1. An outer class declared as private like below:&lt;br /&gt;&lt;blockquote&gt;private class OuterClass&lt;br /&gt;{&lt;br /&gt;&amp;nbsp; &amp;nbsp; //...&lt;br /&gt;}&lt;/blockquote&gt;An outer class only be public or package private not private or protected. So you can write an outer class as below:&lt;br /&gt;&lt;blockquote&gt;public class OuterClass&lt;br /&gt;{&lt;br /&gt;&amp;nbsp; &amp;nbsp;//...&lt;br /&gt;}&lt;/blockquote&gt;or&lt;br /&gt;&lt;blockquote&gt;class OuterClass&lt;br /&gt;{&lt;br /&gt;&amp;nbsp; &amp;nbsp;//...&lt;br /&gt;}&lt;/blockquote&gt;This is true for an interface also. An interface can only be public or package not private or protected.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;2. An interface method declared as private.&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;public interface TestInterface&lt;br /&gt;{&lt;br /&gt;&amp;nbsp; &amp;nbsp;private void method(); // wrong as the interface method is private&lt;br /&gt;}&lt;/blockquote&gt;&lt;br /&gt;An interface can contain only public or package private method.&lt;br /&gt;&lt;br /&gt;The correct code of the above is:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;public interface TestInterface&lt;br /&gt;{&lt;br /&gt;&amp;nbsp; &amp;nbsp;public void method();&lt;br /&gt;}&lt;/blockquote&gt;or&lt;br /&gt;&lt;blockquote&gt;public interface TestInterface&lt;br /&gt;{&lt;br /&gt;&amp;nbsp; &amp;nbsp;void method(); // interface method declared as package private&lt;br /&gt;}&lt;/blockquote&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4816987417907886548-8305073200388076950?l=java-error-messages.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-error-messages.blogspot.com/feeds/8305073200388076950/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-error-messages.blogspot.com/2011/05/modifier-private-not-allowed-here.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/8305073200388076950'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/8305073200388076950'/><link rel='alternate' type='text/html' href='http://java-error-messages.blogspot.com/2011/05/modifier-private-not-allowed-here.html' title='modifier private not allowed here'/><author><name>Shamsuddin Ahammad</name><uri>http://www.blogger.com/profile/09496582775045632128</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/__0uCsTbc98U/S8WC0wZGIZI/AAAAAAAAFMs/8dRnDoXS7Rs/S220/Shamsuddin+Ahammad.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4816987417907886548.post-6348825776558001052</id><published>2011-05-17T22:29:00.006+06:00</published><updated>2011-08-15T10:31:45.909+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JPA'/><title type='text'>No Persistence provider for EntityManager named</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Are you using JPA and getting the error "Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named ..."&lt;br /&gt;&lt;br /&gt;You might have used an entity manager as the following code:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;public void persist(Object object) {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; EntityManagerFactory emf = Persistence.createEntityManagerFactory("TestPU");&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; EntityManager em = emf.createEntityManager();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; em.getTransaction().begin();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; try {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; em.persist(object);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; em.getTransaction().commit();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; } catch (Exception e) {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; e.printStackTrace();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; em.getTransaction().rollback();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; } finally {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; em.close();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp; }&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;And you might have a persistence.xml file as below:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;&lt;br /&gt;&amp;lt;persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"&amp;gt;&lt;br /&gt;&lt;b&gt;&amp;lt;persistence-unit name="PersonPU"&lt;/b&gt; transaction-type="RESOURCE_LOCAL"&amp;gt;&lt;br /&gt;&amp;lt;provider&amp;gt;org.eclipse.persistence.jpa.PersistenceProvider&amp;lt;/provider&amp;gt;&lt;br /&gt;&amp;lt;class&amp;gt;person.entity.Person&amp;lt;/class&amp;gt;&lt;br /&gt;&amp;lt;properties&amp;gt;&lt;br /&gt;&amp;lt;property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/persondb"/&amp;gt;&lt;br /&gt;&amp;lt;property name="javax.persistence.jdbc.password" value="mypassword"/&amp;gt;&lt;br /&gt;&amp;lt;property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/&amp;gt;&lt;br /&gt;&amp;lt;property name="javax.persistence.jdbc.user" value="root"/&amp;gt;&lt;br /&gt;&amp;lt;/properties&amp;gt;&lt;br /&gt;&amp;lt;/persistence-unit&amp;gt;&lt;br /&gt;&amp;lt;/persistence&amp;gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;Now see that, this error may happen for any of the following reasons:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;1. In the code&amp;nbsp;&lt;b&gt;EntityManagerFactory emf = Persistence.createEntityManagerFactory("TestPU"); &lt;/b&gt;TestPU is passed in the method which must be a valid persistence unit name. In the persistence.xml file the name is defined as&amp;nbsp;&lt;b&gt;persistence-unit name="PersonPU". &lt;/b&gt;These two names must be same. So to remove the error the correct code will be :&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;EntityManagerFactory emf = Persistence.createEntityManagerFactory("PersonPU");&lt;/blockquote&gt;&lt;br /&gt;2. If the persistence unit name is correctly used but still the error exists, then confirm that the required jar file containing the JPA implementation classes are available in the classpath. Required jar files for the above code are eclipselink-2.0.0.jar and eclipselink-javax.persistence-2.0.jar&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4816987417907886548-6348825776558001052?l=java-error-messages.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-error-messages.blogspot.com/feeds/6348825776558001052/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-error-messages.blogspot.com/2011/05/no-persistence-provider-for.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/6348825776558001052'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/6348825776558001052'/><link rel='alternate' type='text/html' href='http://java-error-messages.blogspot.com/2011/05/no-persistence-provider-for.html' title='No Persistence provider for EntityManager named'/><author><name>Shamsuddin Ahammad</name><uri>http://www.blogger.com/profile/09496582775045632128</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/__0uCsTbc98U/S8WC0wZGIZI/AAAAAAAAFMs/8dRnDoXS7Rs/S220/Shamsuddin+Ahammad.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4816987417907886548.post-3343028034576360425</id><published>2011-05-17T22:03:00.004+06:00</published><updated>2011-08-15T10:33:00.384+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JPA'/><title type='text'>is not a known entity type</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;To understand the error, let us assume that we have the following classes:&lt;br /&gt;&lt;br /&gt;1) An entity class&lt;br /&gt;&lt;blockquote&gt;package person.entity;&lt;br /&gt;import java.io.Serializable;&lt;br /&gt;import java.util.Date;&lt;br /&gt;import javax.persistence.Basic;&lt;br /&gt;import javax.persistence.Column;&lt;br /&gt;import javax.persistence.Entity;&lt;br /&gt;import javax.persistence.GeneratedValue;&lt;br /&gt;import javax.persistence.GenerationType;&lt;br /&gt;import javax.persistence.Id;&lt;br /&gt;import javax.persistence.NamedQueries;&lt;br /&gt;import javax.persistence.NamedQuery;&lt;br /&gt;import javax.persistence.Table;&lt;br /&gt;import javax.persistence.Temporal;&lt;br /&gt;import javax.persistence.TemporalType;&lt;br /&gt;import javax.xml.bind.annotation.XmlRootElement;&lt;br /&gt;/**&lt;br /&gt;&amp;nbsp;*&lt;br /&gt;&amp;nbsp;* @author Shamsuddin&lt;br /&gt;&amp;nbsp;*/&lt;br /&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="color: red;"&gt;@Entity&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;@Table(name = "person")&lt;br /&gt;@XmlRootElement&lt;br /&gt;@NamedQueries({&lt;br /&gt;&amp;nbsp; &amp;nbsp; @NamedQuery(name = "Person.findAll", query = "SELECT p FROM Person p"),&lt;br /&gt;&amp;nbsp; &amp;nbsp; @NamedQuery(name = "Person.findById", query = "SELECT p FROM Person p WHERE p.id = :id"),&lt;br /&gt;&amp;nbsp; &amp;nbsp; @NamedQuery(name = "Person.findByFirstName", query = "SELECT p FROM Person p WHERE p.firstName = :firstName"),&lt;br /&gt;&amp;nbsp; &amp;nbsp; @NamedQuery(name = "Person.findByLastName", query = "SELECT p FROM Person p WHERE p.lastName = :lastName"),&lt;br /&gt;&amp;nbsp; &amp;nbsp; @NamedQuery(name = "Person.findByDateOfBirth", query = "SELECT p FROM Person p WHERE p.dateOfBirth = :dateOfBirth"),&lt;br /&gt;&amp;nbsp; &amp;nbsp; @NamedQuery(name = "Person.findByEmail", query = "SELECT p FROM Person p WHERE p.email = :email")})&lt;br /&gt;public class Person implements Serializable {&lt;br /&gt;&amp;nbsp; &amp;nbsp; private static final long serialVersionUID = 1L;&lt;br /&gt;&amp;nbsp; &amp;nbsp; @Id&lt;br /&gt;&amp;nbsp; &amp;nbsp; @GeneratedValue(strategy = GenerationType.IDENTITY)&lt;br /&gt;&amp;nbsp; &amp;nbsp; @Basic(optional = false)&lt;br /&gt;&amp;nbsp; &amp;nbsp; @Column(name = "id")&lt;br /&gt;&amp;nbsp; &amp;nbsp; private Integer id;&lt;br /&gt;&amp;nbsp; &amp;nbsp; @Column(name = "first_name")&lt;br /&gt;&amp;nbsp; &amp;nbsp; private String firstName;&lt;br /&gt;&amp;nbsp; &amp;nbsp; @Column(name = "last_name")&lt;br /&gt;&amp;nbsp; &amp;nbsp; private String lastName;&lt;br /&gt;&amp;nbsp; &amp;nbsp; @Column(name = "date_of_birth")&lt;br /&gt;&amp;nbsp; &amp;nbsp; @Temporal(TemporalType.TIMESTAMP)&lt;br /&gt;&amp;nbsp; &amp;nbsp; private Date dateOfBirth;&lt;br /&gt;&amp;nbsp; &amp;nbsp; @Column(name = "email")&lt;br /&gt;&amp;nbsp; &amp;nbsp; private String email;&lt;br /&gt;&amp;nbsp; &amp;nbsp; public Person() {&lt;br /&gt;&amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp; public Person(Integer id) {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; this.id = id;&lt;br /&gt;&amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp; public Integer getId() {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return id;&lt;br /&gt;&amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp; public void setId(Integer id) {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; this.id = id;&lt;br /&gt;&amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp; public String getFirstName() {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return firstName;&lt;br /&gt;&amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp; public void setFirstName(String firstName) {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; this.firstName = firstName;&lt;br /&gt;&amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp; public String getLastName() {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return lastName;&lt;br /&gt;&amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp; public void setLastName(String lastName) {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; this.lastName = lastName;&lt;br /&gt;&amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp; public Date getDateOfBirth() {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return dateOfBirth;&lt;br /&gt;&amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp; public void setDateOfBirth(Date dateOfBirth) {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; this.dateOfBirth = dateOfBirth;&lt;br /&gt;&amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp; public String getEmail() {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return email;&lt;br /&gt;&amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp; public void setEmail(String email) {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; this.email = email;&lt;br /&gt;&amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp; @Override&lt;br /&gt;&amp;nbsp; &amp;nbsp; public int hashCode() {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int hash = 0;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; hash += (id != null ? id.hashCode() : 0);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return hash;&lt;br /&gt;&amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp; @Override&lt;br /&gt;&amp;nbsp; &amp;nbsp; public boolean equals(Object object) {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // TODO: Warning - this method won't work in the case the id fields are not set&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (!(object instanceof Person)) {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return false;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Person other = (Person) object;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if ((this.id == null &amp;amp;&amp;amp; other.id != null) || (this.id != null &amp;amp;&amp;amp; !this.id.equals(other.id))) {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return false;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return true;&lt;br /&gt;&amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp; @Override&lt;br /&gt;&amp;nbsp; &amp;nbsp; public String toString() {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return "person.entity.Person[ id=" + id + " ]";&lt;br /&gt;&amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &lt;br /&gt;}&lt;/blockquote&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;2. A java class that encapsulates an EntityManager&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;blockquote&gt;package person.manager;&lt;br /&gt;import javax.persistence.EntityManager;&lt;br /&gt;import javax.persistence.EntityManagerFactory;&lt;br /&gt;import javax.persistence.Persistence;&lt;br /&gt;/**&lt;br /&gt;&amp;nbsp;*&lt;br /&gt;&amp;nbsp;* @author Shamsuddin&lt;br /&gt;&amp;nbsp;*/&lt;br /&gt;public class MyEntityManager {&lt;br /&gt;&amp;nbsp; &amp;nbsp;EntityManagerFactory emf = Persistence.createEntityManagerFactory("PersonPU");&lt;br /&gt;&amp;nbsp; &amp;nbsp;EntityManager em = emf.createEntityManager();&lt;br /&gt;&amp;nbsp; &amp;nbsp; public void persist(Object object) {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; em.getTransaction().begin();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; try {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; em.persist(object);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; em.getTransaction().commit();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; } catch (Exception e) {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; e.printStackTrace();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; em.getTransaction().rollback();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; } finally {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; em.close();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &lt;br /&gt;}&lt;/blockquote&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;3. A main class&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;blockquote&gt;package person;&lt;br /&gt;import person.entity.Person;&lt;br /&gt;import person.manager.MyEntityManager;&lt;br /&gt;/**&lt;br /&gt;&amp;nbsp;*&lt;br /&gt;&amp;nbsp;* @author Shamsuddin&lt;br /&gt;&amp;nbsp;*/&lt;br /&gt;public class PersonMain {&lt;br /&gt;&amp;nbsp; &amp;nbsp; public static void main(String args[])&lt;br /&gt;&amp;nbsp; &amp;nbsp; {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; MyEntityManager entityManager = new MyEntityManager();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Person person = new Person();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; person.setFirstName("Shamsuddin");&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; person.setLastName("Ahammad");&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;b&gt;&lt;span class="Apple-style-span" style="color: red;"&gt;entityManager.persist(person);&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;&amp;nbsp; &amp;nbsp; }&lt;br /&gt;}&lt;/blockquote&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;If we run the PersonMain class, in a situation, following error may be encountered:&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;java.lang.IllegalArgumentException: Object: person.entity.Person[ id=null ] is not a known entity type&lt;/b&gt;. The compiler indicates the error in the line&amp;nbsp;&lt;b&gt;entityManager.persist(person);&lt;/b&gt; meaning person is not an instance of an entity class.&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Now Let's see:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;1. See that Person is an entity class which has an annotation&amp;nbsp;&lt;b&gt;@Entity&lt;/b&gt; that means we have declared this class as an entity class. If your entity class does not have &lt;b&gt;@Entity&lt;/b&gt;&amp;nbsp;annotation, this may be the cause of this error. In that case, add annotation&amp;nbsp;@Entity in the entity class. In our case, though the entity class is annotated properly, other reasons may cause this error(see below).&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;2. As we are using Java Persistence API (JPA), we have a persistence.xml file containing the following xml code:&lt;/div&gt;&lt;div&gt;&lt;blockquote&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;&lt;br /&gt;&amp;lt;persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;lt;persistence-unit name="PersonPU" transaction-type="RESOURCE_LOCAL"&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;lt;provider&amp;gt;org.eclipse.persistence.jpa.PersistenceProvider&amp;lt;/provider&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;lt;properties&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/persondb"/&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;property name="javax.persistence.jdbc.password" value="mypassword"/&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;property name="javax.persistence.jdbc.user" value="root"/&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;lt;/properties&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;lt;/persistence-unit&amp;gt;&lt;br /&gt;&amp;lt;/persistence&amp;gt;&lt;/blockquote&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;We have error in this persistence.xml file. What's that? The persistence.xml must declare the entity class by writing&amp;nbsp;&amp;lt;class&amp;gt;person.entity.Person&amp;lt;/class&amp;gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;So the correct persistence.xml will be:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;blockquote&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;&lt;br /&gt;&amp;lt;persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;lt;persistence-unit name="PersonPU" transaction-type="RESOURCE_LOCAL"&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;lt;provider&amp;gt;org.eclipse.persistence.jpa.PersistenceProvider&amp;lt;/provider&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;b&gt;&lt;span class="Apple-style-span" style="color: red;"&gt;&amp;lt;class&amp;gt;person.entity.Person&amp;lt;/class&amp;gt;&lt;/span&gt;&lt;/b&gt;&amp;nbsp; &amp;nbsp; &amp;lt;properties&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/persondb"/&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;property name="javax.persistence.jdbc.password" value="mypassword"/&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;property name="javax.persistence.jdbc.user" value="root"/&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;lt;/properties&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;lt;/persistence-unit&amp;gt;&lt;br /&gt;&amp;lt;/persistence&amp;gt;&lt;/blockquote&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;If you use netbeans you can add the entity class declaration in the persistence.xml file very easily using the design view.&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4816987417907886548-3343028034576360425?l=java-error-messages.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-error-messages.blogspot.com/feeds/3343028034576360425/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-error-messages.blogspot.com/2011/05/is-not-known-entity-type.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/3343028034576360425'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/3343028034576360425'/><link rel='alternate' type='text/html' href='http://java-error-messages.blogspot.com/2011/05/is-not-known-entity-type.html' title='is not a known entity type'/><author><name>Shamsuddin Ahammad</name><uri>http://www.blogger.com/profile/09496582775045632128</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/__0uCsTbc98U/S8WC0wZGIZI/AAAAAAAAFMs/8dRnDoXS7Rs/S220/Shamsuddin+Ahammad.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4816987417907886548.post-7000968258247807363</id><published>2011-05-09T22:59:00.012+06:00</published><updated>2011-08-15T10:33:23.826+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Color'/><title type='text'>Color parameter outside of expected range: Red Green Blue</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Java error "Color parameter outside of expected range: Red Green Blue" can be encountered when we use the java.awt.Color class with wrong arguments for RGB (Red Green Blue).&lt;br /&gt;&lt;br /&gt;See the wrong code below:&lt;br /&gt;&lt;blockquote&gt;import javax.swing.JFrame;&lt;br /&gt;import java.awt.Container;&lt;br /&gt;import java.awt.Color;&lt;br /&gt;public class MyFrame extends JFrame&lt;br /&gt;{&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;public MyFrame()&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;{&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;Container container = getContentPane();&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;container.setBackground(new Color(-5,256,300)); // wrong value for RGB&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;setSize(800,600);&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;}&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;public static void main(String args[])&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;{&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;MyFrame myFrame = new MyFrame();&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;myFrame.setVisible(true);&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;}&lt;br /&gt;}&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;See that, we have used -5, 256, 300 for Red, Green and Blue values respectively in the java.awt.Color class constructor. These arguments are illegal as the supported values are in the range 0 to 255.&lt;br /&gt;&lt;br /&gt;So a correct code is:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;container.setBackground(new Color(5,156,200)); // RGB values are in the range 0 to 255&lt;/blockquote&gt;&lt;br /&gt;If the constructor with float arguments is used than the correct RGB values are in the range&amp;nbsp;0.0 to 1.0&lt;br /&gt;&lt;br /&gt;For more details&amp;nbsp;&lt;a href="http://download.oracle.com/javase/1.5.0/docs/api/java/awt/Color.html"&gt;http://download.oracle.com/javase/1.5.0/docs/api/java/awt/Color.html&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4816987417907886548-7000968258247807363?l=java-error-messages.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-error-messages.blogspot.com/feeds/7000968258247807363/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-error-messages.blogspot.com/2011/05/color-parameter-outside-of-expected.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/7000968258247807363'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/7000968258247807363'/><link rel='alternate' type='text/html' href='http://java-error-messages.blogspot.com/2011/05/color-parameter-outside-of-expected.html' title='Color parameter outside of expected range: Red Green Blue'/><author><name>Shamsuddin Ahammad</name><uri>http://www.blogger.com/profile/09496582775045632128</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/__0uCsTbc98U/S8WC0wZGIZI/AAAAAAAAFMs/8dRnDoXS7Rs/S220/Shamsuddin+Ahammad.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4816987417907886548.post-7144652139793234980</id><published>2011-05-09T22:35:00.002+06:00</published><updated>2011-08-15T10:33:47.401+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Constructor'/><category scheme='http://www.blogger.com/atom/ns#' term='Static'/><category scheme='http://www.blogger.com/atom/ns#' term='Interface'/><title type='text'>modifier static not allowed here</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;br /&gt;Java error "modifier static not allowed here" can occur for any of the following reasons:&lt;br /&gt;&lt;br /&gt;1. Constructor is declared as static(!)&lt;br /&gt;&lt;br /&gt;A constructor cannot be static. In the wrong code below:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;public class Person&lt;br /&gt;{&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;private String firstName;&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;private String lastName;&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;public static Person()&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;{&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;//...&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;}&lt;br /&gt;}&lt;/blockquote&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Here the constructor Person is declared as static. As the constructor must be non-static, the correct code is:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;blockquote&gt;public class Person&lt;br /&gt;{&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;private String firstName;&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;private String lastName;&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;public Person()&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;{&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;//...&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;}&lt;br /&gt;}&lt;/blockquote&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;2. Interface contains static method(!)&lt;br /&gt;&lt;br /&gt;All methods of any interface is abstract and hence they must be non static. See the code below:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;public interface MyInterface&lt;br /&gt;{&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;public static void myMetod();&lt;br /&gt;}&lt;/blockquote&gt;&lt;br /&gt;The above code is wrong as the interface method is declared as static. Corrected code is:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;public interface MyInterface&lt;br /&gt;{&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;public void myMetod();&lt;br /&gt;}&lt;/blockquote&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4816987417907886548-7144652139793234980?l=java-error-messages.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-error-messages.blogspot.com/feeds/7144652139793234980/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-error-messages.blogspot.com/2011/05/modifier-static-not-allowed-here.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/7144652139793234980'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/7144652139793234980'/><link rel='alternate' type='text/html' href='http://java-error-messages.blogspot.com/2011/05/modifier-static-not-allowed-here.html' title='modifier static not allowed here'/><author><name>Shamsuddin Ahammad</name><uri>http://www.blogger.com/profile/09496582775045632128</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/__0uCsTbc98U/S8WC0wZGIZI/AAAAAAAAFMs/8dRnDoXS7Rs/S220/Shamsuddin+Ahammad.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4816987417907886548.post-493085875231357662</id><published>2011-05-09T21:27:00.002+06:00</published><updated>2011-08-15T10:34:06.257+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Static'/><category scheme='http://www.blogger.com/atom/ns#' term='Abstract'/><title type='text'>illegal combination of modifiers: abstract and static</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;An abstract method cannot be static because the abstract method must be overridden i.e, body of the abstract method must be defined before invocation.&lt;br /&gt;&lt;br /&gt;See the wrong code below:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;public abstract class Employee&lt;br /&gt;{&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;public &lt;b&gt;static abstract&lt;/b&gt; double earnings(); // error&lt;br /&gt;}&lt;/blockquote&gt;&lt;br /&gt;Here the abstract method earnings() is declared as static. An abstract method must be non-static. So the correct code is:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;public abstract class Employee&lt;br /&gt;{&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;public &lt;b&gt;abstract&lt;/b&gt; double earnings(); // no error now&lt;br /&gt;}&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4816987417907886548-493085875231357662?l=java-error-messages.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-error-messages.blogspot.com/feeds/493085875231357662/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-error-messages.blogspot.com/2011/05/illegal-combination-of-modifiers.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/493085875231357662'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/493085875231357662'/><link rel='alternate' type='text/html' href='http://java-error-messages.blogspot.com/2011/05/illegal-combination-of-modifiers.html' title='illegal combination of modifiers: abstract and static'/><author><name>Shamsuddin Ahammad</name><uri>http://www.blogger.com/profile/09496582775045632128</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/__0uCsTbc98U/S8WC0wZGIZI/AAAAAAAAFMs/8dRnDoXS7Rs/S220/Shamsuddin+Ahammad.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4816987417907886548.post-237888746892824801</id><published>2011-05-09T21:06:00.002+06:00</published><updated>2011-08-15T10:34:28.492+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Interface'/><category scheme='http://www.blogger.com/atom/ns#' term='Method'/><title type='text'>interface methods cannot have body</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Java error "interface methods cannot have body" occurs when body of the method within an interface is defined.&lt;br /&gt;&lt;br /&gt;See the code below:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;public interface MyInterface&lt;br /&gt;{&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;public void myMetod()&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;{&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;}&lt;br /&gt;}&lt;/blockquote&gt;&lt;br /&gt;Here the method myMethod has body starting at the symbol { and ending at }. An interface can have abstract methods (method without any body). The class that implements the interface defines the body of the interface methods.&lt;br /&gt;&lt;br /&gt;So to remove the error, the method signature/header will end by ; (semi colon) and there will be no body section for the method. Below is the correct code:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;public interface MyInterface&lt;br /&gt;{&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;public void myMetod();&lt;br /&gt;}&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4816987417907886548-237888746892824801?l=java-error-messages.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-error-messages.blogspot.com/feeds/237888746892824801/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-error-messages.blogspot.com/2011/05/interface-methods-cannot-have-body.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/237888746892824801'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/237888746892824801'/><link rel='alternate' type='text/html' href='http://java-error-messages.blogspot.com/2011/05/interface-methods-cannot-have-body.html' title='interface methods cannot have body'/><author><name>Shamsuddin Ahammad</name><uri>http://www.blogger.com/profile/09496582775045632128</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/__0uCsTbc98U/S8WC0wZGIZI/AAAAAAAAFMs/8dRnDoXS7Rs/S220/Shamsuddin+Ahammad.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4816987417907886548.post-7177998404204087902</id><published>2011-05-09T20:49:00.002+06:00</published><updated>2011-08-15T10:35:33.616+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Inheritance'/><category scheme='http://www.blogger.com/atom/ns#' term='Class'/><category scheme='http://www.blogger.com/atom/ns#' term='Interface'/><title type='text'>interface expected here</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;The code below leads to an error "interface expected here"&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;public interface MyInterface extends Thread&lt;br /&gt;{&lt;br /&gt;}&lt;/blockquote&gt;&lt;br /&gt;Here an interface is created (MyInterface) and it inherits(extends) the Thread class which is not possible at all. Why? Because an interface can inherit only another interface, not any class. As Thread is a class, it cannot be inherited by any interface.&lt;br /&gt;&lt;br /&gt;The code below is correct as the interface inherits another interface Runnable&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;public interface MyInterface extends Runnable&lt;br /&gt;{&lt;br /&gt;}&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;A similar type of error is posted at &amp;nbsp;&lt;span class="Apple-style-span" style="color: #727272; font-family: Verdana; font-size: 12px; font-weight: bold;"&gt;&lt;a href="http://java-error-messages.blogspot.com/2011/05/no-interface-expected-here.html" style="color: #588cb8; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none;"&gt;no interface expected here&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4816987417907886548-7177998404204087902?l=java-error-messages.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-error-messages.blogspot.com/feeds/7177998404204087902/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-error-messages.blogspot.com/2011/05/interface-expected-here.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/7177998404204087902'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/7177998404204087902'/><link rel='alternate' type='text/html' href='http://java-error-messages.blogspot.com/2011/05/interface-expected-here.html' title='interface expected here'/><author><name>Shamsuddin Ahammad</name><uri>http://www.blogger.com/profile/09496582775045632128</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/__0uCsTbc98U/S8WC0wZGIZI/AAAAAAAAFMs/8dRnDoXS7Rs/S220/Shamsuddin+Ahammad.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4816987417907886548.post-1528620678939707577</id><published>2011-05-09T20:22:00.006+06:00</published><updated>2011-08-15T10:35:56.448+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Inheritance'/><category scheme='http://www.blogger.com/atom/ns#' term='Class'/><category scheme='http://www.blogger.com/atom/ns#' term='Interface'/><title type='text'>no interface expected here</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Any Java code as below will lead an error "no interface expected here"&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;import java.io.Serializable;&lt;br /&gt;public class Person &lt;b&gt;extends&lt;/b&gt; Serializable&lt;br /&gt;{&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;private String firstName;&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;private String lastName;&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;//...&lt;br /&gt;}&lt;/blockquote&gt;&lt;br /&gt;See that, here Person is a class (public &lt;b&gt;class&lt;/b&gt; Person) and it inherits an interface (&lt;b&gt;extends&lt;/b&gt;&amp;nbsp;Serializable). Note that a class can inherit&amp;nbsp;another class&amp;nbsp;only, not any interface. A class can &lt;b&gt;implement&lt;/b&gt; one or more interface&amp;nbsp;only. Serializable is an interface, not a class.&lt;br /&gt;&lt;br /&gt;Actually the correct code of the above will be:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;import java.io.Serializable;&lt;br /&gt;public class Person &lt;b&gt;implements&lt;/b&gt; Serializable&lt;br /&gt;{&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;private String firstName;&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;private String lastName;&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;//...&lt;br /&gt;}&lt;/blockquote&gt;&lt;br /&gt;Here it is notable that, only an interface can inherit another interface.&lt;br /&gt;&lt;br /&gt;A similar type of error is posted at&amp;nbsp;&lt;span class="Apple-style-span" style="color: #727272; font-family: Verdana; font-size: 12px; font-weight: bold;"&gt;&lt;a href="http://java-error-messages.blogspot.com/2011/05/interface-expected-here.html" style="color: #588cb8; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none;"&gt;interface expected here&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4816987417907886548-1528620678939707577?l=java-error-messages.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-error-messages.blogspot.com/feeds/1528620678939707577/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-error-messages.blogspot.com/2011/05/no-interface-expected-here.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/1528620678939707577'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/1528620678939707577'/><link rel='alternate' type='text/html' href='http://java-error-messages.blogspot.com/2011/05/no-interface-expected-here.html' title='no interface expected here'/><author><name>Shamsuddin Ahammad</name><uri>http://www.blogger.com/profile/09496582775045632128</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/__0uCsTbc98U/S8WC0wZGIZI/AAAAAAAAFMs/8dRnDoXS7Rs/S220/Shamsuddin+Ahammad.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4816987417907886548.post-6076965577072717600</id><published>2011-05-05T21:48:00.004+06:00</published><updated>2011-08-15T10:36:29.876+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Constructor'/><category scheme='http://www.blogger.com/atom/ns#' term='Method'/><title type='text'>invalid method declaration; return type required</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;The Java error "invalid method declaration; return type required" can occur for any of the following reasons:&lt;br /&gt;&lt;br /&gt;1. You are trying to define a constructor (of course without any return type; not even void) &amp;nbsp;but the constructor name is not given same as the class name.&lt;br /&gt;&lt;br /&gt;See the wrong code below:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;public class Employee&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;private int id;&lt;br /&gt;&amp;nbsp;private String name;&lt;br /&gt;&amp;nbsp;public employee(int id,String name) // constructor name is not same as the class name.&lt;br /&gt;&amp;nbsp;{&lt;br /&gt;&amp;nbsp; this.id = id;&lt;br /&gt;&amp;nbsp; this.name = name;&lt;br /&gt;&amp;nbsp;}&lt;br /&gt;}&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;So check the spelling of the constructor name and also note that Java is a case sensitive language.&lt;br /&gt;&lt;br /&gt;2. If you are really defining a method (not a constructor) you have forgotten to declare the return type as the wrong code given below:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;public class Test&lt;br /&gt;{&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;public aMethod() // no return type given&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;{&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;System.out.println("This is a method");&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;}&lt;br /&gt;}&lt;/blockquote&gt;&lt;br /&gt;The correct code is:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;public class Test&lt;br /&gt;{&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;public &lt;b&gt;void&lt;/b&gt; aMethod() // return type void is given now&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;{&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;System.out.println("This is a method");&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;}&lt;br /&gt;}&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4816987417907886548-6076965577072717600?l=java-error-messages.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-error-messages.blogspot.com/feeds/6076965577072717600/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-error-messages.blogspot.com/2011/05/invalid-method-declaration-return-type.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/6076965577072717600'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/6076965577072717600'/><link rel='alternate' type='text/html' href='http://java-error-messages.blogspot.com/2011/05/invalid-method-declaration-return-type.html' title='invalid method declaration; return type required'/><author><name>Shamsuddin Ahammad</name><uri>http://www.blogger.com/profile/09496582775045632128</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/__0uCsTbc98U/S8WC0wZGIZI/AAAAAAAAFMs/8dRnDoXS7Rs/S220/Shamsuddin+Ahammad.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4816987417907886548.post-1479157463816940826</id><published>2011-05-03T21:17:00.006+06:00</published><updated>2011-08-15T10:36:52.602+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Constructor'/><title type='text'>recursive constructor invocation</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;If a constructor calls itself, then the error message "recursive constructor invocation" is shown. It may happen when we overload constructors and call the wrong constructor (itself) accidentally.&lt;br /&gt;&lt;br /&gt;See the &lt;b&gt;&lt;u&gt;wrong&lt;/u&gt;&lt;/b&gt; code below:&lt;br /&gt;&lt;blockquote&gt;public class Employee&lt;br /&gt;{&lt;br /&gt;&amp;nbsp; private int id;&lt;br /&gt;&amp;nbsp; private String name;&lt;br /&gt;&amp;nbsp; public Employee(int id,String name)&lt;br /&gt;&amp;nbsp; {&lt;br /&gt;&amp;nbsp; &amp;nbsp; this.id = id;&lt;br /&gt;&amp;nbsp; &amp;nbsp; this.name = name;&lt;br /&gt;&amp;nbsp; }&lt;br /&gt;&amp;nbsp; public Employee(int id)&lt;br /&gt;&amp;nbsp; {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;b&gt;this(id);&amp;nbsp;&lt;/b&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; /* this(id) calls the constructor having one parameter of int type. Thus this is calling itself.*/&lt;br /&gt;&amp;nbsp; }&lt;br /&gt;&amp;nbsp; public Employee()&lt;br /&gt;&amp;nbsp; {&lt;br /&gt;&amp;nbsp; }&lt;br /&gt;}&lt;/blockquote&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;In the above code, there are three constructors:&lt;br /&gt;i)&amp;nbsp;Employee(int id,String name)&lt;br /&gt;ii)&amp;nbsp;Employee(int id)&lt;br /&gt;iii)&amp;nbsp;Employee()&lt;br /&gt;&lt;br /&gt;Within the second constructor, we have written &lt;b&gt;this(id)&lt;/b&gt; which means it calls a constructor with one int parameter and see that it is the constructor itself. It means we have not invoked the right constructor. If we want to invoke the first constructor&amp;nbsp;Employee(int id,String name) within the second constructor we should write this(id,null). We are providing null for the String name as no value is available for the name variable in the second constructor but now it calls the first constructor&amp;nbsp;Employee(int id,String name) as we have provided &amp;nbsp;two parameters now.&lt;br /&gt;&lt;br /&gt;See the &lt;b&gt;&lt;u&gt;corrected&lt;/u&gt;&lt;/b&gt; code below:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;public class Employee&lt;br /&gt;{&lt;br /&gt;&amp;nbsp; private int id;&lt;br /&gt;&amp;nbsp; private String name;&lt;br /&gt;&amp;nbsp; public Employee(int id,String name)&lt;br /&gt;&amp;nbsp; {&lt;br /&gt;&amp;nbsp; &amp;nbsp; this.id = id;&lt;br /&gt;&amp;nbsp; &amp;nbsp; this.name = name;&lt;br /&gt;&amp;nbsp; }&lt;br /&gt;&amp;nbsp; public Employee(int id)&lt;br /&gt;&amp;nbsp; {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;b&gt;this(id,null)&lt;/b&gt;; // this(id,null) calls another constructor having two parameters&lt;br /&gt;&amp;nbsp; }&lt;br /&gt;&amp;nbsp; public Employee()&lt;br /&gt;&amp;nbsp; {&lt;br /&gt;&amp;nbsp; }&lt;br /&gt;}&lt;/blockquote&gt;&lt;br /&gt;Summary:&lt;br /&gt;&lt;br /&gt;If you see the error message "recursive constructor invocation", check that you have provided correct no and type of parameters while calling one constructor in another one.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4816987417907886548-1479157463816940826?l=java-error-messages.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-error-messages.blogspot.com/feeds/1479157463816940826/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-error-messages.blogspot.com/2011/05/recursive-constructor-invocation.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/1479157463816940826'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/1479157463816940826'/><link rel='alternate' type='text/html' href='http://java-error-messages.blogspot.com/2011/05/recursive-constructor-invocation.html' title='recursive constructor invocation'/><author><name>Shamsuddin Ahammad</name><uri>http://www.blogger.com/profile/09496582775045632128</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/__0uCsTbc98U/S8WC0wZGIZI/AAAAAAAAFMs/8dRnDoXS7Rs/S220/Shamsuddin+Ahammad.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4816987417907886548.post-5314445228129284254</id><published>2011-04-15T16:31:00.004+06:00</published><updated>2011-08-15T10:37:18.024+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JDBC'/><title type='text'>java.sql.SQLException: Access denied for user</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;The full error message may be :&lt;br /&gt;&lt;br /&gt;java.sql.SQLException: Access denied for user 'root'@'localhost' (using password&amp;nbsp;: YES)&lt;br /&gt;&lt;br /&gt;or&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: NO)&lt;br /&gt;&lt;br /&gt;When we try to connect to a database through JDBC with wrong username or password - we see this error message.&lt;br /&gt;&lt;br /&gt;See the sample code below:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/DatabaseName","&lt;b&gt;root&lt;/b&gt;","&lt;b&gt;mypassword&lt;/b&gt;");&lt;/blockquote&gt;&lt;br /&gt;In the above code, &lt;b&gt;root&lt;/b&gt; is the username and &lt;b&gt;mypassword&lt;/b&gt; is the password. If the username root or the password is not correct we see this error message "java.sql.SQLException: Access denied for user 'root'@'localhost' (using password&amp;nbsp;: YES)".&lt;br /&gt;&lt;br /&gt;If the password is not provided (blank password) as the code below but the user has password we see the error message "java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: NO)"&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/DatabaseName","&lt;b&gt;root&lt;/b&gt;","");&lt;/blockquote&gt;If you are using JPA with eclipselink/toplink or other, correct the username and password in the persistence.xml file of your project.&lt;br /&gt;&lt;br /&gt;persistence.xml may look like below:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;&lt;br /&gt;&amp;lt;persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;lt;persistence-unit name="MyPersistenceUnitPU" transaction-type="RESOURCE_LOCAL"&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;lt;provider&amp;gt;oracle.toplink.essentials.PersistenceProvider&amp;lt;/provider&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;lt;properties&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;property name="toplink.jdbc.user" value="root"/&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;property name="toplink.jdbc.password" value="mypassword"/&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;property name="toplink.jdbc.url" value="jdbc:mysql://localhost:3306/DatabaseName"/&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;property name="toplink.jdbc.driver" value="com.mysql.jdbc.Driver"/&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;lt;/properties&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;lt;/persistence-unit&amp;gt;&lt;br /&gt;&amp;lt;/persistence&amp;gt;&lt;/blockquote&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4816987417907886548-5314445228129284254?l=java-error-messages.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-error-messages.blogspot.com/feeds/5314445228129284254/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-error-messages.blogspot.com/2011/04/javasqlsqlexception-access-denied-for.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/5314445228129284254'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/5314445228129284254'/><link rel='alternate' type='text/html' href='http://java-error-messages.blogspot.com/2011/04/javasqlsqlexception-access-denied-for.html' title='java.sql.SQLException: Access denied for user'/><author><name>Shamsuddin Ahammad</name><uri>http://www.blogger.com/profile/09496582775045632128</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/__0uCsTbc98U/S8WC0wZGIZI/AAAAAAAAFMs/8dRnDoXS7Rs/S220/Shamsuddin+Ahammad.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4816987417907886548.post-1463592946587516849</id><published>2011-04-15T16:16:00.002+06:00</published><updated>2011-08-15T10:37:43.009+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JDBC'/><title type='text'>com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown database</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Trying to connect to a MySQL server from Java? But seeing the error "Unknown database"?&lt;br /&gt;&lt;br /&gt;The reason is that the database does not exist in the MySQL server. You might have accidentally misspelled the database name in the JDBC connection url.&lt;br /&gt;&lt;br /&gt;See the code below:&lt;br /&gt;&lt;blockquote&gt;Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/&lt;b&gt;sales&lt;/b&gt;","username","password");&lt;/blockquote&gt;&lt;br /&gt;Here &lt;b&gt;sales&lt;/b&gt; is the database name. If you misspelled this or the database sales does not exist in the server, you see this error message.&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4816987417907886548-1463592946587516849?l=java-error-messages.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-error-messages.blogspot.com/feeds/1463592946587516849/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-error-messages.blogspot.com/2011/04/commysqljdbcexceptionsjdbc4mysqlsyntaxe.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/1463592946587516849'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/1463592946587516849'/><link rel='alternate' type='text/html' href='http://java-error-messages.blogspot.com/2011/04/commysqljdbcexceptionsjdbc4mysqlsyntaxe.html' title='com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown database'/><author><name>Shamsuddin Ahammad</name><uri>http://www.blogger.com/profile/09496582775045632128</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/__0uCsTbc98U/S8WC0wZGIZI/AAAAAAAAFMs/8dRnDoXS7Rs/S220/Shamsuddin+Ahammad.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4816987417907886548.post-8982293214290304659</id><published>2011-04-15T15:59:00.003+06:00</published><updated>2011-08-15T10:38:21.792+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JDBC'/><title type='text'>com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;br /&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;This error message may include the following text also:&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;"The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server."&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;When we try to connect to a MySQL server&amp;nbsp;"Communications link failure" error may occur for any of the following errors:&lt;br /&gt;&lt;br /&gt;i) MySQL server is not running. Check for this and run the sever if it is stopped.&lt;br /&gt;&lt;br /&gt;ii) Host name is wrong: If the server is running in the same computer, the correct host name is &lt;b&gt;localhost &lt;/b&gt;otherwise it is a valid IP address or computer name.&lt;br /&gt;&lt;br /&gt;iii) Wrong port no given : By default MySQL server runs in port 3306. If it is different, check that correct port no is given.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Sample code:&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;public static Connection getConnection()&lt;br /&gt;{&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;Connection connection = null;&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;try&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;{&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;Class.forName("com.mysql.jdbc.Driver");&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;connection = &lt;b&gt;DriverManager.getConnection("jdbc:mysql://localhost:3306/database","username","password");&lt;/b&gt;&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;System.out.println("Connection successful");&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;}&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;catch(ClassNotFoundException cnfe)&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;{&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;System.err.println("MySQL driver not found");&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;cnfe.printStackTrace();&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;}&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;catch(SQLException sqle)&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;{&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;System.err.println("Database/Connection error");&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;sqle.printStackTrace();&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;return connection;&lt;br /&gt;}&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4816987417907886548-8982293214290304659?l=java-error-messages.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-error-messages.blogspot.com/feeds/8982293214290304659/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-error-messages.blogspot.com/2011/04/commysqljdbcexceptionsjdbc4communicatio.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/8982293214290304659'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/8982293214290304659'/><link rel='alternate' type='text/html' href='http://java-error-messages.blogspot.com/2011/04/commysqljdbcexceptionsjdbc4communicatio.html' title='com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure'/><author><name>Shamsuddin Ahammad</name><uri>http://www.blogger.com/profile/09496582775045632128</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/__0uCsTbc98U/S8WC0wZGIZI/AAAAAAAAFMs/8dRnDoXS7Rs/S220/Shamsuddin+Ahammad.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4816987417907886548.post-2873458004600148902</id><published>2011-04-15T15:41:00.002+06:00</published><updated>2011-08-15T10:40:17.267+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JDBC'/><title type='text'>ClassNotFoundException: com.mysql.jdbc.Driver</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;This error occurs when the required JDBC driver file is not in the CLASSPATH. Also, if the driver name is not correct&amp;nbsp;ClassNotFoundException occurs. To solve this problem, at first check the driver name; if the driver name is correct, do one of the followings as per requirement.&lt;br /&gt;&lt;br /&gt;i) Add an entry for the driver file (mysql-connector-java-5.1.10.jar, for example) in the CLASSPATH variable.&lt;br /&gt;&lt;br /&gt;or&lt;br /&gt;&lt;br /&gt;ii) If you are not familiar with the CLASSPATH variable, place the&amp;nbsp;mysql-connector-java-5.1.10.jar file in \jre\lib\ext folder in the JDK install directory (for example C:\Program Files\Java\jdk1.6.0_20\jre\lib\ext)&lt;br /&gt;&lt;br /&gt;or&lt;br /&gt;&lt;br /&gt;iii) If you are doing this in NetBeans or other IDEs, add MySQL JDBC Driver Library in the project.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4816987417907886548-2873458004600148902?l=java-error-messages.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-error-messages.blogspot.com/feeds/2873458004600148902/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-error-messages.blogspot.com/2011/04/classnotfoundexception.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/2873458004600148902'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/2873458004600148902'/><link rel='alternate' type='text/html' href='http://java-error-messages.blogspot.com/2011/04/classnotfoundexception.html' title='ClassNotFoundException: com.mysql.jdbc.Driver'/><author><name>Shamsuddin Ahammad</name><uri>http://www.blogger.com/profile/09496582775045632128</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/__0uCsTbc98U/S8WC0wZGIZI/AAAAAAAAFMs/8dRnDoXS7Rs/S220/Shamsuddin+Ahammad.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4816987417907886548.post-6438459543880989594</id><published>2011-04-10T21:09:00.002+06:00</published><updated>2011-08-15T10:40:41.406+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Constructor'/><category scheme='http://www.blogger.com/atom/ns#' term='Inheritance'/><category scheme='http://www.blogger.com/atom/ns#' term='Super class'/><category scheme='http://www.blogger.com/atom/ns#' term='Subclass'/><title type='text'>call to super must be first statement in constructor</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;The error message is very clear actually:&lt;br /&gt;&lt;br /&gt;i) We can call super in the constructor of a subclass&lt;br /&gt;ii) If we call super in the constructor of a subclass, it must be the first statement in that constructor; i.e, before writing any other statement we call to super must be made.&lt;br /&gt;&lt;br /&gt;It is mentionable that, super(parameters) calls the constructor of the super class.&lt;br /&gt;&lt;br /&gt;See the code below:&lt;br /&gt;&lt;br /&gt;The super class...&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;public class Employee&lt;br /&gt;{&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;private int id;&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;private String name;&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;public Employee()&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;{&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;}&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;public Employee(int id,String name)&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;{&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;this.id = id;&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;this.name = name;&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;}&lt;br /&gt;}&lt;/blockquote&gt;&lt;br /&gt;The subclass...&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;public class SalariedEmployee extends Employee&lt;br /&gt;{&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;private double salary;&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;public SalariedEmployee()&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;{&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;}&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;public SalariedEmployee(int id,String name,double salary)&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;{&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;this.salary = salary; //this is the first statement now&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;super(id,name); //error :&amp;nbsp;call to super must be first statement in constructor&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;}&lt;br /&gt;}&lt;/blockquote&gt;&lt;br /&gt;The correct subclass will be...&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;/div&gt;&lt;blockquote&gt;public class SalariedEmployee extends Employee&lt;br /&gt;{&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;private double salary;&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;public SalariedEmployee()&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;{&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;}&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;public SalariedEmployee(int id,String name,double salary)&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;{&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;super(id,name); // now call to super is the first statement in the constructor&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;this.salary = salary; // it is now the second statement&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;}&lt;br /&gt;}&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4816987417907886548-6438459543880989594?l=java-error-messages.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-error-messages.blogspot.com/feeds/6438459543880989594/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-error-messages.blogspot.com/2011/04/call-to-super-must-be-first-statement.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/6438459543880989594'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/6438459543880989594'/><link rel='alternate' type='text/html' href='http://java-error-messages.blogspot.com/2011/04/call-to-super-must-be-first-statement.html' title='call to super must be first statement in constructor'/><author><name>Shamsuddin Ahammad</name><uri>http://www.blogger.com/profile/09496582775045632128</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/__0uCsTbc98U/S8WC0wZGIZI/AAAAAAAAFMs/8dRnDoXS7Rs/S220/Shamsuddin+Ahammad.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4816987417907886548.post-4160810955693470788</id><published>2009-10-30T12:27:00.011+07:00</published><updated>2011-08-15T10:41:46.476+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Array'/><category scheme='http://www.blogger.com/atom/ns#' term='Loop'/><title type='text'>java.lang.ArrayIndexOutOfBoundsException</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;span class="Apple-style-span" style="font-family: 'Times New Roman'; font-size: medium;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Times New Roman'; font-size: medium;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;It's a very common runtime error message or exception we face when we use array wrongly. Very specifically this exception is thrown to indicate that an array has been accessed with an illegal index (location / position / subscript). The index is either negative or greater than or equal to the size of the array.&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Times New Roman'; font-size: medium;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Times New Roman'; font-size: medium;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;See the following code:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Times New Roman'; font-size: medium;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;div style="text-align: justify;"&gt;&lt;/div&gt;&lt;blockquote&gt;&lt;div style="text-align: justify;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Times New Roman'; font-size: medium;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;int data[]={5,7,18,21,27,15,3};&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Times New Roman'; font-size: medium;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Times New Roman'; font-size: medium;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;//show the array elements&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;div style="text-align: justify;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Times New Roman'; font-size: medium;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;for(int i=0;i&lt;/span&gt;&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; border-collapse: collapse;"&gt;&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; border-collapse: separate;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;&lt;span class="Apple-style-span" style="font-family: monospace; font-size: medium; white-space: pre-wrap;"&gt;&amp;lt;&lt;/span&gt;=7;i++)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Times New Roman'; font-size: medium;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;{&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Times New Roman'; font-size: medium;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;System.out.println(data[i]);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Times New Roman'; font-size: medium;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/blockquote&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Times New Roman';"&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;Here the array size is 7 as the array is initialized by assigning 7 elements {5,7,18,21,27,15,3}. So the valid array index is 0 to 6. In the loop condition, we have given i&amp;amp;&lt;/span&gt;&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; border-collapse: collapse;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;lt&lt;/span&gt;&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; border-collapse: separate;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;=7 and i is used as the array index inside the loop - so when i is 7 it tries to access the array element 7 but 7 is not a valid index. This causes the exception. Correct loop condition is i&lt;span class="Apple-style-span" style="font-family: monospace; font-size: medium; white-space: pre-wrap;"&gt;&amp;lt;&lt;/span&gt;7 or i&lt;/span&gt;&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; border-collapse: collapse;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; border-collapse: separate; font-family: monospace; font-size: medium; white-space: pre-wrap;"&gt;&amp;lt;&lt;/span&gt;=6. The recommended approach is using the array built in variable length instead of the static size. Correct the code as below:&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'Times New Roman';"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'Times New Roman';"&gt;&lt;/span&gt;&lt;br /&gt;&lt;div&gt;&lt;/div&gt;&lt;blockquote&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'Times New Roman';"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;int data[]={5,7,18,21,27,15,3};&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'Times New Roman';"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'Times New Roman';"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;//show the array elements&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'Times New Roman';"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;for(int i=0;i&lt;/span&gt;&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; border-collapse: collapse;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; border-collapse: separate; font-family: monospace; font-size: medium; white-space: pre-wrap;"&gt;&amp;lt;&lt;/span&gt;data.length;i++)//data is the array name&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'Times New Roman';"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;{&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'Times New Roman';"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;System.out.println(data[i]);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'Times New Roman';"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/blockquote&gt;&lt;div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'Times New Roman';"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4816987417907886548-4160810955693470788?l=java-error-messages.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-error-messages.blogspot.com/feeds/4160810955693470788/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-error-messages.blogspot.com/2009/10/javalangarrayindexoutofboundsexception.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/4160810955693470788'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/4160810955693470788'/><link rel='alternate' type='text/html' href='http://java-error-messages.blogspot.com/2009/10/javalangarrayindexoutofboundsexception.html' title='java.lang.ArrayIndexOutOfBoundsException'/><author><name>Shamsuddin Ahammad</name><uri>http://www.blogger.com/profile/09496582775045632128</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/__0uCsTbc98U/S8WC0wZGIZI/AAAAAAAAFMs/8dRnDoXS7Rs/S220/Shamsuddin+Ahammad.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4816987417907886548.post-6015317070241129132</id><published>2009-10-30T12:06:00.005+07:00</published><updated>2011-08-15T10:42:14.052+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Array'/><title type='text'>array dimension missing</title><content type='html'>&lt;div style="text-align: justify;"&gt;'array dimension missing' is shown when the array size is not specified while allocating memory for the array or creating an array.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;See below:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;blockquote&gt;int data[ ]=new int[ ];&lt;/blockquote&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;See that, blank [ ]  is given in new int[ ]. We must give an int as the size of the array. Memory will be allocated for the array according to the given int within the [ ] as below:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;blockquote&gt;int data[]=new int[5];&lt;/blockquote&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4816987417907886548-6015317070241129132?l=java-error-messages.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-error-messages.blogspot.com/feeds/6015317070241129132/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-error-messages.blogspot.com/2009/10/array-dimension-missing.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/6015317070241129132'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/6015317070241129132'/><link rel='alternate' type='text/html' href='http://java-error-messages.blogspot.com/2009/10/array-dimension-missing.html' title='array dimension missing'/><author><name>Shamsuddin Ahammad</name><uri>http://www.blogger.com/profile/09496582775045632128</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/__0uCsTbc98U/S8WC0wZGIZI/AAAAAAAAFMs/8dRnDoXS7Rs/S220/Shamsuddin+Ahammad.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4816987417907886548.post-7452764609760966361</id><published>2009-10-30T11:45:00.006+07:00</published><updated>2011-08-15T10:42:36.960+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Expression'/><category scheme='http://www.blogger.com/atom/ns#' term='Array'/><title type='text'>illegal initializer</title><content type='html'>You may see this error for writing wrong expression to initialize an array. See the code below:&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;blockquote&gt;int data={42,15,27,20,19};&lt;/blockquote&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;If you compile this, you will see the following error message:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;illegal initializer for int&lt;/div&gt;&lt;div&gt;int data={42,15,27,20,19};&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;         ^&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Here the array is not declared properly as we have not put [ ] for declaring the array. The correct code is:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;blockquote&gt;int data[ ]={42,15,27,20,19};&lt;/blockquote&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;or&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;blockquote&gt;int[ ] data={42,15,27,20,19};&lt;/blockquote&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4816987417907886548-7452764609760966361?l=java-error-messages.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-error-messages.blogspot.com/feeds/7452764609760966361/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-error-messages.blogspot.com/2009/10/illegal-initializer.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/7452764609760966361'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/7452764609760966361'/><link rel='alternate' type='text/html' href='http://java-error-messages.blogspot.com/2009/10/illegal-initializer.html' title='illegal initializer'/><author><name>Shamsuddin Ahammad</name><uri>http://www.blogger.com/profile/09496582775045632128</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/__0uCsTbc98U/S8WC0wZGIZI/AAAAAAAAFMs/8dRnDoXS7Rs/S220/Shamsuddin+Ahammad.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4816987417907886548.post-907885527812760016</id><published>2009-10-30T11:09:00.007+07:00</published><updated>2011-08-15T10:42:59.381+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Expression'/><category scheme='http://www.blogger.com/atom/ns#' term='Data Type'/><category scheme='http://www.blogger.com/atom/ns#' term='Selection'/><category scheme='http://www.blogger.com/atom/ns#' term='Variable'/><title type='text'>incompatible types</title><content type='html'>&lt;div style="text-align: justify;"&gt;1. Sometimes we may get the following error message in an 'if' (selection) structure.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;incompatible types&lt;/div&gt;&lt;div&gt;found   : int&lt;/div&gt;&lt;div&gt;required: boolean&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;This is because, we have not specified a boolean expression as the condition of the 'if'; instead we might have written such an expression which is may be int, float, String or other types but not boolean.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;See the code below:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;/div&gt;&lt;blockquote&gt;&lt;div&gt;int a=10,b=10;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;if(a=b)&lt;/div&gt;&lt;div&gt;{&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;System.out.println("a and b are equal");&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;/blockquote&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Check the condition is a=b. Is it a boolean expression? By using a single = (equal sign), value of b is assigned to a which is an integer. That's not correct. We must use == (double equal sign) for comparing two variables for equality.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Correct code is the below:&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;blockquote&gt;&lt;div&gt;int a=10,b=10;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;if(a==b)&lt;/div&gt;&lt;div&gt;{&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;System.out.println("a and b are equal");&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;/blockquote&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;2. Sometimes it happens because of assigning one type of value to a variable of other types. See the code below:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;/div&gt;&lt;blockquote&gt;&lt;div&gt;String text='a';&lt;/div&gt;&lt;div&gt;char ch="a";&lt;/div&gt;&lt;/blockquote&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;In this case the error message will be:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;incompatible types&lt;/div&gt;&lt;div&gt;found   : char&lt;/div&gt;&lt;div&gt;required: java.lang.String&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;String text='a';&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;            ^&lt;/div&gt;&lt;div&gt;&lt;div&gt;incompatible types&lt;/div&gt;&lt;div&gt;found   : java.lang.String&lt;/div&gt;&lt;div&gt;required: char&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;char ch="a";&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;        ^&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Here we have not assigned correct value for the variables text and ch. In the first line, we have assigned a char value to a String variable. 'a' is a char value because it is written within ' ' (single quotation mark) . In the second line, we have assigned String value "a" to a char type variable. Note that String value is written within " " (double quotation mark). So we tried to assign char value to a String variable and a String value to a char variable. The correct code is:&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;/div&gt;&lt;blockquote&gt;&lt;div&gt;String text="a";&lt;/div&gt;&lt;div&gt;char ch='a';&lt;/div&gt;&lt;/blockquote&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;If you see this error, check that the correct type of value or variable is assigned.&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4816987417907886548-907885527812760016?l=java-error-messages.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-error-messages.blogspot.com/feeds/907885527812760016/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-error-messages.blogspot.com/2009/10/incompatible-types.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/907885527812760016'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/907885527812760016'/><link rel='alternate' type='text/html' href='http://java-error-messages.blogspot.com/2009/10/incompatible-types.html' title='incompatible types'/><author><name>Shamsuddin Ahammad</name><uri>http://www.blogger.com/profile/09496582775045632128</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/__0uCsTbc98U/S8WC0wZGIZI/AAAAAAAAFMs/8dRnDoXS7Rs/S220/Shamsuddin+Ahammad.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4816987417907886548.post-5301267829335324526</id><published>2009-08-28T22:37:00.007+07:00</published><updated>2011-08-15T10:43:27.685+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Inheritance'/><category scheme='http://www.blogger.com/atom/ns#' term='Class'/><title type='text'>cyclic inheritance involving ...</title><content type='html'>&lt;div&gt;&lt;/div&gt;&lt;blockquote&gt;&lt;div&gt;public class Person extends Employee&lt;/div&gt;&lt;div&gt;{&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;private String firstName;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;private String lastName;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;public Person(String firstName,String lastName)&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;{&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;this.firstName=firstName;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;this.lastName=lastName;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;/blockquote&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Person is a class which inherits Employee and see the code below where Employee also inherit the Class Person.&lt;/div&gt;&lt;table&gt;&lt;tbody&gt;&lt;tr&gt; &lt;td&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;/div&gt;&lt;blockquote&gt;&lt;div&gt;public class Employee extends Person&lt;/div&gt;&lt;div&gt;{&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;private double salary;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;public Employee(String firstName,String lastName,double salary)&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;{&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;super(firstName,lastName);&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;this.salary=salary;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;/blockquote&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;In the above code we will see the error message "cyclic inheritance involving Person&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;public class Person extends Employee"&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Actually Person should be the super class here and Employee is the subclass. But here the relationsship is such that Employee is the subclass of Person, again Person is the subclass of Employee.  It's a cyclic inheritance which is not possible.  &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;The solution of this problem is identifying the proper relationship i.e, finding out the super class and the subclass. In our case Person is the super class, so it should not try to inherit Employee and Employee is the subclass which will inherit Person. Correction is ommiting "extends Employee" from the Person class signature as below:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;/div&gt;&lt;blockquote&gt;&lt;div&gt;public class Person&lt;/div&gt;&lt;div&gt;{&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;private String firstName;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;private String lastName;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;public Person(String firstName,String lastName)&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;{&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;this.firstName=firstName;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;this.lastName=lastName;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;/blockquote&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;/div&gt;&lt;blockquote&gt;&lt;div&gt;public class Employee extends Person&lt;/div&gt;&lt;div&gt;{&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;private double salary;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;public Employee(String firstName,String lastName,double salary)&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;{&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;super(firstName,lastName);&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;this.salary=salary;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;/blockquote&gt;&lt;div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4816987417907886548-5301267829335324526?l=java-error-messages.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-error-messages.blogspot.com/feeds/5301267829335324526/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-error-messages.blogspot.com/2009/08/cyclic-inheritance-involving.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/5301267829335324526'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/5301267829335324526'/><link rel='alternate' type='text/html' href='http://java-error-messages.blogspot.com/2009/08/cyclic-inheritance-involving.html' title='cyclic inheritance involving ...'/><author><name>Shamsuddin Ahammad</name><uri>http://www.blogger.com/profile/09496582775045632128</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/__0uCsTbc98U/S8WC0wZGIZI/AAAAAAAAFMs/8dRnDoXS7Rs/S220/Shamsuddin+Ahammad.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4816987417907886548.post-9128700047069516174</id><published>2009-08-19T14:19:00.009+07:00</published><updated>2011-08-15T10:43:48.775+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Enum'/><category scheme='http://www.blogger.com/atom/ns#' term='Class'/><category scheme='http://www.blogger.com/atom/ns#' term='Interface'/><title type='text'>class, interface, or enum expected</title><content type='html'>You see this error message because of any one of the followings:&lt;br /&gt;&lt;br /&gt;1. You misspelled the keyword class (fully lower case) or you did not write it at all for writing your class.&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;public Class Test //actual keyword is class&lt;br /&gt;{&lt;br /&gt;public void myMethod()&lt;br /&gt;{&lt;br /&gt;System.out.println("class, interface, or enum expected?");&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;In the above example Class (C is in upper case) is written instead of class (fully lower case).&lt;br /&gt;&lt;br /&gt;2. Remember you cannot declare variables outside of class body like below.&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;int variable; //variable must be declared inside the class body&lt;br /&gt;public class Test&lt;br /&gt;{&lt;br /&gt;public void myMethod()&lt;br /&gt;{&lt;br /&gt;System.out.println("class, interface, or enum expected?");&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;To solve this declare variables inside the class body as below.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;public class Test&lt;br /&gt;{&lt;br /&gt;int variable; //variable must be declared inside the class body&lt;br /&gt;public void myMethod()&lt;br /&gt;{&lt;br /&gt;System.out.println("class, interface, or enum expected?");&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;3. All methods are also defined within the method body. If you define any method outside of the class body you will see this error message.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;public class Test&lt;br /&gt;{&lt;br /&gt;public void myMethod()&lt;br /&gt;{&lt;br /&gt;System.out.println("method inside the class body");&lt;br /&gt;}&lt;br /&gt;} //end of class&lt;br /&gt;&lt;br /&gt;public void anotherMethod()&lt;br /&gt;{&lt;br /&gt;System.out.println("method outside of the class body");&lt;br /&gt;}&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;In the above code, the method anotherMethod is defined after the end of the class. So this error occurred. Most often it occurs just because of incorrect use of {} (curly braces). Check all { are closed with } in the proper place.&lt;br /&gt;&lt;br /&gt;4. If you are defining an interface, check you spelled it correctly in fully lowercase.&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;public Interface Test //actual keyword is interface&lt;br /&gt;{&lt;br /&gt;public void myMethod();&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;In the above code, keyword interface is misspelled with upper I.&lt;br /&gt;&lt;br /&gt;5. Same way if you define an enum spell the keyword enum correctly.&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;public Enum Day //actual keyword is enum&lt;br /&gt;{&lt;br /&gt;SUNDAY, MONDAY, TUESDAY, WEDNESDAY,&lt;br /&gt;THURSDAY, FRIDAY, SATURDAY&lt;br /&gt;}&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;In the above example Enum is incorrect as the E is in upper case, it will be lower case e.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4816987417907886548-9128700047069516174?l=java-error-messages.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-error-messages.blogspot.com/feeds/9128700047069516174/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-error-messages.blogspot.com/2009/08/class-interface-or-enum-expected.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/9128700047069516174'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/9128700047069516174'/><link rel='alternate' type='text/html' href='http://java-error-messages.blogspot.com/2009/08/class-interface-or-enum-expected.html' title='class, interface, or enum expected'/><author><name>Shamsuddin Ahammad</name><uri>http://www.blogger.com/profile/09496582775045632128</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/__0uCsTbc98U/S8WC0wZGIZI/AAAAAAAAFMs/8dRnDoXS7Rs/S220/Shamsuddin+Ahammad.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4816987417907886548.post-4515333710741274212</id><published>2009-05-20T09:54:00.004+06:00</published><updated>2011-08-15T10:45:31.028+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Class'/><category scheme='http://www.blogger.com/atom/ns#' term='Package'/><title type='text'>package system does not exist</title><content type='html'>Very simple error ‘package system does not exist’- most probably you have used ‘err’ or ‘in’ or ‘out’ field of the ‘System’ class of ‘java.lang’ package but you have given small s instead of capital S in the class name System.&lt;br /&gt;&lt;br /&gt;See the below code:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;public class PackageSystemDoesNotExistError&lt;br /&gt;{&lt;br /&gt;public static void main(String args[])&lt;br /&gt;{&lt;br /&gt;system.out.println("package system does not exist error"); // here s is small&lt;br /&gt;}&lt;br /&gt;}&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;But in the following code:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;public class PackageSystemDoesNotExistErrorSolved&lt;br /&gt;{&lt;br /&gt;public static void main(String args[])&lt;br /&gt;{&lt;br /&gt;System.out.println("package system does not exist error solved");//S is capital&lt;br /&gt;}&lt;br /&gt;}&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;Though System is not a package, as you have written system.out.println – three parts here (system, out and println) a package like statement, Java compiler considers it as package but as this package doesn’t exist, the error message is shown.&lt;br /&gt;&lt;br /&gt;So the solution is just change the small s of system to capital S.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4816987417907886548-4515333710741274212?l=java-error-messages.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-error-messages.blogspot.com/feeds/4515333710741274212/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-error-messages.blogspot.com/2009/05/package-system-does-not-exist.html#comment-form' title='12 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/4515333710741274212'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/4515333710741274212'/><link rel='alternate' type='text/html' href='http://java-error-messages.blogspot.com/2009/05/package-system-does-not-exist.html' title='package system does not exist'/><author><name>Shamsuddin Ahammad</name><uri>http://www.blogger.com/profile/09496582775045632128</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/__0uCsTbc98U/S8WC0wZGIZI/AAAAAAAAFMs/8dRnDoXS7Rs/S220/Shamsuddin+Ahammad.jpg'/></author><thr:total>12</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4816987417907886548.post-138358552231430982</id><published>2009-05-17T14:06:00.005+06:00</published><updated>2011-08-15T10:45:49.605+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Method'/><title type='text'>non-static method ... cannot be referenced from a static context</title><content type='html'>If you try to access a non static member of a class from a static context, you will see ‘non-static method … cannot be referenced from a static context’. For example, you might have tried to call a non static method from a static method. Bear in mind, you can access a static member (variables, methods etc) from both static and non-static context but cannot access non-static member from a static context.&lt;br /&gt;&lt;br /&gt;See the following example code:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;public class NonStaticMethodCannotBeReferencedFromAStaticContext&lt;br /&gt;{&lt;br /&gt;private double firstNumber;&lt;br /&gt;private double secondNumber;&lt;br /&gt;private double result;&lt;br /&gt;&lt;br /&gt;public void setFirstNumber(double firstNubmer)&lt;br /&gt;{&lt;br /&gt;this.firstNumber=firstNumber;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void setSecondNubmer(double secondNumber)&lt;br /&gt;{&lt;br /&gt;this.secondNumber=secondNumber;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public double add()&lt;br /&gt;{&lt;br /&gt;return firstNumber+secondNumber;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public double substract()&lt;br /&gt;{&lt;br /&gt;return firstNumber-secondNumber;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;public static void main(String args[])&lt;br /&gt;{&lt;br /&gt;setFirstNumber(10.35);// this is a non-static method but referenced from static main method&lt;br /&gt;setSecondNubmer(20.97);&lt;br /&gt;System.out.println("The addition is "+add());&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/blockquote&gt;For the solution you can:&lt;br /&gt;i) declare the non-static member as static and access them from the static context (not always; be careful, this may create other problems)&lt;br /&gt;ii) Create an instance of the class where the non-static members are and then reference the non-static members by the created instance or object.&lt;br /&gt;&lt;br /&gt;Browse &lt;a href="http://javatech-stuff.blogspot.com/2007/11/differences-between-java-terms.html"&gt;http://javatech-stuff.blogspot.com/2007/11/differences-between-java-terms.html&lt;/a&gt;&amp;nbsp;for understanding the differences between static and non-static member.&lt;br /&gt;&lt;br /&gt;Now see the solution below:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;public class NonStaticMethodCannotBeReferencedFromAStaticContextSolved&lt;br /&gt;{&lt;br /&gt;private double firstNumber;&lt;br /&gt;private double secondNumber;&lt;br /&gt;private double result;&lt;br /&gt;&lt;br /&gt;public void setFirstNumber(double firstNubmer)&lt;br /&gt;{&lt;br /&gt;this.firstNumber=firstNumber;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void setSecondNubmer(double secondNumber)&lt;br /&gt;{&lt;br /&gt;this.secondNumber=secondNumber;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public double add()&lt;br /&gt;{&lt;br /&gt;return firstNumber+secondNumber;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public double substract()&lt;br /&gt;{&lt;br /&gt;return firstNumber-secondNumber;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;public static void main(String args[])&lt;br /&gt;{&lt;br /&gt;NonStaticMethodCannotBeReferencedFromAStaticContextSolved object=new NonStaticMethodCannotBeReferencedFromAStaticContextSolved();&lt;br /&gt;object.setFirstNumber(10.35);// accessed by the instance named object&lt;br /&gt;object.setSecondNubmer(20.97);&lt;br /&gt;System.out.println("The addition is "+object.add());&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;/blockquote&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4816987417907886548-138358552231430982?l=java-error-messages.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-error-messages.blogspot.com/feeds/138358552231430982/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-error-messages.blogspot.com/2009/05/non-static-method-cannot-be-referenced.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/138358552231430982'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/138358552231430982'/><link rel='alternate' type='text/html' href='http://java-error-messages.blogspot.com/2009/05/non-static-method-cannot-be-referenced.html' title='non-static method ... cannot be referenced from a static context'/><author><name>Shamsuddin Ahammad</name><uri>http://www.blogger.com/profile/09496582775045632128</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/__0uCsTbc98U/S8WC0wZGIZI/AAAAAAAAFMs/8dRnDoXS7Rs/S220/Shamsuddin+Ahammad.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4816987417907886548.post-3556538913812408096</id><published>2009-05-17T14:05:00.003+06:00</published><updated>2011-08-15T10:46:09.917+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Expression'/><title type='text'>illegal start of expression</title><content type='html'>If a method is defined inside another method we may see ‘illegal start of expression’ error message. Remember that, we cannot define a method inside another method; we just can call a method inside another method. Sometimes it occurs just because of improper opening and closing of curly braces ( { or } ).&lt;br /&gt;&lt;br /&gt;See the following example code:&lt;br /&gt;&lt;blockquote&gt;public class IllegalStartOfExpression&lt;br /&gt;{&lt;br /&gt;public void methodA()&lt;br /&gt;{&lt;br /&gt;System.out.println("This is method A");&lt;br /&gt;&lt;br /&gt;/* methodB is defined inside methodA because we didn’t close methodA before defining methodB*/&lt;br /&gt;&lt;br /&gt;public void methodB()&lt;br /&gt;{&lt;br /&gt;System.out.println("This is method B");&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;Now see the solution:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;public class IllegalStartOfExpression&lt;br /&gt;{&lt;br /&gt;public void methodA()&lt;br /&gt;{&lt;br /&gt;System.out.println("This is method A");&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;/*  methodA is finished then, methodB is being defined*/&lt;br /&gt;public void methodB()&lt;br /&gt;{&lt;br /&gt;System.out.println("This is method B");&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;/blockquote&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4816987417907886548-3556538913812408096?l=java-error-messages.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-error-messages.blogspot.com/feeds/3556538913812408096/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-error-messages.blogspot.com/2009/05/illegal-start-of-expression.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/3556538913812408096'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/3556538913812408096'/><link rel='alternate' type='text/html' href='http://java-error-messages.blogspot.com/2009/05/illegal-start-of-expression.html' title='illegal start of expression'/><author><name>Shamsuddin Ahammad</name><uri>http://www.blogger.com/profile/09496582775045632128</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/__0uCsTbc98U/S8WC0wZGIZI/AAAAAAAAFMs/8dRnDoXS7Rs/S220/Shamsuddin+Ahammad.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4816987417907886548.post-9188262171706727467</id><published>2009-05-17T14:04:00.004+06:00</published><updated>2011-08-15T10:46:29.207+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Expression'/><category scheme='http://www.blogger.com/atom/ns#' term='Class'/><category scheme='http://www.blogger.com/atom/ns#' term='Variable'/><category scheme='http://www.blogger.com/atom/ns#' term='Method'/><title type='text'>identifier expected</title><content type='html'>This error message is shown when the statements are not written in proper place. Most often, mistakenly, we may write the processing task (for example assigning value to a variable; writing a loop etc.) outside of any method. In this situation we may see this type of error message.&lt;br /&gt;&lt;br /&gt;Then the solution is to write such statements inside the appropriate methods.&lt;br /&gt;&lt;br /&gt;See the example code below:&lt;br /&gt;&lt;blockquote&gt;public class IdentifierExptected&lt;br /&gt;{&lt;br /&gt;int number1,number1,sum;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;number1=10; // identifier expected&lt;br /&gt;number2=20; // identifier expected&lt;br /&gt;sum=number1+number2; // identifier expected&lt;br /&gt;&lt;br /&gt;/*&lt;br /&gt;The assignment statement must be written inside a method. Variables can also be assigned/ initialized during the declaration.&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;public void display()&lt;br /&gt;{&lt;br /&gt;System.out.println("Number 1 = "+number1);&lt;br /&gt;System.out.println("Number 2 = "+number2);&lt;br /&gt;System.out.println("Sum = "+sum);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/blockquote&gt;See the solution now:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;public class IdentifierExptectedSolved&lt;br /&gt;{&lt;br /&gt;int number1=10,number2=20,sum;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;public void sum()&lt;br /&gt;{&lt;br /&gt;sum=number1+number2;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;public void display()&lt;br /&gt;{&lt;br /&gt;System.out.println("Number 1 = "+number1);&lt;br /&gt;System.out.println("Number 2 = "+number2);&lt;br /&gt;System.out.println("Sum = "+sum);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;}&lt;/blockquote&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4816987417907886548-9188262171706727467?l=java-error-messages.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-error-messages.blogspot.com/feeds/9188262171706727467/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-error-messages.blogspot.com/2009/05/expected.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/9188262171706727467'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/9188262171706727467'/><link rel='alternate' type='text/html' href='http://java-error-messages.blogspot.com/2009/05/expected.html' title='identifier expected'/><author><name>Shamsuddin Ahammad</name><uri>http://www.blogger.com/profile/09496582775045632128</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/__0uCsTbc98U/S8WC0wZGIZI/AAAAAAAAFMs/8dRnDoXS7Rs/S220/Shamsuddin+Ahammad.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4816987417907886548.post-1779673356206279275</id><published>2008-12-01T15:28:00.007+06:00</published><updated>2011-08-15T10:47:11.970+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Class'/><title type='text'>Exception in thread "main" java.lang.NoClassDefFoundError: [ClassName]</title><content type='html'>If a class file does not exist or the class is in such a package which is not in the CLASSPATH but you are trying to run that class, then you may see "Exception in thread "main" java.lang.NoClassDefFoundError: [ClassName]".&lt;br /&gt;&lt;br /&gt;Sometimes, by mistake, we(the students) try to execute a Java program without compiling it successfully. If a Java class is not compiled successfully, no class file (a file with extension class) is generated. So we need to compile the Java program at first, then it should be run.&lt;br /&gt;&lt;br /&gt;The class might be in another directory or package. The class must be in the CLASSPATH for the successful running.&lt;br /&gt;&lt;br /&gt;In another situation along with the above error message you may see "CMD.EXE was started with the above path as the current directory. UNC paths are not supported.  Defaulting to Windows directory" and "CMD does not support UNC paths as current directories". You may see this when you run a program by a batch file or by using TextPad etc. This error means you are running a class which is located in a remote machine and you have given the address of the class like \\RemotePC\directory\ClassName. You should bring the class to your PC (if required) to run it. Or if you want to call a class from the remote PC you may use RMI.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4816987417907886548-1779673356206279275?l=java-error-messages.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-error-messages.blogspot.com/feeds/1779673356206279275/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-error-messages.blogspot.com/2008/12/exception-in-thread-main.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/1779673356206279275'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/1779673356206279275'/><link rel='alternate' type='text/html' href='http://java-error-messages.blogspot.com/2008/12/exception-in-thread-main.html' title='Exception in thread &quot;main&quot; java.lang.NoClassDefFoundError: [ClassName]'/><author><name>Shamsuddin Ahammad</name><uri>http://www.blogger.com/profile/09496582775045632128</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/__0uCsTbc98U/S8WC0wZGIZI/AAAAAAAAFMs/8dRnDoXS7Rs/S220/Shamsuddin+Ahammad.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4816987417907886548.post-1765127931907598504</id><published>2008-11-30T17:54:00.005+06:00</published><updated>2011-08-15T10:48:13.033+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Class'/><title type='text'>class [ClassName] is public, should be declared in a file named [ClassName].java</title><content type='html'>We get error message "class [ClassName] is public, should be declared in a file named [ClassName].java" if the file name of the Java source program is not same as the public class name.&lt;br /&gt;&lt;br /&gt;Solution is to rename the file or the class name to make them same. If a public class name is ABC then the file name of that class must be ABC.java. So always copy the class name and paste it when naming the file, then we will not face this error anymore.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4816987417907886548-1765127931907598504?l=java-error-messages.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-error-messages.blogspot.com/feeds/1765127931907598504/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-error-messages.blogspot.com/2008/11/class-classname-is-public-should-be.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/1765127931907598504'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/1765127931907598504'/><link rel='alternate' type='text/html' href='http://java-error-messages.blogspot.com/2008/11/class-classname-is-public-should-be.html' title='class [ClassName] is public, should be declared in a file named [ClassName].java'/><author><name>Shamsuddin Ahammad</name><uri>http://www.blogger.com/profile/09496582775045632128</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/__0uCsTbc98U/S8WC0wZGIZI/AAAAAAAAFMs/8dRnDoXS7Rs/S220/Shamsuddin+Ahammad.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4816987417907886548.post-2312482283296147186</id><published>2008-11-18T18:32:00.008+06:00</published><updated>2011-08-15T10:48:34.201+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Method'/><title type='text'>Exception in thread "main" java.lang.NoSuchMethodError: main</title><content type='html'>'Exception in thread "main" java.lang.NoSuchMethodError: main' is a run time error message. If the main method is not properly defined, we may see this error message. You know if you want to execute/run a program that program must have a main method of the following signature:&lt;br /&gt;&lt;br /&gt;public static void main(String args[])&lt;br /&gt;&lt;br /&gt;Generally we do the following mistakes in this regard:&lt;br /&gt;&lt;br /&gt;1. May be, you haven't defined the main method at all. Define it at first then run it.&lt;br /&gt;&lt;br /&gt;2. The method name is not correctly written. The spelling will be exactly in lower case 'main', if we write 'Main' - it will be an error.&lt;br /&gt;&lt;br /&gt;For example:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;public class NoSuchMethodErrorMain&lt;br /&gt;{&lt;br /&gt;public static void Main(String args) // M is capital here&lt;br /&gt;{&lt;br /&gt;System.out.println("Java is an Object Oriented Language");&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;3. The keyword 'static' is omitted. The main method must be static.&lt;br /&gt;&lt;br /&gt;For example,&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;public class NoSuchMethodErrorMain&lt;br /&gt;{&lt;br /&gt;public void main(String args) // keyword static is missing&lt;br /&gt;{&lt;br /&gt;System.out.println("Java is an Object Oriented Language");&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;4. The parameter is not declared. Java main method must have a String array parameter. Sometimes, we forget to put [] after the data type or the parameter name (args, here).&lt;br /&gt;&lt;br /&gt;For example:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;public class NoSuchMethodErrorMain&lt;br /&gt;{&lt;br /&gt;public static void main() // parameter problem&lt;br /&gt;{&lt;br /&gt;System.out.println("Java is an Object Oriented Language");&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;OR&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;public class NoSuchMethodErrorMain&lt;br /&gt;{&lt;br /&gt;public static void main(String args) // the parameter is not array&lt;br /&gt;{&lt;br /&gt;System.out.println("Java is an Object Oriented Language");&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;The correct code will be:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;public class NoSuchMethodErrorMainSolution&lt;br /&gt;{&lt;br /&gt;public static void main(String args[])&lt;br /&gt;{&lt;br /&gt;System.out.println("Java is an Object Oriented Language");&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;/blockquote&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4816987417907886548-2312482283296147186?l=java-error-messages.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-error-messages.blogspot.com/feeds/2312482283296147186/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-error-messages.blogspot.com/2008/11/exception-in-thread-main.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/2312482283296147186'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/2312482283296147186'/><link rel='alternate' type='text/html' href='http://java-error-messages.blogspot.com/2008/11/exception-in-thread-main.html' title='Exception in thread &quot;main&quot; java.lang.NoSuchMethodError: main'/><author><name>Shamsuddin Ahammad</name><uri>http://www.blogger.com/profile/09496582775045632128</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/__0uCsTbc98U/S8WC0wZGIZI/AAAAAAAAFMs/8dRnDoXS7Rs/S220/Shamsuddin+Ahammad.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4816987417907886548.post-265871589215507667</id><published>2008-11-18T18:14:00.007+06:00</published><updated>2011-08-15T10:49:06.324+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Method'/><title type='text'> is already defined</title><content type='html'>If we declare a variable in a method more than once than we see '&lt;variablename&gt; is already defined'. Find out the variable for which the message is shown and check whether you have declared the variable more than one time in a particular block.&lt;br /&gt;&lt;br /&gt;If we compile the following code we will see 'country is already defined in myMethod()'&lt;br /&gt;&lt;blockquote&gt;public class AlreadyDefinedSolution&lt;br /&gt;{&lt;br /&gt;public void myMethod()&lt;br /&gt;{&lt;br /&gt;String country;&lt;br /&gt;String country="Bangladesh";// declared again&lt;br /&gt;System.out.println(country);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;Now the solution is to remove the declaration 'String' from the assignment statement.&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;public class AlreadyDefinedSolution&lt;br /&gt;{&lt;br /&gt;public void myMethod()&lt;br /&gt;{&lt;br /&gt;String country;&lt;br /&gt;country="Bangladesh";//declaration removed&lt;br /&gt;System.out.println(country);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;/blockquote&gt;&lt;blockquote&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;/variablename&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4816987417907886548-265871589215507667?l=java-error-messages.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-error-messages.blogspot.com/feeds/265871589215507667/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-error-messages.blogspot.com/2008/11/is-already-defined.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/265871589215507667'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/265871589215507667'/><link rel='alternate' type='text/html' href='http://java-error-messages.blogspot.com/2008/11/is-already-defined.html' title='&lt;variableName&gt; is already defined'/><author><name>Shamsuddin Ahammad</name><uri>http://www.blogger.com/profile/09496582775045632128</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/__0uCsTbc98U/S8WC0wZGIZI/AAAAAAAAFMs/8dRnDoXS7Rs/S220/Shamsuddin+Ahammad.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4816987417907886548.post-1412047444038567401</id><published>2008-11-18T18:07:00.006+06:00</published><updated>2011-08-15T10:49:36.907+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Class'/><title type='text'>reached end of file while parsing</title><content type='html'>The error 'reached end of file while parsing' occurs because of curly braces } problem. You have given either more or less curly braces } than the required number of } braces.&lt;br /&gt;&lt;br /&gt;See the code below:&lt;br /&gt;&lt;blockquote&gt;public class ReachedEndOfFileWhileParsing&lt;br /&gt;{&lt;br /&gt;public static void main(String args[])&lt;br /&gt;{&lt;br /&gt;System.out.println("java-error-massages.blogspot.com");&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;Here two curly braces are started but only one is ended. We need to put another } after the display statement here like below:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;public class ReachedEndOfFileWhileParsingSolution&lt;br /&gt;{&lt;br /&gt;public static void main(String args[])&lt;br /&gt;{&lt;br /&gt;System.out.println("java-error-massages.blogspot.com");&lt;br /&gt;}// it is now given&lt;br /&gt;&lt;br /&gt;}&lt;/blockquote&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4816987417907886548-1412047444038567401?l=java-error-messages.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-error-messages.blogspot.com/feeds/1412047444038567401/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-error-messages.blogspot.com/2008/11/reached-end-of-file-while-parsing.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/1412047444038567401'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/1412047444038567401'/><link rel='alternate' type='text/html' href='http://java-error-messages.blogspot.com/2008/11/reached-end-of-file-while-parsing.html' title='reached end of file while parsing'/><author><name>Shamsuddin Ahammad</name><uri>http://www.blogger.com/profile/09496582775045632128</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/__0uCsTbc98U/S8WC0wZGIZI/AAAAAAAAFMs/8dRnDoXS7Rs/S220/Shamsuddin+Ahammad.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4816987417907886548.post-8589460009601760444</id><published>2008-11-09T14:51:00.008+06:00</published><updated>2011-08-15T10:49:59.882+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Data Type'/><category scheme='http://www.blogger.com/atom/ns#' term='Variable'/><title type='text'>possible loss of precision</title><content type='html'>You may see the error message 'possible loss of precision' for any of the following reasons:&lt;br /&gt;&lt;br /&gt;1) You are trying to assign a fractional number into a float variable(why not?). Actually Java compiler considers the fractional number as double by default. You need to explicitly specify the fractional number as float by giving the character 'f' or 'F' after the the number, like float number = 65.37F;&lt;br /&gt;&lt;br /&gt;2) Or you are trying to assign the value of a double variable into a float variable. Memory size of double is 8 byte and that of float is 4 byte. If you assign a double value into a float value data may be lost. So be sure about the data type. If you are sure you want to assign the double into float, you need to cast it appropriately, like float floatVariable = (float)doubleVariable;&lt;br /&gt;&lt;br /&gt;An example is given below:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;public class PossibleLossOfPrecision&lt;br /&gt;{&lt;br /&gt;public static void main(String args[])&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;float floatNumber1=65.37; // error&lt;br /&gt;double doubleNumber=65.37;&lt;br /&gt;float floatNumber2=doubleNumber; // error&lt;br /&gt;&lt;br /&gt;System.out.println(floatNumber1);&lt;br /&gt;System.out.println(doubleNumber);&lt;br /&gt;System.out.println(floatNumber2);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;}&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;The above code is wrong; write this code as below and the problem will be solved.&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;public class PossibleLossOfPrecisionSolution&lt;br /&gt;{&lt;br /&gt;public static void main(String args[])&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;float floatNumber1=65.37F; // error solved&lt;br /&gt;double doubleNumber=65.37;&lt;br /&gt;float floatNumber2=(float)doubleNumber; // error solved&lt;br /&gt;&lt;br /&gt;System.out.println(floatNumber1);&lt;br /&gt;System.out.println(doubleNumber);&lt;br /&gt;System.out.println(floatNumber2);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;}&lt;/blockquote&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4816987417907886548-8589460009601760444?l=java-error-messages.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-error-messages.blogspot.com/feeds/8589460009601760444/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-error-messages.blogspot.com/2008/11/possible-loss-of-precision.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/8589460009601760444'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/8589460009601760444'/><link rel='alternate' type='text/html' href='http://java-error-messages.blogspot.com/2008/11/possible-loss-of-precision.html' title='possible loss of precision'/><author><name>Shamsuddin Ahammad</name><uri>http://www.blogger.com/profile/09496582775045632128</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/__0uCsTbc98U/S8WC0wZGIZI/AAAAAAAAFMs/8dRnDoXS7Rs/S220/Shamsuddin+Ahammad.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4816987417907886548.post-198275293306350089</id><published>2008-11-09T14:10:00.008+06:00</published><updated>2011-08-15T10:50:23.367+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Data Type'/><title type='text'>integer number too large</title><content type='html'>We know that the maximum value of an int is 2147483647. If we write any whole number more than 2147483647 in our Java program, we may get this error message 'integer number too large' but may be you are trying to store this large number in a long type variable, then what to do? The solution is to put the letter 'l' or 'L' after the number. This happens, because the compiler considers the whole number as int by default and we specify the large number by character 'l' or 'L' as long number. Now the compiler will consider the number as long.&lt;br /&gt;&lt;br /&gt;For example, we are trying to compile the following Java code:&lt;br /&gt;&lt;blockquote&gt;public class IntegerNumberTooLarge&lt;br /&gt;{&lt;br /&gt;public static void main(String args[])&lt;br /&gt;{&lt;br /&gt;long number=965478213245;&lt;br /&gt;System.out.println(number);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;We will get 'integer number too large' from the above program. Now write the program as below the problem will be solved.&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;public class IntegerNumberTooLargeSolution&lt;br /&gt;{&lt;br /&gt;public static void main(String args[])&lt;br /&gt;{&lt;br /&gt;long number=965478213245L;&lt;br /&gt;System.out.println(number);&lt;br /&gt;}&lt;br /&gt;}&lt;/blockquote&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4816987417907886548-198275293306350089?l=java-error-messages.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-error-messages.blogspot.com/feeds/198275293306350089/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-error-messages.blogspot.com/2008/11/integer-number-too-large.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/198275293306350089'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/198275293306350089'/><link rel='alternate' type='text/html' href='http://java-error-messages.blogspot.com/2008/11/integer-number-too-large.html' title='integer number too large'/><author><name>Shamsuddin Ahammad</name><uri>http://www.blogger.com/profile/09496582775045632128</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/__0uCsTbc98U/S8WC0wZGIZI/AAAAAAAAFMs/8dRnDoXS7Rs/S220/Shamsuddin+Ahammad.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4816987417907886548.post-1634238854132366575</id><published>2008-11-04T23:39:00.006+06:00</published><updated>2011-08-15T10:50:45.248+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Expression'/><title type='text'>; (semi-colon) expected</title><content type='html'>Each java statement must ends with ; (semicolon) in Java. If we don’t put ; after any statement we will see ‘;’ expected&lt;br /&gt;&lt;br /&gt;Here is an example of this error:&lt;br /&gt;&lt;blockquote&gt;public class SemicolonExpected&lt;br /&gt;{&lt;br /&gt;public static void main(String args[])&lt;br /&gt;{&lt;br /&gt;int x=10,y=10    //no ; (semicolon) is given after this statement&lt;br /&gt;if(x==y)&lt;br /&gt;System.out.println(x +" and "+y+" is equal");&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;Here no ; (semicolon) is given after the x,y declaration statement. The correct code is:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;public class SemicolonExpectedSolution&lt;br /&gt;{&lt;br /&gt;public static void main(String args[])&lt;br /&gt;{&lt;br /&gt;int x=10,y=10;   //; (semicolon) is given now&lt;br /&gt;if(x==y)&lt;br /&gt;System.out.println(x +" and "+y+" is equal");&lt;br /&gt;}&lt;br /&gt;}&lt;/blockquote&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4816987417907886548-1634238854132366575?l=java-error-messages.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-error-messages.blogspot.com/feeds/1634238854132366575/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-error-messages.blogspot.com/2008/11/semi-colon-expected.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/1634238854132366575'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/1634238854132366575'/><link rel='alternate' type='text/html' href='http://java-error-messages.blogspot.com/2008/11/semi-colon-expected.html' title='; (semi-colon) expected'/><author><name>Shamsuddin Ahammad</name><uri>http://www.blogger.com/profile/09496582775045632128</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/__0uCsTbc98U/S8WC0wZGIZI/AAAAAAAAFMs/8dRnDoXS7Rs/S220/Shamsuddin+Ahammad.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4816987417907886548.post-4392988587351222610</id><published>2008-11-04T23:37:00.005+06:00</published><updated>2011-08-15T10:51:02.546+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Variable'/><title type='text'>variable … might not have been initialized</title><content type='html'>We see “variable might not have been initialized” when we try to use the value of a variable before assigning any value to that variable. Each local variable must be assigned a value before further using it.&lt;br /&gt;&lt;br /&gt;Here is an example of this error :&lt;br /&gt;&lt;blockquote&gt;public class VariableMightNotHaveBeenInitialized&lt;br /&gt;{&lt;br /&gt;public static void main(String args[])&lt;br /&gt;{&lt;br /&gt;int a,b,c;&lt;br /&gt;a=10;&lt;br /&gt;c=a+b;&lt;br /&gt;System.out.println("The sum is "+c);&lt;br /&gt;}&lt;br /&gt;}&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;Here variable ‘b’ is added with variable ‘a’ before assigning any value.&lt;br /&gt;&lt;br /&gt;Correct code is:&lt;br /&gt;&lt;blockquote&gt;public class VariableMightNotHaveBeenInitializedSolution&lt;br /&gt;{&lt;br /&gt;public static void main(String args[])&lt;br /&gt;{&lt;br /&gt;int a,b,c;&lt;br /&gt;a=10;&lt;br /&gt;b=20;&lt;br /&gt;c=a+b;&lt;br /&gt;System.out.println("The sum is "+c);&lt;br /&gt;}&lt;br /&gt;}&lt;/blockquote&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4816987417907886548-4392988587351222610?l=java-error-messages.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-error-messages.blogspot.com/feeds/4392988587351222610/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-error-messages.blogspot.com/2008/11/variable-might-not-have-been.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/4392988587351222610'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/4392988587351222610'/><link rel='alternate' type='text/html' href='http://java-error-messages.blogspot.com/2008/11/variable-might-not-have-been.html' title='variable … might not have been initialized'/><author><name>Shamsuddin Ahammad</name><uri>http://www.blogger.com/profile/09496582775045632128</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/__0uCsTbc98U/S8WC0wZGIZI/AAAAAAAAFMs/8dRnDoXS7Rs/S220/Shamsuddin+Ahammad.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4816987417907886548.post-2877957132794711683</id><published>2008-11-04T23:36:00.005+06:00</published><updated>2011-08-15T10:51:20.008+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Class'/><category scheme='http://www.blogger.com/atom/ns#' term='Method'/><title type='text'>missing method body, or declare abstract</title><content type='html'>If we put a ; (semicolon) after the method header (i.e., before starting the method body) when we are defining a concrete method (which method has body) then we will see “missing method body, or declare abstract”. Another reason is if we don’t write the keyword ‘abstract’ for an abstract method (a method without body), we’ll also see this message.&lt;br /&gt;To resolve the problem we must remove the ; (semicolon) from the header of the concrete method or if it is an abstract method the keyword ‘abstract’ must be written in the method header.&lt;br /&gt;&lt;br /&gt;Here is an example of this error:&lt;br /&gt;&lt;blockquote&gt;public abstract class MissingMethodBodyOrDeclareAbstract&lt;br /&gt;{&lt;br /&gt;public void display(String message);&lt;br /&gt;{&lt;br /&gt;System.out.println(message);&lt;br /&gt;}&lt;br /&gt;public void display();&lt;br /&gt;}&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;Here, a ; (semicolon) is given after the method header of the first display method (with parameter). And for the second display method, keyword ‘abstract’ is not stated in the header and it doesn’t have any body also. Here it is to be noted that if a class contains an abstract method, the class must also be abstract.&lt;br /&gt;&lt;br /&gt;The correct code is:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;public abstract class MissingMethodBodyOrDeclareAbstractSolution&lt;br /&gt;{&lt;br /&gt;public void display(String message)&lt;br /&gt;{&lt;br /&gt;System.out.println(message);&lt;br /&gt;}&lt;br /&gt;public abstract void display();&lt;br /&gt;}&lt;/blockquote&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4816987417907886548-2877957132794711683?l=java-error-messages.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-error-messages.blogspot.com/feeds/2877957132794711683/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-error-messages.blogspot.com/2008/11/missing-method-body-or-declare-abstract.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/2877957132794711683'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/2877957132794711683'/><link rel='alternate' type='text/html' href='http://java-error-messages.blogspot.com/2008/11/missing-method-body-or-declare-abstract.html' title='missing method body, or declare abstract'/><author><name>Shamsuddin Ahammad</name><uri>http://www.blogger.com/profile/09496582775045632128</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/__0uCsTbc98U/S8WC0wZGIZI/AAAAAAAAFMs/8dRnDoXS7Rs/S220/Shamsuddin+Ahammad.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4816987417907886548.post-9214959040302969073</id><published>2008-11-04T23:35:00.005+06:00</published><updated>2011-08-15T10:51:42.698+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Selection'/><title type='text'>else without if</title><content type='html'>Programmers may see message “else without if” when the selection (if ... else if ... else) structure is used. This may happen for any of the following reasons:&lt;br /&gt;Semicolon (;) is given after the last parenthesis of the condition&lt;br /&gt;Error in use of the curly braces ( } ), may be the } is not closed before starting the next else if or the else or } is given more.&lt;br /&gt;&lt;br /&gt;Here is an example of  this error:&lt;br /&gt;&lt;blockquote&gt;public class ElseWithoutIf&lt;br /&gt;{&lt;br /&gt;public static void main(String args[])&lt;br /&gt;{&lt;br /&gt;int a=10,b=5;&lt;br /&gt;if(a==b);&lt;br /&gt;{&lt;br /&gt;System.out.println(a+" is not equal to "+b);&lt;br /&gt;else&lt;br /&gt;{&lt;br /&gt;System.out.println(a+" is equal "+b);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;Here we have given ; (semicolon) at the last of the first condition, it’s an error. Again, we haven’t closed the } of the if i.e., else is written within the ‘ if’. So we need to remove the ; and put another } before the else.&lt;br /&gt;&lt;br /&gt;Now the correct code is:&lt;br /&gt;&lt;blockquote&gt;public class ElseWithoutIfSolution&lt;br /&gt;{&lt;br /&gt;public static void main(String args[])&lt;br /&gt;{&lt;br /&gt;int a=10,b=5;&lt;br /&gt;if(a==b)&lt;br /&gt;{&lt;br /&gt;System.out.println(a+" is not equal to "+b);&lt;br /&gt;}&lt;br /&gt;else&lt;br /&gt;{&lt;br /&gt;System.out.println(a+" is equal "+b);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;/blockquote&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4816987417907886548-9214959040302969073?l=java-error-messages.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-error-messages.blogspot.com/feeds/9214959040302969073/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-error-messages.blogspot.com/2008/11/else-without-if.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/9214959040302969073'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/9214959040302969073'/><link rel='alternate' type='text/html' href='http://java-error-messages.blogspot.com/2008/11/else-without-if.html' title='else without if'/><author><name>Shamsuddin Ahammad</name><uri>http://www.blogger.com/profile/09496582775045632128</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/__0uCsTbc98U/S8WC0wZGIZI/AAAAAAAAFMs/8dRnDoXS7Rs/S220/Shamsuddin+Ahammad.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4816987417907886548.post-6934571705677732199</id><published>2008-11-04T23:30:00.005+06:00</published><updated>2011-08-15T10:52:06.631+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Class'/><category scheme='http://www.blogger.com/atom/ns#' term='Variable'/><category scheme='http://www.blogger.com/atom/ns#' term='Method'/><title type='text'>cannot find symbol / cannot resolve symbol</title><content type='html'>“cannot find symbol” or “cannot resolve symbol” is the most common error message which the programmers get from the compiler. However this error message may mean that the variable/method/class/object used are not declared/defined properly. In most cases, this happens because:&lt;br /&gt;&lt;br /&gt;· The variable/object is not declared or the spelling of variable/object declaration &amp;amp; later use of that variable/object is not same.&lt;br /&gt;&lt;br /&gt;· The method is not defined or the spelling of the method definition and method calling is not same or the number and/or type of parameters are wrongly given when calling the method or the method where it is defined is not imported properly (in case of class library methods, the package where the method is defined is not imported)&lt;br /&gt;&lt;br /&gt;· If the message is shown for a class, the package of that class might not have been imported or the spelling is wrong.&lt;br /&gt;&lt;br /&gt;The solution of that problem is to check the spelling at first, Java programmers see this message most often just because of the wrong spelling( be careful about the case also, as Java is a case sensitive language). If the spelling is correct check whether the required package is imported.&lt;br /&gt;&lt;br /&gt;Here is an example of this error :&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;public class CannotFindSymbol&lt;br /&gt;{&lt;br /&gt;public static void main(String args[])&lt;br /&gt;{&lt;br /&gt;int quantity;&lt;br /&gt;Scanner input=new Scanner(System.in);&lt;br /&gt;System.out.print(“Enter the quantity: ”);&lt;br /&gt;quntity=imput.nextInteger();&lt;br /&gt;System.out.println(“Your number is ”+quantity);&lt;br /&gt;}&lt;br /&gt;}&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;In the above code, there are many lines where we will get this error message.&lt;br /&gt;&lt;br /&gt;At first it will say Scanner cannot be resolved/found because the package of this class java.util is not imported.&lt;br /&gt;&lt;br /&gt;Also problem in ‘quntity’ as the variable is declared as ‘quantity’&lt;br /&gt;&lt;br /&gt;Error in ‘imput’ as the object is created as ‘input’&lt;br /&gt;&lt;br /&gt;If you correct all the errors it will show error message for nextIntger as the actual method name is nextInt in class Scanner&lt;br /&gt;&lt;br /&gt;Now the correct code is:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;import java.util.*;&lt;br /&gt;public class CannotFindSymbolSolution&lt;br /&gt;{&lt;br /&gt;public static void main(String args[])&lt;br /&gt;{&lt;br /&gt;int quantity;&lt;br /&gt;Scanner input=new Scanner(System.in);&lt;br /&gt;System.out.print("Enter the quantity: ");&lt;br /&gt;quantity=input.nextInt();&lt;br /&gt;System.out.println("Your number is "+quantity);&lt;br /&gt;}&lt;br /&gt;}&lt;/blockquote&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4816987417907886548-6934571705677732199?l=java-error-messages.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-error-messages.blogspot.com/feeds/6934571705677732199/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://java-error-messages.blogspot.com/2008/11/cannot-find-symbol-cannot-resolve.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/6934571705677732199'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4816987417907886548/posts/default/6934571705677732199'/><link rel='alternate' type='text/html' href='http://java-error-messages.blogspot.com/2008/11/cannot-find-symbol-cannot-resolve.html' title='cannot find symbol / cannot resolve symbol'/><author><name>Shamsuddin Ahammad</name><uri>http://www.blogger.com/profile/09496582775045632128</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/__0uCsTbc98U/S8WC0wZGIZI/AAAAAAAAFMs/8dRnDoXS7Rs/S220/Shamsuddin+Ahammad.jpg'/></author><thr:total>0</thr:total></entry></feed>
