Solved

Packages in JAVA

Posted on 2011-03-20
23
501 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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 …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Suggested Courses

738 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