当我收到一条短信(在两个模拟器上测试)时,我想增加进度条的进度,但我收到了一个错误 - 意外地,强制关闭。
这是我在活动 A 中的代码:
progressBar = (ProgressBar)findViewById(R.id.progresslevel);
new Thread(new Runnable() {
public void run() {
// TODO Auto-generated method stub
while (progressStatus < 50000) {
mHandler.post(new Runnable() {
public void run() {
// TODO Auto-generated method stub
progressBar.setProgress(progressStatus);
}
});
}
}).start();
Activity A中的增加方法:
public static void increaseValue(Boolean isSMS) {
if (isSMS == true) {
progressStatus += 5000;
} else {
progressStatus += 7000;
}
}
我的活动短信接收器:
public class SMSReceive extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
FloCareActivity.increaseValue(true);
}
}
如何解决?
来自日志猫的错误:
06-28 11:24:33.733: W/dalvikvm(915): threadid=3: thread exiting with uncaught exception (group=0x4001aa28)
06-28 11:24:33.733: E/AndroidRuntime(915): Uncaught handler: thread main exiting due to uncaught exception
06-28 11:24:33.763: E/AndroidRuntime(915): java.lang.RuntimeException: Unable to instantiate receiver nth.flocare.demo.SMSReceiver: java.lang.ClassNotFoundException: nth.flocare.demo.SMSReceiver in loader dalvik.system.PathClassLoader@43757c18
06-28 11:24:33.763: E/AndroidRuntime(915): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2520)
06-28 11:24:33.763: E/AndroidRuntime(915): at android.app.ActivityThread.access$3000(ActivityThread.java:116)
06-28 11:24:33.763: E/AndroidRuntime(915): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1843)
06-28 11:24:33.763: E/AndroidRuntime(915): at android.os.Handler.dispatchMessage(Handler.java:99)
06-28 11:24:33.763: E/AndroidRuntime(915): at android.os.Looper.loop(Looper.java:123)
06-28 11:24:33.763: E/AndroidRuntime(915): at android.app.ActivityThread.main(ActivityThread.java:4203)
06-28 11:24:33.763: E/AndroidRuntime(915): at java.lang.reflect.Method.invokeNative(Native Method)
06-28 11:24:33.763: E/AndroidRuntime(915): at java.lang.reflect.Method.invoke(Method.java:521)
06-28 11:24:33.763: E/AndroidRuntime(915): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
06-28 11:24:33.763: E/AndroidRuntime(915): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
06-28 11:24:33.763: E/AndroidRuntime(915): at dalvik.system.NativeStart.main(Native Method)
06-28 11:24:33.763: E/AndroidRuntime(915): Caused by: java.lang.ClassNotFoundException: nth.flocare.demo.SMSReceiver in loader dalvik.system.PathClassLoader@43757c18
06-28 11:24:33.763: E/AndroidRuntime(915): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
06-28 11:24:33.763: E/AndroidRuntime(915): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
06-28 11:24:33.763: E/AndroidRuntime(915): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
06-28 11:24:33.763: E/AndroidRuntime(915): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2513)
06-28 11:24:33.763: E/AndroidRuntime(915): ... 10 more
06-28 11:24:33.813: I/dalvikvm(915): threadid=7: reacting to signal 3
06-28 11:24:33.895: I/dalvikvm(915): Wrote stack trace to '/data/anr/traces.txt'
06-28 11:29:33.833: I/Process(915): Sending signal. PID: 915 SIG: 9