求大神解答下问题:java.lang.NullPointerException这个错误该怎么修改 10
importjava.io.BufferedReader;importjava.io.BufferedWriter;importjava.io.FileInputStre...
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintStream;
public class TestChengji
{
private static BufferedReader ba;
/**
* @param args
*/public static void main(String[] args)
{ String name;
String []stu=new String[3];
String []javaScore=new String[3];
String []cScore=new String[3];
Student Stu[]=new Student[3];
try
{
FileOutputStream b=new FileOutputStream("chengji.txt");
BufferedWriter bw=new BufferedWriter(
new OutputStreamWriter(
new FileOutputStream("chengji.txt")));
BufferedReader br=new BufferedReader(
new InputStreamReader(System.in));
for(int i=0;i<3;i++)
{
System.out.println("Please input Student name:");
stu[i]=br.readLine();
Stu[i]=new Student(stu[i]);
System.out.println("please input the java Score:");
javaScore[i]=br.readLine();
Stu[i].setJavaScore(Integer.parseInt(javaScore[i]));
System.out.println("please input the c Score:");
cScore[i]=br.readLine();
Stu[i].setCScore(Integer.parseInt(cScore[i]));
}
br.close();
PrintStream a=new PrintStream(b);
for(int i=0;i<3;i++)
{
bw.write(Stu[i].getName());
bw.write("\n");
bw.write(String.valueOf(Stu[i].getJavaScore()));
bw.write("\n");
bw.write(String.valueOf(Stu[i].getcScore()));
bw.write("\n");
}
bw.close();
FileInputStream g=new FileInputStream("triangle.txt");
ba = new BufferedReader(new InputStreamReader(g));
a=new PrintStream(System.out);
while((name=ba.readLine())!=null)
a.println(name);
}
catch (Exception e)
{
System.out.println(e);
}
}
} 展开
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintStream;
public class TestChengji
{
private static BufferedReader ba;
/**
* @param args
*/public static void main(String[] args)
{ String name;
String []stu=new String[3];
String []javaScore=new String[3];
String []cScore=new String[3];
Student Stu[]=new Student[3];
try
{
FileOutputStream b=new FileOutputStream("chengji.txt");
BufferedWriter bw=new BufferedWriter(
new OutputStreamWriter(
new FileOutputStream("chengji.txt")));
BufferedReader br=new BufferedReader(
new InputStreamReader(System.in));
for(int i=0;i<3;i++)
{
System.out.println("Please input Student name:");
stu[i]=br.readLine();
Stu[i]=new Student(stu[i]);
System.out.println("please input the java Score:");
javaScore[i]=br.readLine();
Stu[i].setJavaScore(Integer.parseInt(javaScore[i]));
System.out.println("please input the c Score:");
cScore[i]=br.readLine();
Stu[i].setCScore(Integer.parseInt(cScore[i]));
}
br.close();
PrintStream a=new PrintStream(b);
for(int i=0;i<3;i++)
{
bw.write(Stu[i].getName());
bw.write("\n");
bw.write(String.valueOf(Stu[i].getJavaScore()));
bw.write("\n");
bw.write(String.valueOf(Stu[i].getcScore()));
bw.write("\n");
}
bw.close();
FileInputStream g=new FileInputStream("triangle.txt");
ba = new BufferedReader(new InputStreamReader(g));
a=new PrintStream(System.out);
while((name=ba.readLine())!=null)
a.println(name);
}
catch (Exception e)
{
System.out.println(e);
}
}
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询