[java] Why am I getting these errors when I compile?

Started by
3 comments, last by fadilthrejk 21 years ago

  
D:\DuelMonsters\src\duelmonsters>javac DuelMonsters.java
DuelMonsters.java:18: cannot resolve symbol
symbol  : class Deck
location: package duelmonsters
  duelmonsters.Deck deck1 = new duelmonsters.Deck(40);
              ^
DuelMonsters.java:18: cannot resolve symbol
symbol  : class Deck
location: package duelmonsters
  duelmonsters.Deck deck1 = new duelmonsters.Deck(40);
                                            ^  
Here is my code for my Deck class, somewhat revamped:
  
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 int dS;

  public Deck()
  {
    int[] arrDeck;
  }//end Deck()


  public int[] setDeck(int dS, int[] arrDeck)
  {
    for (int i = 0; i < dS; i++)
    {
      arrDeck[i] = generator.nextInt(100);
    }//end for

    return arrDeck;
  }//end Deck()



}//end Deck  
And here is the DuelMonsters class:
  
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
{

  duelmonsters.Deck deck1 = new duelmonsters.Deck();


  String string = "";
  Label test = new Label(deck1.toString());

  public void init()
  {
    add(test);
  }
}
  
It''s almost as if the compiler has trouble recognizing the connection between the two files. JBuilder doesn''t say anything though.
Advertisement
I changed my constructor, because I decided to have the deck be always 40 cards, for gameplay balance. So here is the new Deck class:

    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 int dS;  int arrDeck[];  public Deck()  {    for (int i = 0; i <40; i++)    {      arrDeck = generator.nextInt(100);<br>    }<br>  }//end Deck()<br><br>}//end Deck<br>  <br><br>and thus, the changed DuelMonsters class:<br>      <br>package duelmonsters;<br>import java.applet.*;<br>import java.awt.*;<br>import java.awt.event.*;<br>import duelmonsters.*;<br>/**<br> * &lt;p&gt;Title: &lt;/p&gt;<br> * &lt;p&gt;Description: &lt;/p&gt;<br> * &lt;p&gt;Copyright: Copyright © 2003&lt;/p&gt;<br> * &lt;p&gt;Company: &lt;/p&gt;<br> * @author not attributable<br> * @version 1.0<br> */</font><br><br><font color="blue">public</font> <font color="blue">class</font> DuelMonsters extends Applet<br>{<br>  Deck deck1 = <font color="blue">new</font> duelmonsters.Deck();<br><br>  String string = "";<br><br><br>  <font color="blue">public</font> <font color="blue">void</font> init()<br>  {<br><br>  }<font color="gray">//end init()<br></font><br>}<font color="gray">//end DuelMonsters    </font></pre></DIV><!–ENDSCRIPT–><br><br><br>here are the errors:<br>    <!–STARTSCRIPT–><BR><DIV CLASS=source><pre>  <br>D:\DuelMonsters\src\duelmonsters&gt;javac DuelMonsters.java<br>DuelMonsters.java:17: cannot resolve symbol<br>symbol  : <font color="blue">class</font> Deck<br>location: <font color="blue">class</font> duelmonsters.DuelMonsters<br>  Deck deck1 = <font color="blue">new</font> duelmonsters.Deck();<br>  ^<br>DuelMonsters.java:17: cannot resolve symbol<br>symbol  : <font color="blue">class</font> Deck<br>location: package duelmonsters<br>  Deck deck1 = <font color="blue">new</font> duelmonsters.Deck();<br>                               ^  </pre></DIV><!–ENDSCRIPT–>    <br><br>Spread the rusty bleen ointment &#111;n the blue-red fromato with your thimble carver<br><br><SPAN CLASS=editedby>[edited by - fadilthrejk &#111;n March 31, 2003 3:49:19 PM]</SPAN>    
Try going down one directory and running javac duelmonsters/Deck.java from /src. Java is very strict with paths. You might say it''s pathological. Java expects all the files in a package to be in a directory of the same name as the package. So it opens up Deck.java and expects to find class Deck but instead it finds duelmonsters.Deck which it just can''t comprehend. Causes quite a lot of headaches.
If you are going to use packages, you have to set the CLASSPATH environment variable or use the -cp switch of the javac command.

You need:

set CLASSPATH=D:\DuelMonsters\src

then it should work the way you are doing it now.

As you may know, the package names are also a directory structure. So the CLASSPATH has to point to the directory that contains the root of all the packages in your program.


First make it work,
then make it fast.

--Brian Kernighan

"I’m happy to share what I can, because I’m in it for the love of programming. The Ferraris are just gravy, honest!" --John Carmack: Forward to Graphics Programming Black Book
"None of us learn in a vacuum; we all stand on the shoulders of giants such as Wirth and Knuth and thousands of others. Lend your shoulders to building the future!" - Michael Abrash[JavaGaming.org][The Java Tutorial][Slick][LWJGL][LWJGL Tutorials for NeHe][LWJGL Wiki][jMonkey Engine]
never mind, forget this message. It worked.
Thanks guys.

Spread the rusty bleen ointment on the blue-red fromato with your thimble carver

[edited by - fadilthrejk on March 31, 2003 11:18:18 PM]

This topic is closed to new replies.

Advertisement