Solved

Packages in JAVA

Posted on 2011-03-20
23
496 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
Comment Utility
Are you using some IDE - say Eclipse ?
And you want to create a new class in your project ?
0
 

Author Comment

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

Expert Comment

by:CEHJ
Comment Utility
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
 

Author Comment

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

Expert Comment

by:CEHJ
Comment Utility
Please post full java code
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
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
Comment Utility
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
Comment Utility
Please copy and paste the error message
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
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
Comment Utility
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
Comment Utility
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 47

Expert Comment

by:for_yan
Comment Utility
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
Comment Utility

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

Open in new window

0
 

Author Comment

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

Expert Comment

by:CEHJ
Comment Utility
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
Comment Utility
You move to root and compile
with such command:

javac  nproject/natav/client/NatavClient.java

0
 
LVL 47

Expert Comment

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

Accepted Solution

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

Open in new window

0
 

Author Comment

by:deko007
Comment Utility
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
Comment Utility
>>Please post who the win for 50 points.

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

Expert Comment

by:for_yan
Comment Utility
well I think CEHJ should win this one
0
 

Author Closing Comment

by:deko007
Comment Utility
Thanks both
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
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…

772 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now