首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

各位 给帮满看一上 为啥会报错 难道是小弟我 写错了还是如何的

2012-09-25 
各位 给帮满看一下 为啥会报错 难道是我 写错了还是怎么的import java.util.*import java.io.*package e

各位 给帮满看一下 为啥会报错 难道是我 写错了还是怎么的
import java.util.*;
import java.io.*;
package example;

public class HelloWorld {
public static void main(String[] args) {
PrintWriter out = new PrintWriter("D:\\htdocs\\myfile.txt");
System.out.print("what is your name ?");
String name = out.nextLine();
System.out.print("how old are you ?");
int age = out.nextInt();
System.out.println("hello" + name + "Next year,you `ll be" + (age + 1));

}

}


我想把 名字和年龄写进 D:\\htdocs\\myfile.txt 这个文件 请问我这个 程序 写错了吗 为啥 Eclipse 报错呢 


Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
The method nextLine() is undefined for the type PrintWriter
The method nextInt() is undefined for the type PrintWriter

at example.HelloWorld.main(HelloWorld.java:9)


[解决办法]
这个错误很简单,
The method nextLine() is undefined for the type PrintWriter 
The method nextInt() is undefined for the type PrintWriter 
好好读读这个错误信息
nextLine() 方法没被定义在PrintWriter类里

好好看看JDK的API文档吧!

热点排行