本人的在eclipse中写的java程序如下(程序1):
import java.io.*;
public class Nixu
{
class Input
{
BufferedReader br;
String s;
int i;
int init()
{
br=new BufferedReader(new InputStreamReader(System.in));
try
{
s=br.readLine();
}
catch(IOException e)
{
e.getStackTrace();
}
return i=Integer.parseInt(s);
}
}
public static void main(String[] args)
{
//Input p = new Input();
}
}程序没有错误,但是如果我把类Input 移到公共类的外面 改成如下程序(程序2):import java.io.*;
class Input
{
BufferedReader br;
String s;
int i;
int init()
{
br=new BufferedReader(new InputStreamReader(System.in));
try
{
s=br.readLine();
}
catch(IOException e)
{
e.getStackTrace();
}
return i=Integer.parseInt(s);
}
}
public class Nixu
{
public static void main(String[] args)
{
//Input p = new Input();
}
}程序就出错了 错误在第一行 import java.io.*; 错误提示是 Mutiple ers at this line, the type Input is already defined,30已更改 行。顺便问一下 在程序1中 我把注释行//Input p = new Input();的注释去掉,程序就错了 错误提示是:
No enclosing instance of type Nixu is accessible. Must qualify the allocation with
an enclosing instance of type Nixu (e.g. x.new A() where x is an instance of Nixu).
这个又是怎么回事啊????
import java.io.*;
public class Nixu
{
class Input
{
BufferedReader br;
String s;
int i;
int init()
{
br=new BufferedReader(new InputStreamReader(System.in));
try
{
s=br.readLine();
}
catch(IOException e)
{
e.getStackTrace();
}
return i=Integer.parseInt(s);
}
}
public static void main(String[] args)
{
//Input p = new Input();
}
}程序没有错误,但是如果我把类Input 移到公共类的外面 改成如下程序(程序2):import java.io.*;
class Input
{
BufferedReader br;
String s;
int i;
int init()
{
br=new BufferedReader(new InputStreamReader(System.in));
try
{
s=br.readLine();
}
catch(IOException e)
{
e.getStackTrace();
}
return i=Integer.parseInt(s);
}
}
public class Nixu
{
public static void main(String[] args)
{
//Input p = new Input();
}
}程序就出错了 错误在第一行 import java.io.*; 错误提示是 Mutiple ers at this line, the type Input is already defined,30已更改 行。顺便问一下 在程序1中 我把注释行//Input p = new Input();的注释去掉,程序就错了 错误提示是:
No enclosing instance of type Nixu is accessible. Must qualify the allocation with
an enclosing instance of type Nixu (e.g. x.new A() where x is an instance of Nixu).
这个又是怎么回事啊????
解决方案 »
- 请问,在类A中 add 一个类B的对象, 类B是接口的实现,如何在类B中读取 类A中的属性?
- 做一个简单的java编译器,怎么做项目管理打开工程,文件
- 怎么样实现反编译啊?
- eclipse调试时,发现调试窗口有线程[Thread-1**](正在运行),该线程应该是我代码里启动的,且没起名字,如何能查出是哪里启动了这个线程
- Exception in thread "main" java.lang.NoClassDefFoundError: com/adventnet/afp/log/AbstractLogger
- 请教:如何把YY-MM-格式的日期转化为DDYYMMDD格式的日期
- 麻烦给出在JAVA里实现2字节数组到short转换的代码
- 紧急求救SCJP考试问题!!急了!
- XP,IE 6 SP1,安装JRE 1.4无数次,<APPLET>标签下的东西仍不能看,<OBJECT>可以,为什么??!!求救!!
- 如何手动控制 打开 “Java控制台”?
- 做一个像ACDSee的东东 ,右边显示图片的预览器应该用什么容器
- 高手帮忙看个问题
BufferedReader br;
String s;
int i; int init() {
br = new BufferedReader(new InputStreamReader(System.in));
try {
s = br.readLine();
} catch (IOException e) {
e.getStackTrace();
}
return i = Integer.parseInt(s);
}
}public class Nixu { public static void main(String[] args) {
Input p = new Input();
}
}我的没有错误.. 你是不是在同包下还有其他的 input 之类的.
import java.io.*;
public class Nixu
{
public static void main(String[] args)
{
Input p = new Input();
p.init();
}
}class Input
{
BufferedReader br;
String s;
int i;
int init()
{
br=new BufferedReader(new InputStreamReader(System.in));
try
{
s=br.readLine();
}
catch(IOException e)
{
e.getStackTrace();
}
return i=Integer.parseInt(s);
}
}你是不是要写成这个样子啊。就是在控制台上输入数字,你就返回数字!
public Input getInput() //增加一方法
{
return new Input();
}
public static void main(String[] args)
{
Test t = new Test();
Test.Input p = t.getInput(); //通过外部类名及类引用
}
程序2没错,肯定是其他问题
你这样试下:Nixu ni=new Nixu(); //创建外部内对象ni
Nixu.Input input=ni.new Input(); //利用外部类创建内部类对象input
建议LZ看下内部类方面的书