我正在努力创建一个实例。当我在初始调用 onCreate 函数后不执行我的代码时,它会起作用。Logcat 向我抛出了大量无用的错误(至少对我而言)。这是我正在调用的代码
String note=null;
FileInputStream fip=null;
try{
fip=new FileInputStream(this.getFilesDir()+"/currentNote");
}
catch(FileNotFoundException e){
//The first and probably last time this is useful
note="";
}
try {
while(fip.available()>0){
byte current=(byte)fip.read();
note=note+String.valueOf(current);
}
}
catch (IOException e) {
//Just... no
}
TextView note_display=(TextView) findVewById(R.id.note_input);
note_display.setText(note);
这是logcat日志:
05-20 20:11:04.988: W/dalvikvm(20463): threadid=1: thread exiting with uncaught exception (group=0x410d9930)
05-20 20:11:05.008: E/AndroidRuntime(20463): FATAL EXCEPTION: main
05-20 20:11:05.008: E/AndroidRuntime(20463): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.buhala.notestaker/com.buhala.notestaker.ShowNote}: java.lang.NullPointerException
05-20 20:11:05.008: E/AndroidRuntime(20463): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2307)
05-20 20:11:05.008: E/AndroidRuntime(20463): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2357)
05-20 20:11:05.008: E/AndroidRuntime(20463): at android.app.ActivityThread.access$600(ActivityThread.java:153)
05-20 20:11:05.008: E/AndroidRuntime(20463): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1247)
05-20 20:11:05.008: E/AndroidRuntime(20463): at android.os.Handler.dispatchMessage(Handler.java:99)
05-20 20:11:05.008: E/AndroidRuntime(20463): at android.os.Looper.loop(Looper.java:137)
05-20 20:11:05.008: E/AndroidRuntime(20463): at android.app.ActivityThread.main(ActivityThread.java:5226)
05-20 20:11:05.008: E/AndroidRuntime(20463): at java.lang.reflect.Method.invokeNative(Native Method)
05-20 20:11:05.008: E/AndroidRuntime(20463): at java.lang.reflect.Method.invoke(Method.java:511)
05-20 20:11:05.008: E/AndroidRuntime(20463): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
05-20 20:11:05.008: E/AndroidRuntime(20463): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
05-20 20:11:05.008: E/AndroidRuntime(20463): at dalvik.system.NativeStart.main(Native Method)
05-20 20:11:05.008: E/AndroidRuntime(20463): Caused by: java.lang.NullPointerException
05-20 20:11:05.008: E/AndroidRuntime(20463): at com.buhala.notestaker.ShowNote.getText(ShowNote.java:36)
05-20 20:11:05.008: E/AndroidRuntime(20463): at com.buhala.notestaker.ShowNote.onCreate(ShowNote.java:22)
05-20 20:11:05.008: E/AndroidRuntime(20463): at android.app.Activity.performCreate(Activity.java:5104)
05-20 20:11:05.008: E/AndroidRuntime(20463): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
05-20 20:11:05.008: E/AndroidRuntime(20463): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2261)
05-20 20:11:05.008: E/AndroidRuntime(20463): ... 11 more
(我在格式化上很努力)那么,有什么想法我做错了什么吗?