本人的在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).
这个又是怎么回事啊????
解决方案 »
- 把程序放在后台跑,就一定要 extends Thread 吗?
- 不知道哪里的毛病,关于WOW密保卡读取密保卡卡码的小程序~~~
- 到底什么情况才需要手动重启tomcat
- 怎样使产生的随机数不出现重复
- java 读写 word (带排版格式)
- 急求:怎么实现鼠标放到哪里就显示一个消息显示该点的坐标
- 为什么执行这条update语句时,会报错?
- 为什么我在WIN2003下,用JDBC连不上SQL SERVER数据库啊!
- 一个Class调用另外一个class的问题
- 采用for嵌套循环如何写下面两个代码???????????
- 做一个像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看下内部类方面的书