[java] More HTML host woes

Started by
3 comments, last by fadilthrejk 21 years ago
I did all that, and it gives me this:
  
java.lang.NoClassDefFoundError: DuelMonsters (wrong name: duelmonsters/DuelMonst
ers)
        at java.lang.ClassLoader.defineClass0(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:502)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:12
3)
        at sun.applet.AppletClassLoader.findClass(AppletClassLoader.java:148)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:299)
        at sun.applet.AppletClassLoader.loadClass(AppletClassLoader.java:114)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:255)
        at sun.applet.AppletClassLoader.loadCode(AppletClassLoader.java:501)
        at sun.applet.AppletPanel.createApplet(AppletPanel.java:567)
        at sun.applet.AppletPanel.runLoader(AppletPanel.java:496)
        at sun.applet.AppletPanel.run(AppletPanel.java:293)
        at java.lang.Thread.run(Thread.java:536)
  
I have the class files in this directory: D:\DuelMonsters\src\duelmonsters And I have the html as this: <applet code = "DuelMonsters.class" width = 1024 height = 768> </html> The HTML file is also in the same directory. I don''t understand what is wrong. The host is in the same directory as the class files, so there should be no problem, right? GRR!!!!! This is frustrating! LOL. Spread the rusty bleen ointment on the blue-red fromato with your thimble carver
Advertisement
what program are you using to build yer java programs???
because i personally use jbuilder and when you create an applet it usually generates the base html code for you.

Also the other errors i cant really say i dont have the code but it looks like its running into several problems on multiple lines of yer code.. designated by the :### (:512 etc after each error deal)

[edited by - Psionic-X on April 2, 2003 12:29:43 PM]
------------------------------Exsiting in every essence of time I will find you! You will answer my Question!-Psionic-X- Existing from a greater plane
I fixed the HTML host stuff, but now I get these errors:

  java.lang.NullPointerException	at duelmonsters.Deck.<init>(Deck.java:22)	at duelmonsters.DuelMonsters.<init>(DuelMonsters.java:17)	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)	at java.lang.reflect.Constructor.newInstance(Constructor.java:274)	at java.lang.Class.newInstance0(Class.java:306)	at java.lang.Class.newInstance(Class.java:259)	at sun.applet.AppletPanel.createApplet(AppletPanel.java:567)	at sun.plugin.AppletViewer.createApplet(AppletViewer.java:1778)	at sun.applet.AppletPanel.runLoader(AppletPanel.java:496)	at sun.applet.AppletPanel.run(AppletPanel.java:293)	at java.lang.Thread.run(Thread.java:536)  

for this code:

  package duelmonsters;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2003</p> * <p>Company: </p> * @author not attributable * @version 1.0 */public class Deck{  java.util.Random generator = new java.util.Random();  public static int dS;  int arrDeck[];  public Deck(int DeckSize)  {    for (int i = 0; i < DeckSize; i++)    {      arrDeck[i] = generator.nextInt(100);    }//end for    int dS = DeckSize;  }//end Deck()public static String stringifyDeck(Deck arrDeck)  {    return arrDeck.toString();  }}//end Deck  


and

  package duelmonsters;import java.applet.*;import java.awt.*;import java.awt.event.*;import duelmonsters.*;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2003</p> * <p>Company: </p> * @author not attributable * @version 1.0 */public class DuelMonsters extends Applet{  Deck deck1 = new duelmonsters.Deck(40);  String string = "";  Label test = new Label("test");  public void init()  {    add(test);  }//end init()}//end DuelMonsters  

I think my classes are screwed up somehow. I should probably put this project on hold for a while, and do some smaller stuff first. What do you all think?

Spread the rusty bleen ointment on the blue-red fromato with your thimble carver
I think you should try working on a more basic lvl.. judging from yer other post.. youll want to be able to grasp the concepts behind the language to be able to implement them properly. Me personally i have not tried to program any game type programs yet.. because honestly they dont teach you everything they teach you the basis to be able to use everything (2nd semester java in college) so if yer interested you should keep trying to learn.
------------------------------Exsiting in every essence of time I will find you! You will answer my Question!-Psionic-X- Existing from a greater plane
I find that when I have the concept for a program I want to write, and I am excited about it, then I am motivated to learn the concepts I need to implement it. If this project motivates you to learn, stick with it.

Having said that, the error log you posted tells you exactly where the error occured, so you should start looking there. Specifically:

  java.lang.NullPointerException    at duelmonsters.Deck.<init>(Deck.java:22)   


If you look at Deck.java line 22 you will see:

  arrDeck[i] = generator.nextInt(100);   


The problem with that line is you have not allocated any memory for the array. You declared the array like this:

  int arrDeck[];   

,but before you use it you need to use "new" to allocate some memory, like this:

  arrDeck = new int[DeckSize];   


If you put that line just inside your public Deck(int DeckSize) method, your code compiles and runs.

Shawn


[edited by - ShawnO on April 2, 2003 2:12:17 PM]
When using the Windows calculator program, always remember to clear any values from memory before exiting to prevent burn-in.

This topic is closed to new replies.

Advertisement