0

I have a Game class that extends the JApplet class and I want to be able to compile it but I also need to use my Character class. The issue is that I have getting errors while compiling my Character class since I have no main method. The errors on the compilation of the Character are this:

Exception in thread "main" java.lang.NoClassDefFoundError: Character (wrong name: kingdomofcarthania/Character)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:637)
at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
[Finished in 0.9s with exit code 1]

The errors when compiling the Game class are:

Game.java:3: cannot find symbol
symbol  : class Character
location: package kingdomofcarthania
import kingdomofcarthania.Character;
                     ^
 Game.java:10: cannot find symbol
 symbol  : constructor Character()
 location: class java.lang.Character
    Character c = new Character();
                      ^
 Game.java:11: cannot find symbol
 symbol  : method resetCharacter()
 location: class java.lang.Character
    c.resetCharacter();
     ^
3 errors
[Finished in 0.7s with exit code 1]

Here are some snippets of my Applet that might be helpful

Game.java

package kingdomofcarthania;

import kingdomofcarthania.Character;
import javax.swing.JApplet;
import java.awt.*;

public class Game extends JApplet{

public static void main(String[] args) {
    Character c = new Character();
    c.resetCharacter();
    }
}

Character.java

package kingdomofcarthania;

import kingdomofcarthania.*;
import java.util.ArrayList;

public class Character{
 private int xCoord;
 private int yCoord;
 private int currentZone;
 //private Map world;
 //private ArrayList<Zone> map;
 //private Inventory inventory;
 private int gold;

 //private ArrayList<Follower> followers;

 private int might;
 private int wisdom;
 private int dexterity;
 private int toughness;
 private int vigor;
 private int maxVigor;

 private int level;
 private int reputation;
 private int greatness;
 private int greatnessNeeded;

 private String title;


 public Character(){
 }

//some methods
}

I feel like I am making a silly mistake, any help would be greatly appreciated.

EDIT:

These are the new errors I'm getting after changing some stuff:

Game.java:9: cannot find symbol
symbol  : class Champion
location: package kingdomofcarthania
        kingdomofcarthania.Champion c = new kingdomofcarthania.Champion();
                      ^
 Game.java:9: cannot find symbol
 symbol  : class Champion
 location: package kingdomofcarthania
      kingdomofcarthania.Champion c = new kingdomofcarthania.Champion();
                                                          ^
 2 errors
CJ Jacobs
  • 299
  • 1
  • 16

1 Answers1

0

Your Character class is conflicting with java.lang.Character

Use explictly kingdomofcarthania.Character instead of just Character.

classes within java.lang package don't need import, so are subject to conflicts.

AND

You don't need to import class of the same package.

try removing

import kingdomofcarthania.Character;

and

import kingdomofcarthania.*;

Best Way would be to not create a Character class but a MyCharacter or KingDomCharacter to avoid naming conflict.

finaly see a related problem discussion here : http://www.coderanch.com/t/569181/java/java/class-conflicts

philippe lhardy
  • 3,096
  • 29
  • 36