Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

fadilthrejk

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

This topic is 5651 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts


  
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.

Share this post


Link to post
Share on other sites
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[i] = generator.nextInt(100);
}
}//end Deck()

}//end Deck


and thus, the changed 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
{
Deck deck1 = new duelmonsters.Deck();

String string = "";


public void init()
{

}//end init()

}//end DuelMonsters



here are the errors:

  
D:\DuelMonsters\src\duelmonsters>javac DuelMonsters.java
DuelMonsters.java:17: cannot resolve symbol
symbol : class Deck
location: class duelmonsters.DuelMonsters
Deck deck1 = new duelmonsters.Deck();
^
DuelMonsters.java:17: cannot resolve symbol
symbol : class Deck
location: package duelmonsters
Deck deck1 = new duelmonsters.Deck();
^


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

[edited by - fadilthrejk on March 31, 2003 3:49:19 PM]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!