Process: com. Example. Myapplicationfile, PID: 14118
Java. Lang. RuntimeException: Unable to start the activity ComponentInfo {com. Example. Myapplicationfile/com. Example. Myapplicationfile. MainActivity} : Java. Lang. NullPointerException: Attempt to invoke virtual method 'int android. Graphics. Bitmap. GetWidth ()' on a null object reference
. An android app. ActivityThread. PerformLaunchActivity (ActivityThread. Java: 2451)
. An android app. ActivityThread. HandleLaunchActivity (ActivityThread. Java: 2511)
. An android app. ActivityThread. Access the $900 (165) ActivityThread. Java:
An android. App. ActivityThread $H.h andleMessage (ActivityThread. Java: 1375)
An android. OS. Handler. DispatchMessage (Handler. Java: 102)
. An android OS. Stars. Loop (150). Which Java:
. An android app. ActivityThread. Main (5621) ActivityThread. Java:
The at Java. Lang. Reflect. Method. Invoke (Native Method)
At com. Android. Internal. OS. $MethodAndArgsCaller ZygoteInit. Run (ZygoteInit. Java: 794)
At com. Android. Internal. OS. ZygoteInit. Main (ZygoteInit. Java: 684)
CodePudding user response:
Reason one: XXX mistakes, if R.l ayout. Main. So it should be the main tag in an XML file using the wrong, the most common and the compiler will not prompt error is the android: name and android: id both confused, carefully check the main, XML tags are allcorrect
Reason two: the setContentView (view) method using the requestWindowFeature () method, and under this error will be prompted to requestFeature must be used before the setContentView, only need to put the requestWindowFeature () method on the setContentView (view) method can be solved before
Reason 3: in the onCreate () method, and the body does not belong to any one method directly to a control findById (R.i d.x x) as a result, needs in a certain way and in the setContentView (view) method before findById (R.i d.x x) can solve
Reason 4: in the setContentView (view) had no prior to instantiate the view, only made a statement and direct the setContentView (view) as a result, carefully check whether the view the setContentView (view) and in the way before the call to instantiate can solve
Five: because the null pointer error exception, so you should check the Spinner or a list of such things inside value does exist
CodePudding user response:
You also post the error codeCodePudding user response:
Null pointer, post codeCodePudding user response:
What experience! I took several days, is a third reason: three reasons: in the onCreate () method, and the body does not belong to any one method directly to a control findById (R.i d.x x) as a result, needs in a certain way and in the setContentView (view) method before findById (R.i d.x x) can be solved, but I was in the setContentView (view) method of the "after" is solved, my android is the studio 4.1.3, plugin4.1.2, gradle6.5, so, as long as the setContentView (view) method and findById (R.i d.x x) with OnCraete (),