Solved

Packages in JAVA

Posted on 2011-03-20
23
498 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MySQL  on Tomcat 8 46
arguments to jar 5 26
maven module vs maven project 3 23
Java: The Public Class Main 4 17
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
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…
This video teaches viewers about errors in exception handling.

803 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