This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Getting this same error all the time Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Getting this same error all the time "Exception in thread"" Watch "Getting this same error all the time "Exception in thread"" New topic
Author

Getting this same error all the time "Exception in thread"

Chirath Uralagamage
Greenhorn

Joined: Sep 11, 2011
Posts: 17
I am using windows 7. I don't know whether it is a problem of the OS or not. But I'm quite sure that my codes are correct. The destinations are also correct. The source file is also in the picture attached.

Thanks in advance mates
Chirath


[Thumbnail for Java.jpg]

Prithvi Sehgal
Ranch Hand

Joined: Oct 13, 2009
Posts: 771
Hello,

If you closely observe your code, you are compiling class E and then trying to run class A. Thats why
its giving this issue. Another problem is, you should try to declare your class A public, rather then default
access.

HTH,

Prithvi/Beenish,
My Blog, Follow me on Twitter,Scjp Tips, When you score low in mocks, Generics,Scjp Notes, JavaStudyGroup
Pramod P Deore
Ranch Hand

Joined: Jul 15, 2008
Posts: 629

Actually you had saved file as E.java therefore you got this error. save file as A.java then it will compile.

If file contains any public class then file must be saved using public class name. And if there is no public class then you have to save file name as name of class where main method is declared. Here in class A you declared main method so rename file as A.java

Life is easy because we write the source code.....
Chirath Uralagamage
Greenhorn

Joined: Sep 11, 2011
Posts: 17
Prithvi Sehgal wrote:Hello,

If you closely observe your code, you are compiling class E and then trying to run class A. Thats why
its giving this issue. Another problem is, you should try to declare your class A public, rather then default
access.

HTH,


Thanks for the reply mate. I guess what you are saying is,that I should save the file as "A.java",right? I did it that way this time. But I get the same result.I need to tell you,the code DOES compile. It does not execute when I give the
"java A" command. BTW,this was a lesson at my Java class. This was an example what my teacher gave. It worked perfectly at the class. The same code at home doesn't work. It was Win XP in the class PC,and I'm using Win 7 at home. I was wondering if that's the problem here

Thanks
Prithvi Sehgal
Ranch Hand

Joined: Oct 13, 2009
Posts: 771
Try to make your class public A. Can you post your complete source code, i will compile at my machine and tell you.
It shouldn't be a problem.

BR,
Chirath Uralagamage
Greenhorn

Joined: Sep 11, 2011
Posts: 17
Prithvi Sehgal wrote:Try to make your class public A. Can you post your complete source code, i will compile at my machine and tell you.
It shouldn't be a problem.

BR,


Thanks mate,I added public in front of "void" in line 3. Same problem
the complete source code is,



class A{
int x;
void m(A a){
System.out.println(a.x);
a.x=200;
System.out.println(a.x);
}

public static void main(String args[]){
A b=new A();
b.x=100;
System.out.println(b.x);
b.m(b);
System.out.println(b.x);
}
}

Prithvi Sehgal
Ranch Hand

Joined: Oct 13, 2009
Posts: 771
Hello,

Please use CodeTags so that your code
snippet is appealing.

Well, its working perfectly fine on my machine. Please check your JavaFiles folder, is A.class file is getting
created there or not. Try to put your java files, in jdk/bin and run from there and see, because the main
issue i can see is, your .class file seems to be missing.

HTH,
Chirath Uralagamage
Greenhorn

Joined: Sep 11, 2011
Posts: 17
Prithvi Sehgal wrote:Hello,

Please use CodeTags so that your code
snippet is appealing.

Well, its working perfectly fine on my machine. Please check your JavaFiles folder, is A.class file is getting
created there or not. Try to put your java files, in jdk/bin and run from there and see, because the main
issue i can see is, your .class file seems to be missing.

HTH,


A.class file is created mate. It compiles. But doesn't run. I moved the file to jdk/bin and ran it from there. Same problem.
Chirath Uralagamage
Greenhorn

Joined: Sep 11, 2011
Posts: 17
Chirath Uralagamage wrote:
Prithvi Sehgal wrote:Hello,

Please use CodeTags so that your code
snippet is appealing.

Well, its working perfectly fine on my machine. Please check your JavaFiles folder, is A.class file is getting
created there or not. Try to put your java files, in jdk/bin and run from there and see, because the main
issue i can see is, your .class file seems to be missing.

HTH,


A.class file is created mate. It compiles. But doesn't run. I moved the file to jdk/bin and ran it from there. Same problem.


Works fine on Win XP mate. That's what I asked whether there is a problem in Win 7
Shiva.Om Kumar
Ranch Hand

Joined: Jun 14, 2010
Posts: 68
Chirath Uralagamage wrote:I am using windows 7. I don't know whether it is a problem of the OS or not. But I'm quite sure that my codes are correct. The destinations are also correct. The source file is also in the picture attached.

Thanks in advance mates
Chirath


Same code what you have in first post. No Change......

Now try following....

(Compile)
C:\>javac E.java

(run)
C:\>java A


Check out the reason below....

C:\>dir *.java
09/20/2011 10:45 AM 265 E.java


C:\>dir *.class
09/20/2011 10:55 AM 552 A.class


Hope it would be helpful...
Tommy Delson
Ranch Hand

Joined: Apr 13, 2011
Posts: 206
Tested and it works perfectly, your issue must be a windows environment issues, you need to check you "java" run time environment and windows 7 configuration correctly.

The problem seem like your run time environment is corrupted, try to uninstall and reinstall the JDK or reconfigure the JDK.




OCPJP6-05-11
"Your life is in your hands, to make of it what you choose."
dilan alex
Greenhorn

Joined: Sep 17, 2011
Posts: 27
Chirath Uralagamage wrote:I am using windows 7. I don't know whether it is a problem of the OS or not. But I'm quite sure that my codes are correct. The destinations are also correct. The source file is also in the picture attached.

Thanks in advance mates
Chirath


Hi Chirath,

Set your classpath corectly and try to run it again.

do it like this

.;%JAVA_HOME%\lib;

Regards,
Dilan.
Chirath Uralagamage
Greenhorn

Joined: Sep 11, 2011
Posts: 17
Shiva.Om Kumar wrote:
Chirath Uralagamage wrote:I am using windows 7. I don't know whether it is a problem of the OS or not. But I'm quite sure that my codes are correct. The destinations are also correct. The source file is also in the picture attached.

Thanks in advance mates
Chirath


Same code what you have in first post. No Change......

Now try following....

(Compile)
C:\>javac E.java

(run)
C:\>java A


Check out the reason below....

C:\>dir *.java
09/20/2011 10:45 AM 265 E.java


C:\>dir *.class
09/20/2011 10:55 AM 552 A.class


Hope it would be helpful...



I tried it after saving it as A.java too. Same problem dude. Works fine on Win XP. Not on Win 7
Chirath Uralagamage
Greenhorn

Joined: Sep 11, 2011
Posts: 17
dilan alex wrote:
Chirath Uralagamage wrote:I am using windows 7. I don't know whether it is a problem of the OS or not. But I'm quite sure that my codes are correct. The destinations are also correct. The source file is also in the picture attached.

Thanks in advance mates
Chirath


Hi Chirath,

Set your classpath corectly and try to run it again.

do it like this

.;%JAVA_HOME%\lib;

Regards,
Dilan.


Thanks for the reply Dilan,

I set the classpath as you told. But still I'm getting the same problem. It works on Win XP but not on Win 7. I wanna know why. I reinstalled the JDK,but same problem
Chirath Uralagamage
Greenhorn

Joined: Sep 11, 2011
Posts: 17
Tommy Delson wrote:Tested and it works perfectly, your issue must be a windows environment issues, you need to check you "java" run time environment and windows 7 configuration correctly.

The problem seem like your run time environment is corrupted, try to uninstall and reinstall the JDK or reconfigure the JDK.




Thanks for the reply mate,

I reinstalled the JDK in win 7. Same problem. I don't know how to configure java for win 7. I installed the version 6,update 27

Cheers
Prithvi Sehgal
Ranch Hand

Joined: Oct 13, 2009
Posts: 771
Hii,

Its working perfectly fine on windows 7 64 bit, i am using windows 7 only. Please always keep in mind, java has nothing to
do with platform as it is platform independent. It seems to be your JDK issue.

BR,
Chirath Uralagamage
Greenhorn

Joined: Sep 11, 2011
Posts: 17
Prithvi Sehgal wrote:Hii,

Its working perfectly fine on windows 7 64 bit, i am using windows 7 only. Please always keep in mind, java has nothing to
do with platform as it is platform independent. It seems to be your JDK issue.

BR,


Yeah mate,I know it's platform independent. I'm using Win 7,32 bit. I don't know what's wrong
Prithvi Sehgal
Ranch Hand

Joined: Oct 13, 2009
Posts: 771
Hi,
Do you have teamviewer with you. Add me up, i will be online in somtime, may be i can help debug it.

BR,
Chirath Uralagamage
Greenhorn

Joined: Sep 11, 2011
Posts: 17
Prithvi Sehgal wrote:Hi,
Do you have teamviewer with you. Add me up, i will be online in somtime, may be i can help debug it.

BR,


Nope mate. I don't know how it works. Any help? Thanks in advance
karthick chinnathambi
Ranch Hand

Joined: Jul 06, 2009
Posts: 196


If you closely observe your code, you are compiling class E and then trying to run class A. Thats why
its giving this issue. Another problem is, you should try to declare your class A public, rather then default
access.


This has nothing to do with the problem . Any class that is NOT public can be saved with any Name . But if you compile that JAVA file the class file generated will be of the name <defined_class_name>.class

In this case if you compile E.java you will get A.class.


Since you haven't declared any packages just put your .class file into
<your_jdk_path>/bin
folder. In command prompt go to this
<your_jdk_path>/bin
folder and
execute "java A" command . If you still have the issue , let me know.


KARTHICK.C , SCJP6-93%
(Born to Win)
Chirath Uralagamage
Greenhorn

Joined: Sep 11, 2011
Posts: 17
karthick chinnathambi wrote:

If you closely observe your code, you are compiling class E and then trying to run class A. Thats why
its giving this issue. Another problem is, you should try to declare your class A public, rather then default
access.


This has nothing to do with the problem . Any class that is NOT public can be saved with any Name . But if you compile that JAVA file the class file generated will be of the name <defined_class_name>.class

In this case if you compile E.java you will get A.class.


Since you haven't declared any packages just put your .class file into
<your_jdk_path>/bin
folder. In command prompt go to this
<your_jdk_path>/bin
folder and
execute "java A" command . If you still have the issue , let me know.


Yup mate. Still getting the problem
Tommy Delson
Ranch Hand

Joined: Apr 13, 2011
Posts: 206
The problem seem like you have two JRE installed on your machine so, you need to delete one on the "C:" drive and use the JRE in your JDK.

You need to tweak around and configure it, Google the web for instructions how to fix it if you don't know how.

Good luck and hope it help....
Prithvi Sehgal
Ranch Hand

Joined: Oct 13, 2009
Posts: 771

This has nothing to do with the problem . Any class that is NOT public can be saved with any Name . But if you compile that JAVA file the class file generated will be of the name <defined_class_name>.class

In this case if you compile E.java you will get A.class.


I know that mate. I was referring to his case that he is trying to refer a class may be which doesn't exist.

BR,
Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8717
my compiler couldn't read the original .jpg

Eliminate fossil fuel subsidies. (If you're not on the edge, you're taking up too much room.)
Prithvi Sehgal
Ranch Hand

Joined: Oct 13, 2009
Posts: 771
Bert Bates wrote:my compiler couldn't read the original .jpg


That was a good way to ease up tension Bert.

BR,
Yohan Weerasinghe
Ranch Hand

Joined: Oct 07, 2010
Posts: 485

Chirath Uralagamage wrote:I am using windows 7. I don't know whether it is a problem of the OS or not. But I'm quite sure that my codes are correct. The destinations are also correct. The source file is also in the picture attached.

Thanks in advance mates
Chirath


Didn't read all the replies here, but I am very familiar with this issue. I don't know what is the actual reason for this issue, but in most cases JAVA virtual machine is down (I have solved this issue more than 20 times ). Uninstall and reinstall JDK. Then when you are setting the Environmental Variables, I think it is better to use the EASIEST way. here it is

Open environment variables in advanced options of the My Computer
Under "user variables", click "new"
Type "PATH" as the variable name
Copy the location of the JDK bin folder, and paste it to the value section of the newly created user variable
Click OK


Are you better than me? Then please show me my mistakes..
Javin Paul
Ranch Hand

Joined: Oct 15, 2010
Posts: 276

@Chirath Uralagamage , have you managed to resolve the issue or are you still searching for solution ?


http://javarevisited.blogspot.com - java classpath - Java67 - java hashmap - java logging tips java interview questions Java Enum Tutorial
Chirath Uralagamage
Greenhorn

Joined: Sep 11, 2011
Posts: 17
Javin Paul wrote:@Chirath Uralagamage , have you managed to resolve the issue or are you still searching for solution ?


I still am having the problem. This works perfectly on winXP. But not on Win 7
Prithvi Sehgal
Ranch Hand

Joined: Oct 13, 2009
Posts: 771
Dear Chirath,

Where is your jdk installed, is it in the C drive? Is your JAVA_HOME defined?

Try running using the following command

java -cp A

If your jdk is in C, then try to run as a Administrative user. It might help. Let me know if it is fixed.,

BR,
Chirath Uralagamage
Greenhorn

Joined: Sep 11, 2011
Posts: 17
Prithvi Sehgal wrote:Dear Chirath,

Where is your jdk installed, is it in the C drive? Is your JAVA_HOME defined?

Try running using the following command

java -cp A

If your jdk is in C, then try to run as a Administrative user. It might help. Let me know if it is fixed.,

BR,


I don't know how to define JAVA_HOME. And I tried the java -cp A command,it gives a long error or something. I am logged into the administrator account of my Win 7,and yeah,jdk is in C:/Program Files/Java. Still am getting the problem
Yohan Weerasinghe
Ranch Hand

Joined: Oct 07, 2010
Posts: 485

Chirath Uralagamage wrote:
Prithvi Sehgal wrote:Dear Chirath,

Where is your jdk installed, is it in the C drive? Is your JAVA_HOME defined?

Try running using the following command

java -cp A

If your jdk is in C, then try to run as a Administrative user. It might help. Let me know if it is fixed.,

BR,


I don't know how to define JAVA_HOME. And I tried the java -cp A command,it gives a long error or something. I am logged into the administrator account of my Win 7,and yeah,jdk is in C:/Program Files/Java. Still am getting the problem


did you follow my advice?
Prithvi Sehgal
Ranch Hand

Joined: Oct 13, 2009
Posts: 771
Here is how you define your environment variable

Go to Computer
Right Mouse Click -> Click Properties
On left side Click -> Advanced Environment Settings
Advanced Tab - Bottom Click Environment Variables
On user variables click NEW and give

name of variable -> JAVA_HOME (All in caps)
variable value -> D:\jdk\jdk1.6 (its for me, for your give the root to your jdk)

See below System variables

Find the variable PATH -> click on Edit Path and at the end of Path put a semicolon and append like this

;D:\jdk\jdk1.6\bin;

Put same way on the CLASSPATH as well.

HTH,


Chirath Uralagamage
Greenhorn

Joined: Sep 11, 2011
Posts: 17
Bert Bates wrote:my compiler couldn't read the original .jpg


why do you need to read the jpg?
Chirath Uralagamage
Greenhorn

Joined: Sep 11, 2011
Posts: 17
Prithvi Sehgal wrote:Here is how you define your environment variable

Go to Computer
Right Mouse Click -> Click Properties
On left side Click -> Advanced Environment Settings
Advanced Tab - Bottom Click Environment Variables
On user variables click NEW and give

name of variable -> JAVA_HOME (All in caps)
variable value -> D:\jdk\jdk1.6 (its for me, for your give the root to your jdk)

See below System variables

Find the variable PATH -> click on Edit Path and at the end of Path put a semicolon and append like this

;D:\jdk\jdk1.6\bin;

Put same way on the CLASSPATH as well.

HTH,




Oh,at last!!! It works Thanks a lot mate. I don't know how to thank you. Thanks again
Prithvi Sehgal
Ranch Hand

Joined: Oct 13, 2009
Posts: 771
Dear Chirath,

Congratulations. I am glad, it helped you solve the problem

Happy ending to the thread

BR,
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Getting this same error all the time "Exception in thread"
 
Similar Threads
JQplus Question
ejb exam question
Use case in 486
ZerosOnesTwos...
Question on Pass-by-value for Primitves & References