这段代码那里出现空指针。请教高手。
java.lang.NullPointerException
这段代码那里出现空指针。
void introduce(int x)
{
String fn;
fn="/";
fn=fn+Integer.toString(x);
fn=fn+".txt";
InputStream in = getClass().getResourceAsStream(fn);
ByteArrayOutputStream s;
s = new ByteArrayOutputStream(); //产生内存数组输出字节流对象变量S
try{
int ch=0;
ch=in.read(); //由输入流对象变量in的read方法以字节为单位来读取文件的内容,读取到文件尾时的值为-1。
while ( ch!= -1 ) {
//如果未读到文件尾把读取的内容写入S变量中,并读取下一字节内容
s.write( ch );
ch=in.read();
}
in.close(); //关闭输入流对象。
} catch (IOException ioe){
System.out.println(ioe.toString());
}
sr = s.toString(); //将S变量转为字符串
try{
s.close(); //关闭输出流对象
} catch (IOException ioe){
System.out.println(ioe.toString());
}
// phone =new TextField(menu.getTitle(), Sr,4000,0);
// ui_form.append(phone);
myCanvas.setTitle("三国演义");
myCanvas.addCommand(quit);
myCanvas.addCommand(back);
myCanvas.setCommandListener(this);
display.setCurrent(myCanvas);
}