Android—-java.lang.NullPointerException:—java.lang.NullPointerException:

2021-03-06 13:26:12.274 8544-8544/com.example.helloworld E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.helloworld,PID: 8544 java.lang.NullPointerException:: Unable to start activity ComponentInfo{com.example.helloworld/com.example.helloworld.MainActivity} : java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget. Check@R_ 748_ 2419@.setOnCheckedchangelistener (android.widget.CompoundButton$OnCheckedchangelistener)' on a null object reference at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3897) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4076) at android.app.servertransaction.LaunchActivityItem.execute (LaunchActivityItem.java:91) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:103) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2473) at android.os.Handler.dispatchMessage(Handler.java:110) at android.os.Looper.loop(Looper.java:219) at android.app.ActivityThread.main(ActivityThread.java:8349) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1055) Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget. Check@R_748_2419 @.setOnCheckedchangelistener(android.widget.CompoundButton$OnCheckedchangelistener)' on a null object reference at com.example.helloworld.MainActivity.setListener(MainActivity.java:161) at com.example.helloworld.MainActivity.onCreate (MainActivity.java:138) at android.app.Activity.performCreate(Activity.java:8085) at android.app.Activity.performCreate(Activity.java:8073) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1320) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3870) at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:4076) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:91) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:103) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2473) at android.os.Handler.dispatchMessage(Handler.java:110) at android.os.Looper.loop(Looper.java:219) at android.app.ActivityThread.main(ActivityThread.java:8349) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:513) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1055) 2021-03-06 13:26:12.282 8544-8544/com.example.helloworld I/Process: Sending signal. PID: 8544 SIG: 9

Check the XML file definition check@R_ 748_ Is the ID of 2419 @ consistent with the ID obtained in the activity

The problem is that the corresponding is not found at runtime check@R_ 748_ 2419@

Process: com.example.helloworld,PID: 21319 java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.helloworld/com.example.helloworld.MoreActivity} : java.lang.illegalaccessexception: java.lang.Class<com.example.helloworld.MoreActivity> is not accessible from java.lang.Class<android.app.AppComponentFactory> at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3815) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4076) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:91) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:103) at android.app.ActivityThread$H.handleMessage (ActivityThread.java:2473) at android.os.Handler.dispatchMessage(Handler.java:110) at android.os.Looper.loop(Looper.java:219) at android.app.ActivityThread.main(ActivityThread.java:8349) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1055) Caused by: java.lang.illegalaccessexception: java.lang.Class<com.example.helloworld.MoreActivity> is not accessible from java.lang.Class<android.app.AppComponentFactory> at java.lang.Class.newInstance(Native Method) at android.app.AppComponentFactory.instantiateActivity (AppComponentFactory.java:95) at androidx.core.app.CoreComponentFactory.instantiateActivity(CoreComponentFactory.java:41) at android.app.Instrumentation.newActivity(Instrumentation.java:1264) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3800) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4076) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:91) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:103) at android.app.ActivityThread$H.handleMessage (ActivityThread.java:2473) at android.os.Handler.dispatchMessage(Handler.java:110) at android.os.Looper.loop(Looper.java:219) at android.app.ActivityThread.main(ActivityThread.java:8349) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1055)

This is because the activity is not registered in the manifest file

All activity classes must be public, or the manifest file cannot be found, so it cannot be run

java.lang.NullPointerException: Attempt to invoke virtual method 'android.text.Editable android.widget.EditText.getText()' on a null object reference;

This is the same as problem 1, because the corresponding ID cannot be found

Blogger link: https://blog.csdn.net/qq_ 42618969/article/details/81141895

Android: ID specifies the corresponding ID for the control. Android: text specifies the text of the control. Try to use strings.xml. Android: grivity specifies the basic position of the control, such as weight lifting, right. Android: padding specifies the inner margin of the control and the content in the control. Android: singleline if it is set to true, the content of the control will be displayed in the same line

android:layout_ Above places the bottom of the space above the space with a given ID. Android: Layout_ Below: place the top of the control under the control with the given ID Android: Layout_ Toleftof: align the right edge of the control with the left edge of the control with the given ID to its Android: layout_ Torightof aligns the left edge of the control with the right edge of the control with the given ID

android:layout_ Alignbaselinealign the baseline of the control with the baseline of the control with the given ID. Android: Layout_ Alignbottom aligns the bottom edge of the control with the bottom edge of the control with the given ID Android: layout_ Alignleft aligns the left edge of the control with the left edge of the control with the given ID. Android: Layout_ Alignright aligns the right edge of the control with the right edge of the control with the given ID. Android: Layout_ Aligntop aligns the top edge of the given control with the top of the given ID control

Android: alignparentbottom if the value is true, align the bottom of the control with the bottom of the parent control Android: Layout_ Alignparentleft if the value is true, align the left side of the control with the left side of the parent control Android: Layout_ Alignparentright if the value is true, align the right side of the control with the right side of the parent control Android: Layout_ Alignparenttop aligns the top of the control with the top of the parent control

android:layout_ If the value of centerhorizontal is true, the control will be placed in the center of the horizontal Android: layout_ Centerinparent will be centered horizontally and vertically on the parent control Android: Layout_ Centervertical will be centered vertically

android:layout_ Centerhorizontal center Android: Layout_ Centervertical center Android: Layout_ Centerinparent is completely centered relative to the parent element Android: Layout_ Align parentbottom is close to the lower edge of the parent element Android: layout_ Align parentleft is close to the left edge of the parent element Android: layout_ Align parentright is close to the right edge of the parent element Android: layout_ Align parenttop is close to the upper edge of the parent element Android: layout_ Alignwithparentifmissing if the corresponding sibling element cannot be found, the parent element will be used as a reference

android:layout_ Below Android: layout below an element_ Above above an element Android: Layout_ Toleftof is on the left of an element. Android: Layout_ Torightof is on the right of an element. Android: Layout_ Aligntop align the upper edge of this element with the upper edge of an element Android: Layout_ Alignleft align the left edge of this element with the left edge of an element Android: Layout_ Alignbottom align the lower edge of this element with the lower edge of an element Android: Layout_ Alignright the right edge of this element is aligned with the right edge of an element

android:layout_ The distance from the marginbottom to the bottom edge of the parent control Android: Layout_ Distance from marginleft to the left edge of the parent control Android: Layout_ Marginright distance from the right edge of the parent control Android: Layout_ The distance of margintop from the upper edge of the parent control

Android: hint of EditText sets the prompt in the input box when EditText is empty.

Android: gravity Android: gravity attribute is a restriction on the content of the view. For example, the text above a button. You can set the text to the left and right of the view. Take a button as an example, Android: gravity = "right" means the text above the button to the right

android:layout_ gravity android:layout_ Gravity is used to set the position of the view relative to the parent view. For example, if a button is in the LinearLayout, you can set it through this property if you want to place the button on the left, right, etc. take the button as an example,

android:layout_ Gravity = "right" button to the right

android:layout_ Alignparentright aligns the right end of the current control with the right end of the parent control. Here, the attribute value can only be true or false, and the default is false.

The difference between padding and margin: therefore, padding defines the distance between the content of the control and the edge of the control. Padding means filling filler, while margin means the distance beyond the four edges of the control, which means the distance between the control and other controls. Margin means edge and page blank

Original link: https://blog.csdn.net/qq_ 28296925/article/details/51115132

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>