我的应用程序在我在Android Studio中运行后,在已经运行的情况下进行更改时崩溃了

时间:2016-06-16 17:27:11

标签: java android nullpointerexception buzztouch

我正在使用Android Studio中的某个应用程序,由于某种原因,该应用程序不断抛出错误"不幸的是,MyApp已停止"。只有当我运行应用程序,在代码运行时对其进行更改,然后尝试再次运行它时,才会发生这种情况。如果我停止"运行"任务并重新开始,我没有收到此错误。

这是日志:

06-14 15:54:06.213 25752-25752/com.myapp E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.myapp, PID: 25752
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myapp/com.myapp.activity_host}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.myapp.MB_item.getItemId()' on a null object reference
  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
  at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4077)
  at android.app.ActivityThread.-wrap15(ActivityThread.java)
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1350)
  at android.os.Handler.dispatchMessage(Handler.java:102)
  at android.os.Looper.loop(Looper.java:148)
  at android.app.ActivityThread.main(ActivityThread.java:5417)
  at java.lang.reflect.Method.invoke(Native Method)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.myapp.MB_item.getItemId()' on a null object reference
  at com.myapp.BT_screen_menuButtons$override.onCreateView(MB_screen_menuButtons.java:119)
  at com.myapp.BT_screen_menuButtons$override.access$dispatch(MB_screen_menuButtons.java)
  at com.myapp.BT_screen_menuButtons.onCreateView(MB_screen_menuButtons.java:0)
  at android.app.Fragment.performCreateView(Fragment.java:2220)
  at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:973)
  at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1148)
  at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1130)
  at android.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1953)
  at android.app.FragmentController.dispatchActivityCreated(FragmentController.java:152)
  at android.app.Activity.performCreateCommon(Activity.java:6232)
  at android.app.Activity.performCreate(Activity.java:6239)
  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
  at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4077) 
  at android.app.ActivityThread.-wrap15(ActivityThread.java) 
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1350) 
  at android.os.Handler.dispatchMessage(Handler.java:102) 
  at android.os.Looper.loop(Looper.java:148) 
  at android.app.ActivityThread.main(ActivityThread.java:5417) 
  at java.lang.reflect.Method.invoke(Native Method) 
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

为什么代码在后续启动时的行为不同 ,而不是在我最初运行应用程序时?

附加代码:

这是抛出错误的行(MB_screen_menuButtons.java的119行)。 screenData.getItemId()显然是传递null值的地方,但我不明白为什么在Instant Run更新期间它只会为null。

debugger.showIt(fragmentName + ":onCreateView JSON itemId: \"" + screenData.getItemId() + "\" itemType: \"" + screenData.getItemType() + "\" itemNickname: \"" + screenData.getItemNickname() + "\"");

1 个答案:

答案 0 :(得分:3)

这似乎是Instant Run与代码中的某些内容不兼容的问题 - 可能是生成代码的库。

您可以停用即时运行,它应解决此问题:

  

偏好设置>构建,执行,部署>即时运行>取消选中"启用即时运行"

如果您想保持即时运行,您只需取消选中"重新启动代码更改活动"

  

偏好设置>构建,执行,部署>即时运行>取消选中"重新启动代码更改活动"