This week's book giveaway is in the Programmer Certification forum.
We're giving away four copies of OCP Oracle Certified Professional Java SE 21 Developer Study Guide: Exam 1Z0-830 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread for details.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Error in import statement.

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



I compiled this code successfully but after referring this code to other package getting error that package does not exist.Please help me what to do??
here is code in which import statement does not supporting







I am working on Java SE 7.
Thank You in advance
 
Ranch Hand
Posts: 226
Eclipse IDE Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Afreen Patel wrote:package certificate;
public class Exam
{
public static int mark;
static public void print()
{
System.out.println("Print" + 100);
}
}


I compiled this code successfully but after referring this code to other package getting error that package does not exist.Please help me what to do??
here is code in which import statement does not supporting



package university;
import static certificate.Exam.mark;

public class AnnualExam
{
AnnualExam()
{
mark=100;
System.out.println(100);
}
}



I am working on Java SE 7.
Thank You in advance



Are these 2 packages present in the same project or in two different projects?
 
Afreen Patel
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
present in same project.
 
Nick Widelec
Ranch Hand
Posts: 226
Eclipse IDE Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Afreen Patel wrote:present in same project.


Well, it should work..

Perhaps there has been some conflicts by adding a new package in a project, sometimes using IDEs it happens (with Eclipse for example).
So I would suggest to rebuild the project or copy the classes in another brand new project and paste them there. (obviosuly rebuilding the package structure)

It should be working..
 
Afreen Patel
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am working with command prompt. I made two different packages still not working. Giving error at import statement. please help!!
 
Sheriff
Posts: 7346
1404
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you show us the command you use to compile AnnualExam ?
 
Bartender
Posts: 2442
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Suppose certification and university packages are in the same directory c:\myProject
Under myProject, do you use this:
java -cp certification university.AnnualExam
?
 
Devaka Cooray
Sheriff
Posts: 7346
1404
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Himai Minh wrote:...java -cp ...


The OP is having a problem with compiling AnnualExam
 
Himai Minh
Bartender
Posts: 2442
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Based on what the OP wrote :


I compiled this code successfully but after referring this code to other package getting error that package does not exist.Please help me what to do??
here is code in which import statement does not supporting



I am under an impression that the code can compile, but cannot find the package during execution. Correct me if I am wrong.

To compile it, use this under c:\myProject\:
javac -cp certification university\AnnualExam.java

 
Afreen Patel
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
package certificate and university exist in folder myproject.


Here is the compilation steps:


Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.

C:\Users\Aafreen>cd\

C:\>cd myproject\certificate\

C:\myproject\certificate>javac Exam.java

C:\myproject\certificate>cd\

C:\>cd myproject\university\

C:\myproject\university>javac AnnualExam.java
AnnualExam.java:2: error: package certificate does not exist
import static certificate.Exam.mark;
^
AnnualExam.java:2: error: static import only from classes and interfaces
import static certificate.Exam.mark;
^
AnnualExam.java:12: error: cannot find symbol
System.out.println(mark);
^
symbol: variable mark
location: class AnnualExam
3 errors

C:\myproject\university>


please tell where I am going wrong.
 
Afreen Patel
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And class path is set through environment variable.
 
Afreen Patel
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please guys tell me where I am going wrong? please!!!
 
Nick Widelec
Ranch Hand
Posts: 226
Eclipse IDE Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Afreen Patel wrote:Please guys tell me where I am going wrong? please!!!



Going through this link http://www.ibm.com/developerworks/library/j-classpath-windows/ you will fix your problem.
 
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Afreen Patel wrote:And class path is set through environment variable.


Can you show us the value of the CLASSPATH environment variable. Does it include the C:\myproject directory ?
 
Afreen Patel
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
CLASSPATH
"c:\Program Files (x86)\Java\jdk1.7.0_25\bin;"
 
Stuart A. Burkett
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Afreen Patel wrote:CLASSPATH
"c:\Program Files (x86)\Java\jdk1.7.0_25\bin;"


The JDK bin directory should not be in the CLASSPATH environment variable, only in the PATH environment variable. The CLASSPATH is for telling java/javac where they can find any classes they need.
Try
javac -cp C:\myproject AnnualExam.java
 
Afreen Patel
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It worked

Thank you!
Thank You!!
 
Because those who mind don't matter and those who matter don't mind - Seuss. Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic