I have 2 java programs in separate c: \ test and in another c: \ test \ new
I can compile it without any error \ javac
but when I try to execute the file \ java it shows an error like this
ButtonFrame on the ButtonFrame.MakeButton (ButtonTest3.java 42) on the exception button "AWT-EventQueue-0" java.lang.NullPointerException. & Lt; Init & gt; Button (ButtonTest3.java29) ButtonTest $ 1.run (ButtonTest.java.1) at Java.awt.event.InvocationEvent.dispatch (unknown source) at java.awt.EventQueue.dispatchEvent (unknown source) java.awt.EventDispatchThread (Unknown source) on Java.awt.EventDispatchThread.pumpEventsForHierarchy (unknown source) on java.awt.EventDispatchThread.pumpEventsForFilter (unknown source) on .pumpOneEventForFilters (Unknown Source) java.awt.EventDispatchThread.pumpEvents (unknown source) java.awt.EventDispatchThread.pumpEvents IpatchThread.run at (unknown source) java.awt.EventD (unknown source)
I put it in my squared
CLASSPATH value-C : \ Test; C: \ test \ new
But if I change the value order to CLASSPATH
CLASSPATH value- C: \ test \ new; C: \ test
error has settled
why ?? Could it be that only the case of the order?
You have a class with the same name in both the folders. There is a version of class in the C: \ Test
button code3 which has a programming bug, due to which it is NullPointerException
. There is a separate version of ButtonTest3
class in C: \ test \ new
that this bug is not, or maybe a ButtonTest
class which is C: \ Test
does things completely different than one.
Clearing your classpace It is not a good idea to duplicate classes with separate versions with the same signature in the classpath. If you intend that new
is considered to be a package identifier, then you have to keep it away from the space. However, such a package name may have a compilation error, so that it may be.
In the form of a bug, a NullPointerException
is relatively trivial: first look at the first line of the first stacktrace: the
buttonframe. MacBootton (ButtonTest 3.Java 42)
It's saying that it happened in the line under the button> buttonTest 3
class, MacButton () < Now go to the line of code ButtonTest3.java
within the / code> method, something like this:
someObject.doSomething ();
See if there is a dot operator .
is used to access a method or to enter an area of an object. NullPointerException
means that someObject
is null
at a special moment. There is no example!
This is a simple solution: Just make sure that not null
you are currently using / entering it:
someObject = new SomeObject (); // ... someObject.doSomething ();
Comments
Post a Comment