我刚刚在Play商店更新了我的应用程序,我开始收到人们的崩溃报告,一个是我认识的人,所以他开始帮助我解决这个问题,我发现问题是由我什至没有的东西引起的调整。
代码如下所示 导致问题的部分是bulb.onClickListener
public class Bulb extends Activity {
public boolean isAwake = false;
boolean timerActivated = false;
static ImageView glow;
public static boolean bulbActIsRunning = false;
public void startWake() {
Intent wS=new Intent(getBaseContext(), WakeService.class);
startService(wS);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageButton bulb = (ImageButton) findViewById(R.id.bulb);
ImageButton ghl = (ImageButton) findViewById(R.id.ghl);
glow = (ImageView) findViewById(R.id.glow);
if (WakeService.isAwake) {
glow.setVisibility(View.VISIBLE);
}
else {
glow.setVisibility(View.INVISIBLE);
}
bulb.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startWake();
if (WakeService.isAwake) {
glow.setVisibility(View.INVISIBLE);
}
else {
glow.setVisibility(View.VISIBLE);
}
}
});
ghl.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.geekshavelanded.com/"));
startActivity(browserIntent);
}
});
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
glow = (ImageView) findViewById(R.id.glow);
if (WakeService.isAwake) {
glow.setVisibility(View.VISIBLE);
}
else {
glow.setVisibility(View.INVISIBLE);
}
}
@Override
public void onStart() {
super.onStart();
bulbActIsRunning = true;
}
@Override
public void onStop() {
super.onStop();
bulbActIsRunning = false;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
在我的朋友单击灯泡按钮后,应用程序无故崩溃,我在 onClickListener 的开头放置了一些 toast 通知,以查看它是否在崩溃前出现,但没有
崩溃报告如下所示
java.lang.RuntimeException: Unable to start service com.doublep.wakey.WakeService@41740bb8 with Intent { cmp=com.doublep.wakey/.WakeService }: java.lang.NullPointerException
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2933)
at android.app.ActivityThread.access$1900(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1438)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:155)
at android.app.ActivityThread.main(ActivityThread.java:5454)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1029)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:796)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at android.os.Parcel.readException(Parcel.java:1436)
at android.os.Parcel.readException(Parcel.java:1384)
at com.android.internal.appwidget.IAppWidgetService$Stub$Proxy.updateAppWidgetIds(IAppWidgetService.java:513)
at android.appwidget.AppWidgetManager.updateAppWidget(AppWidgetManager.java:333)
at android.appwidget.AppWidgetManager.updateAppWidget(AppWidgetManager.java:400)
at com.doublep.wakey.WakeService.keepAwake(WakeService.java:86)
at com.doublep.wakey.WakeService.onStartCommand(WakeService.java:48)
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2912)
... 10 more
任何人都可以看到可疑的东西吗?当我更新我的应用程序时,我什至没有触及这个活动的代码,其他一切都很好,因为我也可以从小部件调用服务。所以问题一定出在这里
我还将 min SDK 从 8 修改为 7(但为了查看它是否有效,我将其恢复为 8)并且我压缩了一些图形以节省空间
编辑哦,我忘了说,这仅发生在少数设备上,在大多数设备上似乎工作正常
更新 2这是导致这些问题的一段代码
AppWidgetManager mgr=AppWidgetManager.getInstance(this);
mgr.updateAppWidget(ToggleWidget.appWidgetId, ToggleWidget.remoteViews);