在我的 android 应用程序中检查服务是否运行,如果运行我想更改 UI 颜色。我使用以下代码
if(true==util.isMyServiceRunning(getApplicationContext())){
makeUIChangesforTurnOn(true);
}
但它显示错误..
09-09 00:53:26.810: E/AndroidRuntime(1106): FATAL EXCEPTION: main 09-09 00:53:26.810:
E/AndroidRuntime(1106): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.param.calltracker/com.param.calltracker.MainActivity}:java.lang.NullPointerException
09-09 00:53:26.810: E/AndroidRuntime(1106): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
09-09 00:53:26.810: E/AndroidRuntime(1106): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
09-09 00:53:26.810: E/AndroidRuntime(1106): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
09-09 00:53:26.810: E/AndroidRuntime(1106): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
09-09 00:53:26.810: E/AndroidRuntime(1106): at android.os.Handler.dispatchMessage(Handler.java:99)
09-09 00:53:26.810: E/AndroidRuntime(1106): at android.os.Looper.loop(Looper.java:130)
09-09 00:53:26.810: E/AndroidRuntime(1106): at android.app.ActivityThread.main(ActivityThread.java:3687)
09-09 00:53:26.810: E/AndroidRuntime(1106): at java.lang.reflect.Method.invokeNative(Native Method)
09-09 00:53:26.810: E/AndroidRuntime(1106): at java.lang.reflect.Method.invoke(Method.java:507)
09-09 00:53:26.810: E/AndroidRuntime(1106): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
09-09 00:53:26.810: E/AndroidRuntime(1106): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
09-09 00:53:26.810: E/AndroidRuntime(1106): at dalvik.system.NativeStart.main(Native Method)
09-09 00:53:26.810: E/AndroidRuntime(1106): Caused by: java.lang.NullPointerException
09-09 00:53:26.810: E/AndroidRuntime(1106): at com.param.calltracker.MainActivity.makeUIChangesforTurnOn(MainActivity.java:214)
09-09 00:53:26.810: E/AndroidRuntime(1106): at com.param.calltracker.MainActivity.onCreate(MainActivity.java:79)
09-09 00:53:26.810: E/AndroidRuntime(1106): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-09 00:53:26.810: E/AndroidRuntime(1106): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
我的 UI 更改代码>
public void makeUIChangesforTurnOn(Boolean on){
if(on){
trun_on_off_img.setImageResource(R.drawable.green_signal);
buttonToggleDetect.setBackgroundResource(R.drawable.orenge_button);
buttonToggleDetect.setText("Turn off");
textViewDetectState.setText("Monitoring Calls");
textViewDetectState.setTextColor(getResources().getColor(R.color.green));
}else{
trun_on_off_img.setImageResource(R.drawable.yellow_signal);
buttonToggleDetect.setBackgroundResource(R.drawable.green_button);
buttonToggleDetect.setText("Turn on");
textViewDetectState.setText("Not Monitoring Calls");
textViewDetectState.setTextColor(getResources().getColor(R.color.orenge));
}
}
任何人帮助我...