Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (576)
games submitted by our members
Games in WIP (498)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Package question  (Read 1540 times)
0 Members and 1 Guest are viewing this topic.
Offline Scooby

Senior Newbie





« Posted 2010-04-18 17:07:53 »

Hi
This isn't specific to games but hopefully someone might be able to point me in the correct direction.
I have 1 main class which imports a package containing 2 smaller classes (TestClassOne and TestClassTwo).
TestClassOne has to create an instance of TestClassTwo, but when compiling TestClassOne I keep getting the error "Unable to find symbol" in reference to TestClassTwo.

Both test classes are in the dir ..org/testpackage/ which I've added to my classpath, I've also done something reasonably similar to this as part of a tutorial from a book which worked.

I've tried putting a little test program together with the bare minimum in it incase some of the other code was tripping me up but I'm still getting the same thing.  Does anyone have any ideas please?  Undecided

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
package org.testpackage;
import java.io.*;

public class TestClassOne{

   public TestClassOne(){
      super();
      doStuff();
   }

   public static void doStuff(){
      TestClassTwo tempTestClass = new TestClassTwo();
   }

}


1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
package org.testpackage;

public class TestClassTwo{

   public TestClassTwo(){
      super();
      doStuff();
   }

   public void doStuff(){
      System.out.println("I work!");
   }

}
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 12


Game Engineer


« Reply #1 - Posted 2010-04-18 20:14:00 »

Well there's nothing wrong with this - if they're in the same package as you've described then you shouldn't have to do an import.

There must be more to this than what you've put in the forum. Look for simple spelling errors, missing semicolons or things like that. But probably there's some corrupted folder in your project or something. What IDE are you using?

See my work:
OTC Software
Offline irreversible_kev

Junior Member





« Reply #2 - Posted 2010-04-18 20:21:23 »

I copied your TestClassOne.java and TestClassTwo.java and added my own Main.java and tried it from the command line:

org\mainpackage\Main.java:
1  
2  
3  
4  
5  
6  
7  
8  
9  
package org.mainpackage;

import org.testpackage.TestClassOne;

public final class Main {
   public static void main(String[] args) {
      System.out.println("Here is a TestClassOne I just created: " + new TestClassOne());      
   }
}


1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
C:\Users\irr\Desktop\jgo>dir *.java /S /B
C:\Users\irr\Desktop\jgo\org\mainpackage\Main.java
C:\Users\irr\Desktop\jgo\org\testpackage\TestClassOne.java
C:\Users\irr\Desktop\jgo\org\testpackage\TestClassTwo.java

C:\Users\irr\Desktop\jgo>javac org\mainpackage\Main.java

C:\Users\irr\Desktop\jgo>java -cp . org.mainpackage.Main
I work!
Here is a TestClassOne I just created: org.testpackage.TestClassOne@addbf1
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Scooby

Senior Newbie





« Reply #3 - Posted 2010-04-19 09:22:03 »

There must be more to this than what you've put in the forum. Look for simple spelling errors, missing semicolons or things like that. But probably there's some corrupted folder in your project or something. What IDE are you using?

Hi.
I'm just using notepad and the command line to develop this.

Thanks.
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 12


Game Engineer


« Reply #4 - Posted 2010-04-19 16:05:02 »

Hi.
I'm just using notepad and the command line to develop this.

Thanks.
Well then are sure that both of these classes are being compiled and are in the classpath?

See my work:
OTC Software
Offline Scooby

Senior Newbie





« Reply #5 - Posted 2010-04-19 19:53:05 »

Well then are sure that both of these classes are being compiled and are in the classpath?

Hi
Thanks for having another look at this.

TestClassTwo compiles without error.
TestClassOne gives the error:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
Cannot find symbol
Symbol: TestClassTwo
Location: org.testpackage.TestClassOne
 TestClassTwo tempTestClass = new TestClassTwo();
 ^

Cannot find symbol
Symbol: TestClassTwo
Location: org.testpackage.TestClassOne
 TestClassTwo tempTestClass = new TestClassTwo();
                                                           ^


Edit: the ^ should be under the T's in TestClassTwo

Classpath variable is set to : c:\javacc-5.0\bin\;f:\users\jp\appdata\java\org.testpackage\;
Added through the windows control panel

My files are in the directory : f:\users\jp\appdata\java\org.testpackage\
Offline DzzD
« Reply #6 - Posted 2010-04-19 20:11:39 »

strange do you compil both at the same time like this : javac file1.java file2.java

Offline Scooby

Senior Newbie





« Reply #7 - Posted 2010-04-19 20:37:00 »

strange do you compil both at the same time like this : javac file1.java file2.java

Bingo!  Grin
I was compiling them separately as I wasn't aware they would have to be done at the same time (I assume they have to be done at the same time as it works now).
Thanks very much for all who posted.
Feel a bit of a berk for tearing my hair out over this.
Offline cylab

JGO Knight


Medals: 34



« Reply #8 - Posted 2010-04-20 11:03:12 »

Classpath variable is set to : c:\javacc-5.0\bin\;f:\users\jp\appdata\java\org.testpackage\;
Added through the windows control panel

My files are in the directory : f:\users\jp\appdata\java\org.testpackage\

Your classpath and folders are "wrong", too.  Each package segment has to have a separate folder, so its  f:\users\jp\appdata\java\org\testpackage\ and the classpath always has to point to the root-package, so it should be f:\users\jp\appdata\java\ without any package name in there.

Mathias - I Know What [you] Did Last Summer!
Offline Mr. Gol

Senior Member


Medals: 1



« Reply #9 - Posted 2010-04-20 19:06:24 »

Feel a bit of a berk for tearing my hair out over this.

Actually you deserve a compliment for starting out on the lowest level, without and IDE and compiling everything yourself. That said, I do hope that you eventually switch to Eclipse or Netbeans, because you really don't want to use Notepad for programming Smiley
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Scooby

Senior Newbie





« Reply #10 - Posted 2010-04-23 21:11:40 »

Thanks for the tips peeps.  I'll alter my classpath just now.
I find notepad a bit simpler to use, that said once I get my feet wet I'll prolly have to spend time getting comfortable with eclipse.  Especially once I try to make something of any real size.
Offline cylab

JGO Knight


Medals: 34



« Reply #11 - Posted 2010-04-23 21:40:59 »

I find notepad a bit simpler to use

You may like notepad++ instead, so you have syntax coloration.

And if you want to play a bit, you could try to automate the stuff you've learned about the java tools like this:
http://javaforyou.wordpress.com/2008/07/25/using-notepad-to-compile-and-run-java-programs/

Mathias - I Know What [you] Did Last Summer!
Offline markmistry

Junior Member





« Reply #12 - Posted 2010-04-24 09:21:02 »

Notepad++ Rules...!
I use it when i program.
Offline Scooby

Senior Newbie





« Reply #13 - Posted 2010-04-27 19:19:31 »

Ah cool. Ty.
I use notepad at work, hadn't thought of using it to compile java code in though Smiley
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (15 views)
2014-04-15 18:08:23

BurntPizza (13 views)
2014-04-15 03:46:01

UprightPath (27 views)
2014-04-14 17:39:50

UprightPath (12 views)
2014-04-14 17:35:47

Porlus (29 views)
2014-04-14 15:48:38

tom_mai78101 (51 views)
2014-04-10 04:04:31

BurntPizza (110 views)
2014-04-08 23:06:04

tom_mai78101 (211 views)
2014-04-05 13:34:39

trollwarrior1 (179 views)
2014-04-04 12:06:45

CJLetsGame (185 views)
2014-04-01 02:16:10
List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:05:20
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!