【发布时间】:2014-07-17 05:10:49
【问题描述】:
我有一个线程调用 Soap 网络服务,我在其中登录用户,然后显示祝酒词“欢迎”+ 用户名 ...但现在在该 UI 线程中,我还希望页面从登录名导航屏幕显示到主登录页面,但我在执行此操作时收到错误消息。下面是代码和错误。
线程代码
Thread thread = new Thread(new Runnable(){
@Override
public void run() {
try {
String Response = "";
HT.call(Soap_action_Temp,envelope);
SoapPrimitive resultString = (SoapPrimitive) envelope.getResponse();
Settings.setUserLoginResult(resultString.getValue().toString());
Response = Settings.getUserLoginResult().toString();
if (Response != "")
{
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(LoginScreen.this,"Welcome " + username + " !",Toast.LENGTH_LONG).show();
Intent i = new Intent(LoginScreen.this,LandingPage.class);
startActivity(i);
}
});
}
} catch (Exception e) {
e.printStackTrace();
}
}
});
thread.start();
问题
下图显示活动为空?这有什么理由吗?
Logcat 没有向我显示任何异常,但我的应用程序崩溃并显示“应用程序名称已停止工作”
任何人都可以帮助我们解决为什么会失败吗?还是我的代码错了?
编辑
应用程序甚至没有触发我放入的 catch 事件。
这是点击登录后应用程序崩溃后的logcat条目
07-17 07:52:33.145 10329-10329/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.Ellipsys.embizomobile/com.example.Ellipsys.embizomobile.LandingPage}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2295)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2349)
at android.app.ActivityThread.access$700(ActivityThread.java:159)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5419)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:108)
at android.support.v7.app.ActionBarActivityDelegateICS.onCreate(ActionBarActivityDelegateICS.java:57)
at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:98)
at com.example.Ellipsys.embizomobile.LandingPage.onCreate(LandingPage.java:13)
at android.app.Activity.performCreate(Activity.java:5372)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2257)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2349)
at android.app.ActivityThread.access$700(ActivityThread.java:159)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5419)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
at dalvik.system.NativeStart.main(Native Method)
【问题讨论】:
-
你不需要放两个
runOnUiThreads。您可以将startActivity..部分移动到第一个部分。其次,如果应用程序崩溃了,一定是 logcat 说了什么。 -
不要将 TOAST 通知放在后台进程中
-
@Prag's 它不在后台进程上,它在 UI 线程上,因为 Soap 调用在后台线程中,我必须创建一个 UI 线程来在屏幕上显示 Toast
-
尝试删除它并运行你的进程
-
您的 ddms 是否启用了所有级别的日志记录?您可以在其中选择所需的日志记录级别。
标签: android multithreading android-activity