• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 506
  • Last Modified:

Packages in JAVA

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
deko007
Asked:
deko007
  • 9
  • 7
  • 7
1 Solution
 
for_yanCommented:
Are you using some IDE - say Eclipse ?
And you want to create a new class in your project ?
0
 
deko007Author Commented:
No just working on vista,i added the path and stiil dont recognized
0
 
CEHJCommented:
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
deko007Author Commented:
That's what i did,Still not working.
0
 
CEHJCommented:
Please post full java code
0
 
for_yanCommented:
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
 
deko007Author Commented:
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
 
CEHJCommented:
Please copy and paste the error message
0
 
for_yanCommented:
Do you have all of them in a jar, or you expanded them and have them as class files?
0
 
for_yanCommented:
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
 
for_yanCommented:
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
 
for_yanCommented:
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
 
deko007Author Commented:

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
 
CEHJCommented:
Try
javac -classpath C:\ NatavClient.java

Open in new window

0
 
deko007Author Commented:
OK it compile well but is that good solution when i need to run the program?
0
 
CEHJCommented:
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
 
for_yanCommented:
You move to root and compile
with such command:

javac  nproject/natav/client/NatavClient.java

0
 
for_yanCommented:
And place NatavClient.java into c:\nproject\natav\client
0
 
CEHJCommented:
To run client:
java -classpath C:\ nproject.natav.client.NatavClient

Open in new window

0
 
deko007Author Commented:
Thanks both! answers from CHEJ  and  yan was good but i think CHEJ was first
Please post who the win for 50 points.
0
 
CEHJCommented:
>>Please post who the win for 50 points.

Not sure what you mean there..?
0
 
for_yanCommented:
well I think CEHJ should win this one
0
 
deko007Author Commented:
Thanks both
0

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

  • 9
  • 7
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now