• Post Reply Bookmark Topic Watch Topic
  • New Topic

Error while using packages  RSS feed

 
sunil oza
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi

i am trying to use package and the following is the code and the error i am getting while compiling. Please suggest a way to do it.
both the classes are in same package and are public. one is a bean with getter and setter methods and another is with main were i m trying to create a object of the first class. Please check and guide.
class1:
package practice;

public class TestIO {
String roll_no;
String name =null;
boolean flag ;

public boolean isFlag() {
return flag;
}
public void setFlag(boolean flag) {
this.flag = flag;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getRoll_no() {
return roll_no;
}
public void setRoll_no(String roll_no) {
this.roll_no = roll_no;
}



}

Class2
package practice;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import practice.TestIO;
public class TestIOMain {

public static void main(String[] args) {
TestIO tio=new TestIO();
String roll_no=null;
boolean flag;
System.out.println("Enter your details");
try{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter your roll number");
roll_no=br.readLine();
tio.setRoll_no(roll_no);
if(roll_no.equals("")){
tio.setFlag(false);
System.out.println("entered in if ");
}
else{
tio.setFlag(true);
}
flag=tio.isFlag();

if(flag==false){
System.out.println("Flag is false because roll no can't be blank program will terminate ");
System.exit(1);
}
else{
System.out.println("Enter your name");
tio.setName(br.readLine());
System.out.println("****************************");
System.out.println("The details entered are");
System.out.println("****************************");
System.out.println("Roll no:"+tio.getRoll_no());
System.out.println("Name :"+tio.getName());
}
}
catch(IOException ioe){
ioe.printStackTrace();
}

}

}

error while compiling:
for class1
C:\Documents and Settings\Administrator\Desktop>javac -d . TestIO.java

while compiling class 2
C:\Documents and Settings\Administrator\Desktop>javac -d . TestIOMain.java
TestIOMain.java:6: cannot resolve symbol
symbol : class TestIO
location: package practice
import practice.TestIO;
^
TestIOMain.java:10: cannot resolve symbol
symbol : class TestIO
location: class practice.TestIOMain
TestIO tio=new TestIO();
^
TestIOMain.java:10: cannot resolve symbol
symbol : class TestIO
location: class practice.TestIOMain
TestIO tio=new TestIO();
^
3 errors


 
shivendra tripathi
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it's not problem with import. This is the problem with your class path setting. class practice.TestIO is not your classpath. try compiling with javac -cp practice.TestIO TestIOMain.java.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sunil,

Please use code tags
You can edit your existing post to incorporate them by clicking on the button.
 
Campbell Ritchie
Marshal
Posts: 56533
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please use the CODE button; your code is difficult to read.

I tried exactly what you did and it worked first time.

you should have a directory structure like thisI don't know what the problem is, but it is worth printing your CLASSPATH. If nothing prints out at all, then the CLASSPATH is all right. If anything prints out at all then your CLASSPATH needs a . for current directory somewhere.
 
shivendra tripathi
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
use
javac -d . -cp . TestIOMain.java
I have executed it. And it worked.
 
Campbell Ritchie
Marshal
Posts: 56533
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
shivendra tripathi wrote:use
javac -d . -cp . TestIOMain.java
I have executed it. And it worked.
If you can sort out your problem with that solution, then you need to review your system classpath. If that doesn't sort it out, please tell us.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!