Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

interfaces used to work on my system but now they dont :)

 
sunil mirani
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is the code
/*Inter.java*/
interface Inter{
void disp();
}
/*B.java*/
class A implements Inter{
public void disp(){
System.out.println("This is working ???");
}
}
public class B {
public static void main(String args[]){
Inter obj = new A();
obj.disp();
}
}
on compiling it gives this error :
C:\examples\inter\B.java:1: cannot resolve symbol
symbol : class Inter
location: class A
class A implements Inter{
^
C:\examples\inter\B.java:9: cannot resolve symbol
symbol : class Inter
location: class B
Inter obj = new A();
^
2 errors

But if i put the interface i the file B.java it works..
plz tell me ??? what to do ??
 
Susan Hoover
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The thing that comes to mind is the package structure. Make sure that Inter and B are in the same package. If you don't specify a "package foo.bar;" line at the top of your files, then Inter and B are in the same package and must be in the same directory, which is the directory you're compiling from.
Since you have provided the output, I'm going to assume that C:\examples\inter is the directory that contains both Inter.java and B.java. There are several ways you can structure this:
1. No package statements.
This means that C:\examples\inter is the root of your package structure, and you have to either compile from C:\examples\inter or use the -sourcepath C:\examples\inter option.
2. package inter;
This means that C:\examples is the root of your package structure, and you have to either compile from C:\examples or use the -sourcepath C:\examples option.
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sunil:
the code you posted, in the same format, works fine on my
system.
pl. check your env.
regds.
- satya
 
sunil mirani
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Susan,
Susan, I dont want to use a package for this , i think there is a problem in the env setting of my system it is a 98 if you tell me the class path i shall try.
the same code works on other machines, i too have checked it.

Originally posted by Susan Hoover:
The thing that comes to mind is the package structure. Make sure that Inter and B are in the same package. If you don't specify a "package foo.bar;" line at the top of your files, then Inter and B are in the same package and must be in the same directory, which is the directory you're compiling from.
Since you have provided the output, I'm going to assume that C:\examples\inter is the directory that contains both Inter.java and B.java. There are several ways you can structure this:
1. No package statements.
This means that C:\examples\inter is the root of your package structure, and you have to either compile from C:\examples\inter or use the -sourcepath C:\examples\inter option.
2. package inter;
This means that C:\examples is the root of your package structure, and you have to either compile from C:\examples or use the -sourcepath C:\examples option.

 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I am just wondering if you have specified "." in your
classpath variable ie; the current working dir.
regds.
- satya
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic