当前位置: 技术问答>java相关
关于package问题。晕着呢!
来源: 互联网 发布时间:2017-03-31
本文导语: // a.java package test; import java.util.*; public interface a { int rint=(int)(Math.random()*10); long rlong=(long)(Math.random()*10); float rfloat=(float)(Math.random()*10); double rdouble=(double)(Math.random()*10); } //b.java import test.*; public class b { publ...
// a.java
package test;
import java.util.*;
public interface a
{
int rint=(int)(Math.random()*10);
long rlong=(long)(Math.random()*10);
float rfloat=(float)(Math.random()*10);
double rdouble=(double)(Math.random()*10);
}
//b.java
import test.*;
public class b
{
public static void main(String[] args)
{
System.out.println(a.rint);
System.out.println(a.rlong);
System.out.println(a.rfloat);
System.out.println(a.rdouble);
}
}
其中:都在c:jdk1.4.0test目录下。
1.javac a.java 通过
2.java b.java 报错:
TestRandVals.java:2: package test does not exist
import test.*;
^
TestRandVals.java:8: cannot access RandVals
bad class file: .RandVals.class
class file contains wrong class: test.RandVals
Please remove or make sure it appears in the correct subdirectory of the classp
th.
System.out.println(RandVals.rint);
^
2 errors
请问怎么解决呀?
package test;
import java.util.*;
public interface a
{
int rint=(int)(Math.random()*10);
long rlong=(long)(Math.random()*10);
float rfloat=(float)(Math.random()*10);
double rdouble=(double)(Math.random()*10);
}
//b.java
import test.*;
public class b
{
public static void main(String[] args)
{
System.out.println(a.rint);
System.out.println(a.rlong);
System.out.println(a.rfloat);
System.out.println(a.rdouble);
}
}
其中:都在c:jdk1.4.0test目录下。
1.javac a.java 通过
2.java b.java 报错:
TestRandVals.java:2: package test does not exist
import test.*;
^
TestRandVals.java:8: cannot access RandVals
bad class file: .RandVals.class
class file contains wrong class: test.RandVals
Please remove or make sure it appears in the correct subdirectory of the classp
th.
System.out.println(RandVals.rint);
^
2 errors
请问怎么解决呀?
|
先设置好classpath
文件目录如下:
……testa.java
……b.java
转到……下用javac 和 java命令
祝好运
文件目录如下:
……testa.java
……b.java
转到……下用javac 和 java命令
祝好运