-1

I am new to Android programming and I try to learn it and take sample sample applications on the git * ub site, I have tried to resolve some errors in the application and after compiling the application is able to run, but the problem that arises when I open the details from the application post, the error is like this

    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.app.newsagni/com.app.newsagni.ActivityPostDetails}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2490)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2550)
    at android.app.ActivityThread.access$1100(ActivityThread.java:154)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1401)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:157)
    at android.app.ActivityThread.main(ActivityThread.java:5615)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:774)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:652)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
    at com.app.newsagni.ActivityPostDetails.displayPostData(ActivityPostDetails.java:190)
    at com.app.newsagni.ActivityPostDetails.onCreate(ActivityPostDetails.java:98)
    at android.app.Activity.performCreate(Activity.java:6362)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2443)
    ... 9 more

The following listings from

ActivityPostDetails.java https://pastebin.com/h56LUx2T

activity_post_details.xml https://pastebin.com/hwYpza37

Can you help me overcome this error

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Debot
  • 1
  • 1
  • You probably will need a `try-catch` to check if values (for `TextView`s) isn't empty then, set `TextView` values. Here, error comes from one of those values which is empty. – ʍѳђઽ૯ท Aug 04 '18 at 05:45

1 Answers1

0

You don't have a TextView with an id of "date", so Android cannot find the TextView. Therefore you get a NPE when trying to work with it. Add the TextView to your activity and you should be good to go.

Toby Caulk
  • 103
  • 8