Reputation: 2001
I have created a class with name 'Minn' in a package in G: drive.
And now i want to use this class in a class which i am defining inside another folder of G:drive.
So,i am importing that package.
But the error shows package doesn't exist.
Below is the code.
Minn.java
package packa;
import java.io.*;
class Minn {
public int min(int a[],int x) {
int minimum=Integer.MAX_VALUE;
for(int i=0;i<x;i++) {
if(a[i]< minimum)
minimum=a[i];
}
return minimum;
}
}
Tes.java
import java.io.*;
import java.util.*;
import packa.*;
class Tes {
static int a[];
public static void main(String s[]) {
a=new int[10];
Random r=new Random();
for(int i=0;i<10;i++) {
a[i]=r.nextInt(30);
System.out.println(a[i]+" " );
}
new Tes().call();
}
void call() {
int ret=new Minn().min(a,10);
System.out.println("min is "+ret);
}
}
Upvotes: 0
Views: 38
Reputation: 1077
When you want to import a class from another project, you have to add It to the Build Path in project properties.
If your project is inside the Workspace, just choose "add class folder". If it's outside your workspace, use "add external class folder".
Hope that helps.
Upvotes: 1