これが私のコードです:
public class NoteView extends FragmentActivity implements CustomDialogFragment.CustomDialogListener {
private Uri mUri;
private String[] projection = { NotepadContract.Notes.COLUMN_NAME_NOTE,
NotepadContract.Notes.COLUMN_NAME_TITLE };
private TextView mTextView;
private String content;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.note_view);
mTextView = (TextView) findViewById(R.id.text_body);
// Show the Up button in the action bar.
getActionBar().setDisplayHomeAsUpEnabled(true);
Intent intent = getIntent();
mUri = intent.getData();
// String action=intent.getAction();
// if ("com.yuyizhao.NoteView".equals(action)) System.out.println(mUri);
Cursor mCursor = getContentResolver().query(mUri, projection, null,
null, null);
int index_note = mCursor
.getColumnIndexOrThrow(NotepadContract.Notes.COLUMN_NAME_NOTE);
System.out.println(index_note);
int index_title = mCursor
.getColumnIndexOrThrow(NotepadContract.Notes.COLUMN_NAME_TITLE);
System.out.println(index_title);
if (mCursor != null) {
while (mCursor.moveToNext()) {
content = mCursor.getString(index_note);
setTitle(mCursor.getString(index_title));
System.out.println(mCursor.getString(index_title));
System.out.println(mCursor.getString(index_note));
}
}
mTextView.setText(content);
}
レイアウト xml ファイル:(note_view xml)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/view_body"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:scrollbars="vertical"
android:textIsSelectable="true"
android:textSize="@dimen/font_medium" />
</LinearLayout>
これらは、logcat で取得したエラー メッセージです。何度も試しましたが、それでも同じエラーが発生します。まず、メモのインデックスと内容を印刷します。これらは正しくあります。しかし、setText() を使用してコンテンツを TextView ウィジェットに入れると、バグが出てきます。
02-25 06:25:48.132: I/ActivityManager(289): START u0 {act=com.yuyizhao.NoteView dat=content://com.yuyizhao.notepad_yuyizhao.provider/notes/1 cmp=com.yuyizhao.notepad_yuyizhao/.NoteView} from pid 2243
02-25 06:25:48.482: D/dalvikvm(289): GC_FOR_ALLOC freed 1176K, 31% free 12125K/17420K, paused 92ms, total 104ms
02-25 06:25:48.522: I/Choreographer(2243): Skipped 30 frames! The application may be doing too much work on its main thread.
02-25 06:25:48.803: I/System.out(2243): 0
02-25 06:25:48.803: I/System.out(2243): 1
02-25 06:25:48.803: I/System.out(2243): wqdwqdqwdqwd
02-25 06:25:48.813: I/System.out(2243): wdqwdqwdqwdqwdwqdwddwq
02-25 06:25:48.823: D/AndroidRuntime(2243): Shutting down VM
02-25 06:25:48.823: W/dalvikvm(2243): threadid=1: thread exiting with uncaught exception (group=0x40a70930)
02-25 06:25:48.863: E/AndroidRuntime(2243): FATAL EXCEPTION: main
02-25 06:25:48.863: E/AndroidRuntime(2243): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.yuyizhao.notepad_yuyizhao/com.yuyizhao.notepad_yuyizhao.NoteView}: java.lang.NullPointerException
02-25 06:25:48.863: E/AndroidRuntime(2243): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
02-25 06:25:48.863: E/AndroidRuntime(2243): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
02-25 06:25:48.863: E/AndroidRuntime(2243): at android.app.ActivityThread.access$600(ActivityThread.java:141)
02-25 06:25:48.863: E/AndroidRuntime(2243): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
02-25 06:25:48.863: E/AndroidRuntime(2243): at android.os.Handler.dispatchMessage(Handler.java:99)
02-25 06:25:48.863: E/AndroidRuntime(2243): at android.os.Looper.loop(Looper.java:137)
02-25 06:25:48.863: E/AndroidRuntime(2243): at android.app.ActivityThread.main(ActivityThread.java:5039)
02-25 06:25:48.863: E/AndroidRuntime(2243): at java.lang.reflect.Method.invokeNative(Native Method)
02-25 06:25:48.863: E/AndroidRuntime(2243): at java.lang.reflect.Method.invoke(Method.java:511)
02-25 06:25:48.863: E/AndroidRuntime(2243): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
02-25 06:25:48.863: E/AndroidRuntime(2243): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
02-25 06:25:48.863: E/AndroidRuntime(2243): at dalvik.system.NativeStart.main(Native Method)
02-25 06:25:48.863: E/AndroidRuntime(2243): Caused by: java.lang.NullPointerException
02-25 06:25:48.863: E/AndroidRuntime(2243): at com.yuyizhao.notepad_yuyizhao.NoteView.onCreate(NoteView.java:53)
02-25 06:25:48.863: E/AndroidRuntime(2243): at android.app.Activity.performCreate(Activity.java:5104)
02-25 06:25:48.863: E/AndroidRuntime(2243): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
02-25 06:25:48.863: E/AndroidRuntime(2243): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
02-25 06:25:48.863: E/AndroidRuntime(2243): ... 11 more
02-25 06:25:48.913: W/ActivityManager(289): Force finishing activity com.yuyizhao.notepad_yuyizhao/.NoteView
02-25 06:25:48.932: W/ActivityManager(289): Force finishing activity com.yuyizhao.notepad_yuyizhao/.Notepad
02-25 06:25:49.252: E/SurfaceFlinger(37): ro.sf.lcd_density must be defined as a build property
02-25 06:25:49.442: W/ActivityManager(289): Activity pause timeout for ActivityRecord{40eed718 u0 com.yuyizhao.notepad_yuyizhao/.NoteView}
02-25 06:25:49.823: E/SurfaceFlinger(37): ro.sf.lcd_density must be defined as a build property
02-25 06:25:49.833: W/EGL_emulation(403): eglSurfaceAttrib not implemented
-25 06:25:48.132: I/ActivityManager(289): START u0 {act=com.yuyizhao.NoteView dat=content://com.yuyizhao.notepad_yuyizhao.provider/notes/1 cmp=com.yuyizhao.notepad_yuyizhao/.NoteView} from pid 2243
02-25 06:25:48.482: D/dalvikvm(289): GC_FOR_ALLOC freed 1176K, 31% free 12125K/17420K, paused 92ms, total 104ms
02-25 06:25:48.522: I/Choreographer(2243): Skipped 30 frames! The application may be doing too much work on its main thread.
02-25 06:25:48.803: I/System.out(2243): 0
02-25 06:25:48.803: I/System.out(2243): 1
02-25 06:25:48.803: I/System.out(2243): wqdwqdqwdqwd
02-25 06:25:48.813: I/System.out(2243): wdqwdqwdqwdqwdwqdwddwq
02-25 06:25:48.823: D/AndroidRuntime(2243): Shutting down VM
02-25 06:25:48.823: W/dalvikvm(2243): threadid=1: thread exiting with uncaught exception (group=0x40a70930)
02-25 06:25:48.863: E/AndroidRuntime(2243): FATAL EXCEPTION: main
02-25 06:25:48.863: E/AndroidRuntime(2243): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.yuyizhao.notepad_yuyizhao/com.yuyizhao.notepad_yuyizhao.NoteView}: java.lang.NullPointerException
02-25 06:25:48.863: E/AndroidRuntime(2243): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
02-25 06:25:48.863: E/AndroidRuntime(2243): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
02-25 06:25:48.863: E/AndroidRuntime(2243): at android.app.ActivityThread.access$600(ActivityThread.java:141)
02-25 06:25:48.863: E/AndroidRuntime(2243): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
02-25 06:25:48.863: E/AndroidRuntime(2243): at android.os.Handler.dispatchMessage(Handler.java:99)
02-25 06:25:48.863: E/AndroidRuntime(2243): at android.os.Looper.loop(Looper.java:137)
02-25 06:25:48.863: E/AndroidRuntime(2243): at android.app.ActivityThread.main(ActivityThread.java:5039)
02-25 06:25:48.863: E/AndroidRuntime(2243): at java.lang.reflect.Method.invokeNative(Native Method)
02-25 06:25:48.863: E/AndroidRuntime(2243): at java.lang.reflect.Method.invoke(Method.java:511)
02-25 06:25:48.863: E/AndroidRuntime(2243): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
02-25 06:25:48.863: E/AndroidRuntime(2243): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
02-25 06:25:48.863: E/AndroidRuntime(2243): at dalvik.system.NativeStart.main(Native Method)
02-25 06:25:48.863: E/AndroidRuntime(2243): Caused by: java.lang.NullPointerException
02-25 06:25:48.863: E/AndroidRuntime(2243): at com.yuyizhao.notepad_yuyizhao.NoteView.onCreate(NoteView.java:53)
02-25 06:25:48.863: E/AndroidRuntime(2243): at android.app.Activity.performCreate(Activity.java:5104)
02-25 06:25:48.863: E/AndroidRuntime(2243): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
02-25 06:25:48.863: E/AndroidRuntime(2243): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
02-25 06:25:48.863: E/AndroidRuntime(2243): ... 11 more
02-25 06:25:48.913: W/ActivityManager(289): Force finishing activity com.yuyizhao.notepad_yuyizhao/.NoteView
02-25 06:25:48.932: W/ActivityManager(289): Force finishing activity com.yuyizhao.notepad_yuyizhao/.Notepad
02-25 06:25:49.252: E/SurfaceFlinger(37): ro.sf.lcd_density must be defined as a build property
02-25 06:25:49.442: W/ActivityManager(289): Activity pause timeout for ActivityRecord{40eed718 u0 com.yuyizhao.notepad_yuyizhao/.NoteView}
02-25 06:25:49.823: E/SurfaceFlinger(37): ro.sf.lcd_density must be defined as a build property
02-25 06:25:49.833: W/EGL_emulation(403): eglSurfaceAttrib not implemented
setText()
メソッドを使用しているときにこのエラーが発生した理由を知っている人はいますか?