• 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

Strange error on running the simplest code there is.

 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I know it sounds ridiculous, but its true!



It compiles and run fine. Now, when I change Klasa0 to Klasa1 it compiles but when i try to run it, I get:


Exception in thread "main" java.lang.NoSuchMethodError: Klasa1.<init>(Ljava/lang/String;)V
at Test.main(Test.java:3)



The same happens when i put 2 and 3 at the end of Klasax name.
Here comes the best, when I change it to Klasa4 it compiles but when I try to run it gives:


Exception in thread "main" java.lang.InstantiationError: Klasa4
at Test.main(Test.java:3)



When i change it to Klasa5 (6, 7, 8, 9 or 0) its OK, but not for (Klasa1, Klasa2, Klasa3 and Klasa4 - gives different error)
Unfortunately (for me) i 've checked it on two other machines and it runs fine with all names.

What kind of magic may be lurking in my JVM that stops me from running this code?

My version of java is :


java version "1.6.0_06"
Java(TM) SE Runtime Environment (build 1.6.0_06-b02)
Java HotSpot(TM) Client VM (build 10.0-b22, mixed mode, sharing)



And i've tried to compile it with -source 1.3, 1.4 and 1.5. The effect is the same.

Anyone have a clue?



 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you post your code after you make the change? It almost looks like you are changing the class name, but not the Constructor name as well.

-- Edit --

I take that back. Take a look around your classpath, it sounds like you may already have classes named Klasa1, Klasa2, Klasa3, or Klasa4 in your classpath, which may be interfering with your running.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The most likely explanation is that your first machine is already littered with class files named "Klasa1", "Klasa2", etc, somewhere on your class path, and those classes don't include the same constructor. Use your operating system's facilities for finding files to find all files named "Klasa*.class", and delete them, then try again.
 
Pawel Nowacki
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, I expected that question
Here what im doing step by step:

1. Write and save (Test.java) this code in notepad:

class Test {
public static void main (String [] args) {
Klasa0 k = new Klasa0("a");
}
}

class Klasa0 {
private String name;

Klasa0(String name) {
this.name = name;
}
}

2. Compile:


# javac Test.java
#



3. Run:


# java Test
#



4. Open Test.java in notepad.
5. Replace all "Klasa0" to "Klasa1":



6. Compile:


# javac Test.java
#



7. Run:


# java Test
Exception in thread "main" java.lang.NoSuchMethodError: Klasa1.<init>(Ljava/lang/String;)V
at Test.main(Test.java:3)






 
Pawel Nowacki
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ernest, you were right. I had Klasa1, Klasa2, Klasa3 and Klasa4 class files addressed somwhere in the middle of my CLASSPATH var.
I thought my JVM went crazy, but that was only me in the end ..
Thank you.
 
reply
    Bookmark Topic Watch Topic
  • New Topic