I have an application on android and in it I need to display the date and time in two separate textview. To solve the problem I used the answers and information from my previous question Get the current time and date android . I did everything as advised to me, but I still got an error and the activation could not be created. Here is the error I received:

07-10 07:40:16.172 11481-11481/com.example.andrew.diplom E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.andrew.diplom, PID: 11481 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.andrew.diplom/com.example.andrew.diplom.Results}: 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:2509) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2569) at android.app.ActivityThread.access$900(ActivityThread.java:150) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1399) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:168) at android.app.ActivityThread.main(ActivityThread.java:5885) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687) 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.example.andrew.diplom.Results.onCreate(Results.java:36) at android.app.Activity.performCreate(Activity.java:6262) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1125) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2462) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2569) at android.app.ActivityThread.access$900(ActivityThread.java:150) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1399) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:168) at android.app.ActivityThread.main(ActivityThread.java:5885) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687) 

I am a novice application developer, and maybe I incorrectly decode this error, but as far as I can see the problem is that I pass an empty null value to the textview and I see from the code what the value should be. If someone faced a similar error or knows what the reason for me is, I will be grateful for the help.

  • one
    The problem is that you have not initialized TextView itself. See for yourself or show the code where you ( un ) do it - Jarvis_J
  • you do not pass a "null value" in the widget. Your widget is "empty value". Either the link is not obtained by the method findViewById() , or the wrong widget ID is specified in this method - these are the main reasons. If you cannot solve this issue on your own, then you need to attach a code and markup on which the widget is present. - pavlofff
  • one
    Yes, I understood soon I will edit the answer and attach my problem code. - Andrew Goroshko

0