Today, I met a simple error message prompt, which is recorded as follows for future search:
Error message 1:
2020-02-02 13:27:48.472 20534-20534/com.example.helloworld1 E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.helloworld1, PID: 20534 android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.helloworld1/com.example.helloworld1.gridview.GridViewActivity}; have you declared this activity in your AndroidManifest.xml? at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1827) at android.app.Instrumentation.execStartActivity(Instrumentation.java:1531) at android.app.Activity.startActivityForResult(Activity.java:4405) at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:767) at android.app.Activity.startActivityForResult(Activity.java:4363) at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:754) at android.app.Activity.startActivity(Activity.java:4702) at android.app.Activity.startActivity(Activity.java:4670) at com.example.helloworld1.MainActivity$Onclick.onClick(MainActivity.java:108) at android.view.View.performClick(View.java:5642) at android.view.View$PerformClick.run(View.java:22485) at android.os.Handler.handleCallback(Handler.java:751) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6211) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:793)
In this error message, * * * have you declared this activity in your AndroidManifest.xml? * * * clearly indicates that "no relevant activity is declared in the AndroidManifest.xml file"
Amend to read:
Add relevant activities to the Android manifest.xml file
<activity android:name=".gridview.GridViewActivity"></activity>
Error message 2:
2020-02-02 16:14:15.819 16410-16410/com.example.helloworld1 E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.helloworld1, PID: 16410 java.lang.NullPointerException: Argument must not be null at com.bumptech.glide.util.Preconditions.checkNotNull(Preconditions.java:31) at com.bumptech.glide.util.Preconditions.checkNotNull(Preconditions.java:25) at com.bumptech.glide.RequestBuilder.into(RequestBuilder.java:651) at com.example.helloworld1.gridview.MyGridViewAdapter.getView(MyGridViewAdapter.java:68) at android.widget.AbsListView.obtainView(AbsListView.java:2486) at android.widget.GridView.onMeasure(GridView.java:1065) at android.view.View.measure(View.java:19913) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6247) at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464) at android.widget.LinearLayout.measureVertical(LinearLayout.java:758) at android.widget.LinearLayout.onMeasure(LinearLayout.java:640) at android.view.View.measure(View.java:19913) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6247) at android.widget.FrameLayout.onMeasure(FrameLayout.java:185) at androidx.appcompat.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:143) at android.view.View.measure(View.java:19913) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6247) at androidx.appcompat.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:401) at android.view.View.measure(View.java:19913) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6247) at android.widget.FrameLayout.onMeasure(FrameLayout.java:185) at android.view.View.measure(View.java:19913) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6247) at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464) at android.widget.LinearLayout.measureVertical(LinearLayout.java:758) at android.widget.LinearLayout.onMeasure(LinearLayout.java:640) at android.view.View.measure(View.java:19913) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6247) at android.widget.FrameLayout.onMeasure(FrameLayout.java:185) at com.android.internal.policy.DecorView.onMeasure(DecorView.java:759) at android.view.View.measure(View.java:19913) at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2279) at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1370) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1623) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1258) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6468) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:908) at android.view.Choreographer.doCallbacks(Choreographer.java:720) at android.view.Choreographer.doFrame(Choreographer.java:655) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:894) at android.os.Handler.handleCallback(Handler.java:751) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6211) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:793) 2020-02-02 16:14:15.849 16410-16410/? I/Process: Sending signal. PID: 16410 SIG: 9
Every time you enter the current page, the program crashes and the interface flashes back,
When the network pictures are commented out, it will run successfully.
After various attempts, it is found that the problem is very simple. The associated id of the current page imageView is wrong
//Error id: holder.imageView = (ImageView) convertView.findViewById(R.id.iv_item); //Correct id: holder.imageView = (ImageView) convertView.findViewById(R.id.iv_grid);
Summary:
Different layout file id names in Android Studio can be used repeatedly, but the id in each layout file cannot be repeated, and the related control id in the corresponding layout file must be taken in the Activity.java file, otherwise the program may crash, flash back and other errors may result.