gpt4 book ai didi

android - 从 Activity A 调用方法到 Activity B 时出错

转载 作者:行者123 更新时间:2023-11-29 22:04:03 25 4
gpt4 key购买 nike

我想在收到短信时增加进度条的进度(在两个模拟器上测试),但出现错误 - 出乎意料,强制关闭。

这是我在 Activity 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;
}
}

我的 Activity SMReceiver:

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

最佳答案

这意味着你的 list 告诉 android 你有一个名为 nth.flocare.demo.SMSReceiver 的类,而 Android 找不到它。

你犯的错误是

您在代码中的类名为 SMSReceive,Android 正在尝试查找 nth.flocare.demo.SMSReceiver 因此,将您的类重命名为 SMSReceiver

关于android - 从 Activity A 调用方法到 Activity B 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11238089/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com