![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: May 2006
Posts: 39
Rep Power: 0
![]() |
Sun Java Studio creator not running what another compiler does...
Basically I have two classes:
public class abc123 { public static void main(String[] args) { int val1 = 1, val2 = 2, sum; cba abc = new cba(); sum = abc.xcalc(val1, val2); } } ____________ public class cba { public int xcalc(int z, int y) { return z + y; } } ________________ when I compile both on Sun Java Studio creator and try to run them I get an error: java.lang.NoClassDefFoundError: class2/abc123 Exception in thread "main" Java Result: 1 If I run it off Jcreator it runs fine... could someone pelase helP? |
|
|
|
|
|
#2 |
|
Professional Programmer
Join Date: Mar 2005
Location: Student of University of Mumbai, Maharashtra State, India
Posts: 344
Rep Power: 4
![]() |
What are you running through Jcreator? (the class file?)
I hope you have saved the file with the name of the class where main function resides. This error is more common for committing mistakes with the above procedure. It shouldn't be anything else (AFAIK)
__________________
Visit: http://www.somaiya.edu |
|
|
|
|
|
#3 |
|
Programmer
Join Date: May 2006
Posts: 39
Rep Power: 0
![]() |
well one class is called abc123, the other is called ruff.
When I compile and run them using jcreator it works fine, when I do the same in Sun Java Studio it gives me that error... |
|
|
|
|
|
#4 |
|
Sexy Programmer
|
First, please you code tags for your code. second, Sun Java Studio is really slow and why are you using 2 IDE at once. Third place cba class within your main class.
Call this file "Abc.java" [PHP] public class Abc { public static void main(String[] args) { cba abc = new cba(); int val1 = 1, val2 = 2, sum; sum = abc.xcalc(val1, val2); } private class cba { public int xcalc(int z, int y) { return z + y; } } } [/PHP] Compile and run it, this will work fine regardless of any type of Java IDE
__________________
I would love to change the world, but they won't give me the source code! |
|
|
|
|
|
#5 |
|
Programmer
Join Date: May 2006
Posts: 39
Rep Power: 0
![]() |
I'm not using 2 IDE's, I'm only using Sun's IDE, but it's not working on it, but its working on jcreator.
I also want it to run from two serperate class files, not just one... |
|
|
|
|
|
#6 |
|
Sexy Programmer
|
Either you must have the two files in the same directory or just define the cba class in a packages.
[PHP] package mypackage.classes; class cba { public int xcalc(int z, int y) { return z + y; } } [/PHP] Then import that package where you would like to use that class [PHP] //main class import mypackage.classes; public class Abc { public static void main(String[] args) { cba abc = new cba(); int val1 = 1, val2 = 2, sum; sum = abc.xcalc(val1, val2); } } [/PHP] If this doesn't work, your IDE is f*cked up!
__________________
I would love to change the world, but they won't give me the source code! |
|
|
|
|
|
#7 |
|
Programmer
Join Date: May 2006
Posts: 39
Rep Power: 0
![]() |
I just don't understand why Sun's doesn't work werein jcreator does (also the linux based compiler at school also works)...
|
|
|
|
|
|
#8 |
|
Sexy Programmer
|
Did you do what I said to do?
__________________
I would love to change the world, but they won't give me the source code! |
|
|
|
|
|
#9 |
|
Programmer
Join Date: May 2006
Posts: 39
Rep Power: 0
![]() |
well I haven't read up on packages just yet, its actually in the next chapter, so I'm going to read it and see how it works and what to do exactly.
If the packaging doesnt work I'll come back ![]() |
|
|
|
|
|
#10 |
|
Sexy Programmer
|
It should, if not, your IDE is the problem then.
__________________
I would love to change the world, but they won't give me the source code! |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|