Getting java.lang.NoSuchMethodError when running code -


my code isn't running. error

exception in thread "main" java.lang.nosuchmethoderror: main

this code below...would please help?!

the problem comes final nested branch testdieclass.

public class diemod {      private final int max = 6;     private int facevalue;      public diemod() {         facevalue = 1;     }      public int roll() {         facevalue = (int) (math.random() * max) + 1;         return facevalue;     }      public void setfacevalue(int value) {         if (value >= 1 && value <= 6) {             facevalue = value;         }     }      public int getfacevalue() {         return facevalue;     }      public string tostring() {         string result = integer.tostring(facevalue);         return result;     }      public class testdieclass {          public static void main(string[] args) {             diemod die = new diemod();             die.setfacevalue(4);             system.out.println("input value : " + 4);             system.out.println("result value : " + die.getfacevalue());             die.setfacevalue(10);             system.out.println("input value : " + 10);             system.out.println("result value : " + die.getfacevalue());         }     } } 

remove public class testdieclass , work.

code:

public class diemod {      private final int max = 6;     private int facevalue;      public diemod() {         facevalue = 1;     }      public int roll() {         facevalue = (int) (math.random() * max) + 1;         return facevalue;     }      public void setfacevalue(int value) {         if (value >= 1 && value <= 6) {             facevalue = value;         }     }      public int getfacevalue() {         return facevalue;     }      public string tostring() {         string result = integer.tostring(facevalue);         return result;     }      // change made here     public static void main(string[] args) {         diemod die = new diemod();         die.setfacevalue(4);         system.out.println("input value : " + 4);         system.out.println("result value : " + die.getfacevalue());         die.setfacevalue(10);         system.out.println("input value : " + 10);         system.out.println("result value : " + die.getfacevalue());     } } 

output:

input value : 4 result value : 4 input value : 10 result value : 4 

note:

  • if wish have diemod class, , separate driver class, i.e. testdieclass, have put them in separate .java files.
  • another option declare diemod class inner class of testdieclass, not recommended.

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -