Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (535)
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  
  And then the package line goes...?  (Read 1169 times)
0 Members and 1 Guest are viewing this topic.
Offline Lemon

Senior Newbie




Java games rock!


« Posted 2005-01-27 02:21:34 »

Ultimate Newless Clubie question here:

Trying to make a package, can't do it, and yes i have tried searching  Huh

I have two basic classes with just a constructor and the following line at the top:

package RandomPackage;


They are contained within a folder called RandomPackage.

I have my test file in the folder that contains the RandomPackage folder. I have imported the package using:

import RandomPackage.*;

Up to this point everything works, the Tester can create instances of the two basic classes within the package RandomPackage.
The problem is that the two basic classes cannot refer to each other. I cannot create an instance of basic class A within basic class B... This pretty much ruins the whole point of packaging so I must be doing something wrong.
How do I fix this?

Thank you in advance

Simon
Offline jbanes

JGO Coder


Projects: 1


"Java Games? Incredible! Mr. Incredible, that is!"


« Reply #1 - Posted 2005-01-27 03:16:27 »


Quote
The problem is that the two basic classes cannot refer to each other. I cannot create an instance of basic class A within basic class B... This pretty much ruins the whole point of packaging so I must be doing something wrong.
How do I fix this?


Post one of the code attempts so we can see what you're doing. Once we have a basis to work from, we can give you some advice. :-)

Java Game Console Project
Last Journal Entry: 12/17/04
Offline Lemon

Senior Newbie




Java games rock!


« Reply #2 - Posted 2005-01-27 07:33:28 »

Sorry about the lack of code.

The class that runs it all:

import RandomPackage.*;

public class TESTER1 {

     public static void main(String[] args){

           TestClass2 t = new TestClass2();  [Edit = I forgot the 2 in the TestClass2  Shocked]

     }

}




The two test classes, In two seperate java files:

package RandomPackage;

public class TestClass{

     public TestClass(){
           System.out.println("Created Test Class");
     }

}

package RandomPackage;

public class TestClass2{

     TestClass insideClass;

     public TestClass2(){
           insideClass = new TestClass();
     }

}

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline CaptainJester

JGO Knight


Medals: 12
Projects: 2
Exp: 14 years


Make it work; make it better.


« Reply #3 - Posted 2005-01-27 10:38:46 »

Are you getting errors?  When you compile or when you run?  I suspect this might be a simple classpath issue.  Here is a sample error you might get when it is a classpath issue:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
C:\Test\Java\work\RandomPackage\TestClass2.java:5: cannot resolve symbol
symbol  : class TestClass
location: class RandomPackage.TestClass2
 TestClass insideClass;
 ^
C:\Test\Java\work\RandomPackage\TestClass2.java:8: cannot resolve symbol
symbol  : class TestClass
location: class RandomPackage.TestClass2
  insideClass = new TestClass();
                    ^
2 errors


If this is your problem, then you simply have to set the classpath to the directory where RandomPackage resides.  You can do this with an environment variable or the '-classpath' command line switch.  Then the javac command must either be executed in the directory where RandomPackage is or you can use the '-sourcepath' switch to point to it. So if your directory structure is:

c:\java\work\RandomPackage

you need to do this:

c:\java\work>javac -classpath . TESTER1.java RandomPackage/*.java

If this is not your problem, you need to provide more information.  What you are trying to do(compile, execute) and what your error messages are.

Offline Tzan

Junior Member





« Reply #4 - Posted 2005-01-27 16:26:10 »

You have no line where you are creating a:       new TestClass2()

In your main change :

new TestClass()

to

TestClass2 t2 = new TestClass2();

Then TestClass2 will make a new TestClass and print the result
You should put a print() in TestClass2 also so you know they were both touched.
Offline Lemon

Senior Newbie




Java games rock!


« Reply #5 - Posted 2005-01-28 22:42:44 »

Quote
Are you getting errors?  When you compile or when you run?  I suspect this might be a simple classpath issue.  Here is a sample error you might get when it is a classpath issue:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
C:\Test\Java\work\RandomPackage\TestClass2.java:5: cannot resolve symbol
symbol  : class TestClass
location: class RandomPackage.TestClass2
 TestClass insideClass;
 ^
C:\Test\Java\work\RandomPackage\TestClass2.java:8: cannot resolve symbol
symbol  : class TestClass
location: class RandomPackage.TestClass2
  insideClass = new TestClass();
                    ^
2 errors


If this is your problem, then you simply have to set the classpath to the directory where RandomPackage resides.  You can do this with an environment variable or the '-classpath' command line switch.  Then the javac command must either be executed in the directory where RandomPackage is or you can use the '-sourcepath' switch to point to it. So if your directory structure is:

c:\java\work\RandomPackage

you need to do this:

c:\java\work>javac -classpath . TESTER1.java RandomPackage/*.java

If this is not your problem, you need to provide more information.  What you are trying to do(compile, execute) and what your error messages are.



Firstly, thanx!
This is exactly my problem.Grin

Unfortunately I still cant get it working Embarrassed

How do I compile the classTestClass2.

I recieve the error:

D:\My Programs\Tests\RandomPackage\TestClass2.java:5: cannot resolve symbol
symbol  : class TestClass
location: class RandomPackage.TestClass2
     TestClass insideClass;
       ^
D:\My Programs\Tests\RandomPackage\TestClass2.java:8: cannot resolve symbol
symbol  : class TestClass
location: class RandomPackage.TestClass2
           insideClass = new TestClass();
                                 ^
2 errors

Tool completed with exit code 1

I tried c:\java\work\RandomPackage>javac -classPath . TestClass.java RandomPackage/*.java

but that does not work...

One more question , I'm currently using textpad to write my java code, which means your solution requires I either:
compile through command prompt (which is annoying)
create a new user defined tool that compiles and includes the extra arguments "c:\java\work>javac -classpath . TESTER1.java RandomPackage/*.java"  
Is there another way that I have missed?
This whole package thing seems rather complicated for something that should be so simple  :-/

Thanx again

Simon
Offline CaptainJester

JGO Knight


Medals: 12
Projects: 2
Exp: 14 years


Make it work; make it better.


« Reply #6 - Posted 2005-02-01 17:45:45 »

Don't forget, everything is case sensitive.  You need to use '-classpath' not '-classPath'

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.

Riven (7 views)
2014-07-29 12:53:52

Dwinin (7 views)
2014-07-29 10:59:34

E.R. Fleming (23 views)
2014-07-29 03:07:13

E.R. Fleming (9 views)
2014-07-29 03:06:25

pw (39 views)
2014-07-24 01:59:36

Riven (39 views)
2014-07-23 21:16:32

Riven (26 views)
2014-07-23 21:07:15

Riven (28 views)
2014-07-23 20:56:16

ctomni231 (59 views)
2014-07-18 06:55:21

Zero Volt (51 views)
2014-07-17 23:47:54
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!