I had an app that was working as expected. I didn’t like the UI due to unknown behaviors of android so I decided to redesign the XML file. I created a new_layout.xml file, designed it as I wanted and then refactored > renamed the activity_main.xml file to activity_main_old.xml and refactored > renamed new_layout.xml to activity_main.xml.
The app crashed saying something about not being able to cast a Button to ImageButton, but the weird thing is that I only copy/pasted the elements from the one XML file to the other, so there should have been no issues since the names were the same.
As a result, I thought that maybe the names of each of the element were conflicting with the original layout (now activity_main_old.xml) and so I deleted this file out of the project. Then I refactored > renamed the activity_main.xml to something more meaningful (scoreboard.xml). I changed the setContentView() method to the next scoreboard layout id.
I don’t understand the error messages that I’m getting and would appreciate any help I can get please:
12-27 15:31:24.744: E/AndroidRuntime(4800): FATAL EXCEPTION: main
12-27 15:31:24.744: E/AndroidRuntime(4800): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.ultimatescoreclock/com.example.ultimatescoreclock.ScoreboardActivity}: java.lang.NullPointerException
12-27 15:31:24.744: E/AndroidRuntime(4800): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
12-27 15:31:24.744: E/AndroidRuntime(4800): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
12-27 15:31:24.744: E/AndroidRuntime(4800): at android.app.ActivityThread.access$600(ActivityThread.java:123)
12-27 15:31:24.744: E/AndroidRuntime(4800): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
12-27 15:31:24.744: E/AndroidRuntime(4800): at android.os.Handler.dispatchMessage(Handler.java:99)
12-27 15:31:24.744: E/AndroidRuntime(4800): at android.os.Looper.loop(Looper.java:137) 12-27 15:31:24.744: E/AndroidRuntime(4800): at android.app.ActivityThread.main(ActivityThread.java:4424)
12-27 15:31:24.744: E/AndroidRuntime(4800): at java.lang.reflect.Method.invokeNative(Native Method)
12-27 15:31:24.744: E/AndroidRuntime(4800): at java.lang.reflect.Method.invoke(Method.java:511) 12-27 15:31:24.744: E/AndroidRuntime(4800): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
12-27 15:31:24.744: E/AndroidRuntime(4800): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
12-27 15:31:24.744: E/AndroidRuntime(4800): at dalvik.system.NativeStart.main(Native Method) 12-27 15:31:24.744: E/AndroidRuntime(4800): Caused by: java.lang.NullPointerException
12-27 15:31:24.744: E/AndroidRuntime(4800): at com.example.ultimatescoreclock.ScoreboardActivity.onCreate(ScoreboardActivity.java:207)
12-27 15:31:24.744: E/AndroidRuntime(4800): at android.app.Activity.performCreate(Activity.java:4465)
12-27 15:31:24.744: E/AndroidRuntime(4800): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
12-27 15:31:24.744: E/AndroidRuntime(4800): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
12-27 15:31:24.744: E/AndroidRuntime(4800): ... 11 more
NullPointerExceptionat line 207 inScoreboardActivity.javaclass.There is no code in your question, so it is hard to tell what is going on but, the reason could be you are trying to do some call on
nullreference.