• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Java.jpg
[Thumbnail for Java.jpg]
 
Ranch Hand
Posts: 774
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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,
 
Ranch Hand
Posts: 633
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Chirath Uralagamage
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 774
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 774
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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...
 
Ranch Hand
Posts: 206
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.


 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 774
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 774
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Ranch Hand
Posts: 196
Android Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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.
 
Chirath Uralagamage
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 206
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 774
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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,
 
author
Posts: 9050
21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
my compiler couldn't read the original .jpg
 
Prithvi Sehgal
Ranch Hand
Posts: 774
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bert Bates wrote:my compiler couldn't read the original .jpg



That was a good way to ease up tension Bert.

BR,
 
Ranch Hand
Posts: 507
Netbeans IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Ranch Hand
Posts: 300
Eclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Chirath Uralagamage , have you managed to resolve the issue or are you still searching for solution ?
 
Chirath Uralagamage
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 774
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 507
Netbeans IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 774
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bert Bates wrote:my compiler couldn't read the original .jpg



why do you need to read the jpg?
 
Chirath Uralagamage
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 774
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Chirath,

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

Happy ending to the thread

BR,
 
Acetylsalicylic acid is aspirin. This could be handy too:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic