Home > Mobile >  Java. Lang. RuntimeException abnormalities, a great god, please grant instruction!!!!!!
Java. Lang. RuntimeException abnormalities, a great god, please grant instruction!!!!!!

Time:10-16

11 to 18 09:39:51. 281, 19604-19604/com. Example. Admin. Emotion E/AndroidRuntime: FATAL EXCEPTION: the main
Process: com. Example. Admin. Emotion, PID: 19604
Java. Lang. RuntimeException: Unable to start the activity ComponentInfo {com. Example. Admin. Emotion/com. Example. Admin. Emotion. MainFragment} : Java. Lang. NullPointerException: Attempt to invoke virtual method 'void android. View. The view. SetOnClickListener (android. View. The view $an OnClickListener)' on a null object reference
. An android app. ActivityThread. PerformLaunchActivity (ActivityThread. Java: 2793)
. An android app. ActivityThread. HandleLaunchActivity (ActivityThread. Java: 2864)
. An android app. ActivityThread. - wrap12 (ActivityThread. Java)
An android. App. ActivityThread $H.h andleMessage (ActivityThread. Java: 1567)
An android. OS. Handler. DispatchMessage (Handler. Java: 105)
. An android OS. Stars. Loop (156). Which Java:
. An android app. ActivityThread. Main (6524) ActivityThread. Java:
The at Java. Lang. Reflect. Method. Invoke (Native Method)
At com. Android. Internal. OS. $MethodAndArgsCaller ZygoteInit. Run (ZygoteInit. Java: 941)
At com. Android. Internal. OS. ZygoteInit. Main (ZygoteInit. Java: 831)
Under Caused by: Java. Lang. NullPointerException: Attempt to invoke virtual method 'void android. View. The view. SetOnClickListener (android. View. The view $an OnClickListener)' on a null object reference
At com. Example. Admin. Emotion. MainFragment. InitView (MainFragment. Java: 80)
At com. Example. Admin. Emotion. MainFragment. OnCreate (MainFragment. Java: 59)
. An android app. Activity. PerformCreate (6910) Activity. Java:
. An android app. Instrumentation. CallActivityOnCreate (1123) Instrumentation. Java:
. An android app. ActivityThread. PerformLaunchActivity (ActivityThread. Java: 2746)
. An android app. ActivityThread. HandleLaunchActivity (ActivityThread. Java: 2864)
. An android app. ActivityThread. - wrap12 (ActivityThread. Java)
An android. App. ActivityThread $H.h andleMessage (ActivityThread. Java: 1567)
An android. OS. Handler. DispatchMessage (Handler. Java: 105)
. An android OS. Stars. Loop (156). Which Java:
. An android app. ActivityThread. Main (6524) ActivityThread. Java:
The at Java. Lang. Reflect. Method. Invoke (Native Method)
At com. Android. Internal. OS. $MethodAndArgsCaller ZygoteInit. Run (ZygoteInit. Java: 941)
At com. Android. Internal. OS. ZygoteInit. Main (ZygoteInit. Java: 831)
Wrong code:
Protected void onCreate (Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
The setContentView (R.l ayout. Content_main);
FragmentManager=getSupportFragmentManager ();
InitView ();
SetChioceItem (0);
}

Private void initView () {
FirstImage=(ImageView) the findViewById (R.i d.f irst_image);
SecondImage=(ImageView) the findViewById (R.i d.s econd_image);
ThirdImage=(ImageView) the findViewById (R.i which hird_image);
FourthImage=(ImageView) the findViewById (R.i d.f ourth_image);
FirstText=(TextView) the findViewById (R.i d.f irst_text);
SecondText=(TextView) the findViewById (R.i d.s econd_text);
ThirdText=(TextView) the findViewById (R.i which hird_text);
FourthText=(TextView) the findViewById (R.i d.f ourth_text);
FirstLayout=(RelativeLayout) the findViewById (R.i d.f irst_layout);
SecondLayout=(RelativeLayout) the findViewById (R.i d.s econd_layout);
ThirdLayout=(RelativeLayout) the findViewById (R.i which hird_layout);
FourthLayout=(RelativeLayout) the findViewById (R.i d.f ourth_layout);

FirstLayout. SetOnClickListener (MainFragment. This);
SecondLayout. SetOnClickListener (MainFragment. This);
ThirdLayout. SetOnClickListener (MainFragment. This);
FourthLayout. SetOnClickListener (MainFragment. This);
}

CodePudding user response:

NullPointerException if you click Settings that control does not give the findviewbyid?

CodePudding user response:

SetOnClickListener reference view is empty, when using, increase the judge whether the control is empty, or troubleshoot your process to find the real rootcause,

CodePudding user response:

Com. Example. Admin. Emotion. MainFragment. InitView (MainFragment. Java: 80)
80 rows call setOnClickListener object is empty,

CodePudding user response:

1. Look at the code you have already the findViewById
2. Now that can compile installation instructions right
Thus the id you are looking for is not content_main the layout file, and in other layout file
Can to MainFragment. Java line 80 to see which objects are, and then to search to see whether there is in the layout file

CodePudding user response:

InitView way you write wrong, you have a look at fragments of life cycle, should you want to use the View after onViewCreated onCreate interface when haven't apply colours to a drawing to the window,

CodePudding user response:

  • Related