2016-07-14 3 views
-1

私は正しい馬のバッテリーのステイプルスタイルのパスワードジェネレータを作っています。私のTextViewがありますように、それはセットアップし、あなたがそれをタップすると、それはこのようにアクティビティを切り替えている:私はプログラムを実行し、より多くの情報のTextViewをクリックしたときに、私はこのエラーを取得し、
TextView moreInfo = (TextView) findViewById(R.id.moreinfo); moreInfo.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(MainActivity.this, Description.class); startActivity(intent); }; });
しかし:
07-14 12:34:15.930 2295-2295/com.example.bobmo.correcthorsebatterystaple E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.bobmo.correcthorsebatterystaple, PID: 2295 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.bobmo.correcthorsebatterystaple/com.example.bobmo.correcthorsebatterystaple.Description}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setClickable(boolean)' on a null object reference at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2339) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2413) at android.app.ActivityThread.access$800(ActivityThread.java:155) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1317) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5343) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700) Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setClickable(boolean)' on a null object reference at com.example.bobmo.correcthorsebatterystaple.Description.onCreate(Description.java:16) at android.app.Activity.performCreate(Activity.java:6010) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1129) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2292) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2413)  at android.app.ActivityThread.access$800(ActivityThread.java:155)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1317)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:135)  at android.app.ActivityThread.main(ActivityThread.java:5343)  at java.lang.reflect.Method.invoke(Native Method)  at java.lang.reflect.Method.invoke(Method.java:372)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700) 
...そして、電話では、プログラムが停止したと言います。これを修正する方法はありますか?ありがとう!ヌルAndroidでの切り替えのアクティビティ奇妙なエラー

+0

を持つ任意のビューが含まれていませんあなたがNullPointerExceptionを持っていることを教えてください。また、あなたはテキストビューをクリックしているボタンをクリックしていません。 – basic

答えて

2
TextView moreInfo = (TextView) findViewById(R.id.moreinfo); 

findViewById戻り、それが現在の活動内容ビューにビューが見つかりませんでしたので、あなたはおそらく正しいレイアウトを設定していないか、そのレイアウトはありません奇妙なID R.id.moreinfo

+0

xmlでtextviewを定義した場所を二重にチェックしました。これは私のコードです:
' ' –

+0

@BobMonkeywartsあなたはsetContentView(R.layoutを呼び出しています。?)findViewByIdの前に? – Ladas125

+0

はい、findviewbyidの前にsetcontentviewを呼び出しています。 –

関連する問題