Home » Android » i am getting this type of error while running the program of recycle view in android-Exceptionshub

i am getting this type of error while running the program of recycle view in android-Exceptionshub

Posted by: admin February 26, 2020 Leave a comment

Questions:
  E/AndroidRuntime: FATAL EXCEPTION: main
     Process: com.example.spammessagedetector, PID: 2137
     java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.spammessagedetector/com.example.spammessagedetector.Inbox}:
 java.lang.NullPointerException: Attempt to invoke virtual method 'void
 androidx.swiperefreshlayout.widget.SwipeRefreshLayout.setOnRefreshListener(androidx.swiperefreshlayout.widget.SwipeRefreshLayout$OnRefreshListener)'
 on a null object reference
         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
         at android.app.ActivityThread.-wrap12(ActivityThread.java)
         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
         at android.os.Handler.dispatchMessage(Handler.java:102)
         at android.os.Looper.loop(Looper.java:154)
         at android.app.ActivityThread.main(ActivityThread.java:6077)
         at java.lang.reflect.Method.invoke(Native Method)
         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
      Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void
 androidx.swiperefreshlayout.widget.SwipeRefreshLayout.setOnRefreshListener(androidx.swiperefreshlayout.widget.SwipeRefreshLayout$OnRefreshListener)'
 on a null object reference
         at com.example.spammessagedetector.Inbox.onCreate(Inbox.java:76)
         at android.app.Activity.performCreate(Activity.java:6662)
         at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
   at android.app.ActivityThread.-wrap12(ActivityThread.java) 
         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460) 
         at android.os.Handler.dispatchMessage(Handler.java:102) 
         at android.os.Looper.loop(Looper.java:154) 
         at android.app.ActivityThread.main(ActivityThread.java:6077) 
         at java.lang.reflect.Method.invoke(Native Method) 
         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)

here is the code for Inbox.java

activity_inbox.xml

AndroidManifest.xml

How to&Answers:

error at this line.Your referenced id not found on current layout.

why call same method multiple time in your activity.may be here miss lead your swipe_refresh_layout id.

Answer:

by adding internet permission and removing setContentView(R.layout.activity_main); the code gets executed successfully.