Solved

Packages in JAVA

Posted on 2011-03-20
23
499 Views
Last Modified: 2013-12-29
Hello everyone!

I am trying to add files into packages  in one of my project,I added a classpath variables path and so on and still can't see the packages
the error syntext like this:can't find  symbol package nproject.natav.common.*;
Please help
0
Comment
Question by:deko007
  • 9
  • 7
  • 7
23 Comments
 
LVL 47

Expert Comment

by:for_yan
ID: 35175478
Are you using some IDE - say Eclipse ?
And you want to create a new class in your project ?
0
 

Author Comment

by:deko007
ID: 35176285
No just working on vista,i added the path and stiil dont recognized
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 35176293
Your source, if you want to import a package, should begin something like the first statement below. If you want to define your source as being IN a package, there's no wildcard and it should be something like the second:
import nproject.natav.common.*;

OR

package nproject.natav.common;

Open in new window

0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

Author Comment

by:deko007
ID: 35176348
That's what i did,Still not working.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 35176355
Please post full java code
0
 
LVL 47

Expert Comment

by:for_yan
ID: 35176412
if on top of your java code it is written

package nproject.natav.common;

public class MyClass{
...

And you are issuing your comman java... in the folder
c:\myfolder

then your class file MyClass.class
should be sitting in the folder
c:\myfolder\nproject\natav\common

and you should run it with such command:

java nproject.natav.common.MyClass


0
 

Author Comment

by:deko007
ID: 35176455
A lot of  code.....to post.

One file called "NatavServerInterface" is in a folder named "common" in the first line of it
"package nproject.natav.common;"

One file called "NatavClient" is in a folder named "client" int the first  line of it
"package nproject.natav.client;" and it has an import line "import nproject.natav.common.*;"

Both ffolder "common" and "client" under same folder "natav"

I think the code is pretty good,maybe the problem is with the OS (vista)...
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 35176462
Please copy and paste the error message
0
 
LVL 47

Expert Comment

by:for_yan
ID: 35176470
Do you have all of them in a jar, or you expanded them and have them as class files?
0
 
LVL 47

Expert Comment

by:for_yan
ID: 35176484
if you have them as the .class files then you need
to make sure that you have all those folders present and file should be sitting in them.
So if you work in the folder c:\myfolder
you should  have thhis whole path c:\myfolder\nproject\natav\common and then NatavServerInterface.class should be sitting
in that folder
and analogously with the client folder path
0
 
LVL 47

Expert Comment

by:for_yan
ID: 35176504
if you have them in the jar - then they should be itting in this folders with ithe jar starting
with \nproject\... and so on
and when you print
echo %CLASSPATH%
you should see
something like that:
CLASSPATH=C:\location_of_the_jar\jar_fileName.jar

if you are not sure about the jar copy this jar to the same file with .zip
extension - in some other place and open it with winzip - you'll see the paths to all your classe and you could check it

Java is everywhere the same - Vista should not matter
0
 
LVL 47

Expert Comment

by:for_yan
ID: 35176540
if you are using some class coming from the jar inside your code
you should have import at the top of your code.

Say if you are referring to  NatavServerInterface from your code,
the on top of your code you should write:

import nproject.natav.common.NatavServerInterface;

and somehere in your code it will be say,

public MyClass implements NatavServerInterface  ...


or you should have at the top:

import nproject.natav.client.NatavClient;

then soemwhere in the code, say

NatavClient myClient = new NatavClient();




0
 

Author Comment

by:deko007
ID: 35176846

There is the errors:

C:\nproject\natav\client>javac NatavClient.java
NatavClient.java:14: package nproject.natav.common does not exist
import nproject.natav.common.*;
^
NatavClient.java:16: cannot find symbol
symbol: class NatavClientInterface
public class NatavClient extends JFrame implements NatavClientInterface,java.io.Serializable
                                                   ^
NatavClient.java:18: cannot find symbol
symbol  : class NatavServerInterface
location: class nproject.natav.client.NatavClient
  NatavServerInterface server;
  ^
NatavClient.java:40: cannot find symbol
symbol  : method exportObject(nproject.natav.client.NatavClient)
location: class java.rmi.server.UnicastRemoteObject
           UnicastRemoteObject.exportObject(this);
                              ^
NatavClient.java:43: cannot find symbol
symbol  : class NatavServerInterface
location: class nproject.natav.client.NatavClient
           server=(NatavServerInterface) Naming.lookup(name);
                   ^
Note: NatavClient.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
5 errors
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 35176860
Try
javac -classpath C:\ NatavClient.java

Open in new window

0
 

Author Comment

by:deko007
ID: 35176873
OK it compile well but is that good solution when i need to run the program?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 35176882
You need to set the classpath to run the program too, yes. Or you need to move into the root of the package tree (C:\)
0
 
LVL 47

Expert Comment

by:for_yan
ID: 35176891
You move to root and compile
with such command:

javac  nproject/natav/client/NatavClient.java

0
 
LVL 47

Expert Comment

by:for_yan
ID: 35176894
And place NatavClient.java into c:\nproject\natav\client
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 50 total points
ID: 35176909
To run client:
java -classpath C:\ nproject.natav.client.NatavClient

Open in new window

0
 

Author Comment

by:deko007
ID: 35176960
Thanks both! answers from CHEJ  and  yan was good but i think CHEJ was first
Please post who the win for 50 points.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 35176969
>>Please post who the win for 50 points.

Not sure what you mean there..?
0
 
LVL 47

Expert Comment

by:for_yan
ID: 35176971
well I think CEHJ should win this one
0
 

Author Closing Comment

by:deko007
ID: 35176989
Thanks both
0

Featured Post

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question