本文介绍了未捕获的处理程序:螺纹主力退出,由于未捕获的异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
磨我开始使用这种方法如下
whet i am starting new Activity using this way below
Intent edit = new Intent(getParent(), WebViewLink.class);
TabGroupActivity parentActivity = (TabGroupActivity) getParent();
edit.putExtra(POSITION, FAQ);
parentActivity.startChildActivity("WebViewLink", edit);
我收到错误这样
I am getting error like this
08-19 13:44:49.955: ERROR/AndroidRuntime(548): Uncaught handler: thread main exiting due to uncaught exception
08-19 13:44:49.974: ERROR/AndroidRuntime(548): android.view.WindowManager$BadTokenException: Unable to add window -- token android.app.LocalActivityManager$LocalActivityRecord@44dabdc8 is not valid; is your activity running?
08-19 13:44:49.974: ERROR/AndroidRuntime(548): at android.view.ViewRoot.setView(ViewRoot.java:468)
08-19 13:44:49.974: ERROR/AndroidRuntime(548): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
08-19 13:44:49.974: ERROR/AndroidRuntime(548): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
08-19 13:44:49.974: ERROR/AndroidRuntime(548): at android.view.Window$LocalWindowManager.addView(Window.java:424)
08-19 13:44:49.974: ERROR/AndroidRuntime(548): at android.app.Dialog.show(Dialog.java:239)
08-19 13:44:49.974: ERROR/AndroidRuntime(548): at com.stress.WebViewLink$2.onLoadResource(WebViewLink.java:73)
08-19 13:44:49.974: ERROR/AndroidRuntime(548): at android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:355)
08-19 13:44:49.974: ERROR/AndroidRuntime(548): at android.os.Handler.dispatchMessage(Handler.java:99)
08-19 13:44:49.974: ERROR/AndroidRuntime(548): at android.os.Looper.loop(Looper.java:123)
08-19 13:44:49.974: ERROR/AndroidRuntime(548): at android.app.ActivityThread.main(ActivityThread.java:4363)
08-19 13:44:49.974: ERROR/AndroidRuntime(548): at java.lang.reflect.Method.invokeNative(Native Method)
08-19 13:44:49.974: ERROR/AndroidRuntime(548): at java.lang.reflect.Method.invoke(Method.java:521)
08-19 13:44:49.974: ERROR/AndroidRuntime(548): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
08-19 13:44:49.974: ERROR/AndroidRuntime(548): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
08-19 13:44:49.974: ERROR/AndroidRuntime(548): at dalvik.system.NativeStart.main(Native Method)
但是当我使用这种方式调用新的活动是没有问题的。
but when I am using this way for call new Activity There is no problem
Intent edit = new Intent(getParent(), WebViewLink.class);
edit.putExtra(POSITION, FAQ);
More.this.startActivity(edit);
您可以在这里看到我的WebViewLink.java类
you can see My WebViewLink.java class here
public class WebViewLink extends Activity {
public static String POSITION = "position";
int position = 0;
private Button back;
private TextView ttl;
ProgressDialog myProgressDialog = null;
private WebView webView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.webview);
webView = (WebView) findViewById(R.id.webview);
back = (Button) findViewById(R.id.backtomore);
ttl = (TextView) findViewById(R.id.my_title);
webView.getSettings().setJavaScriptEnabled(true);
if (getIntent().getExtras() != null) {
if (getIntent().getExtras().containsKey(POSITION)) {
position = getIntent().getExtras().getInt(POSITION);
}
}
switch (position) {
case More.FAQ:
ttl.setText("FAQ");
setWebLink();
webView.loadUrl("file:///android_asset/faq4.htm");
break;
case More.ABOUT_US:
ttl.setText("About Us");
setWebLink();
webView.loadUrl("file:///android_asset/Advice/About Us.html");
break;
case More.DISCLAIMMER:
ttl.setText("Disclaimer");
setWebLink();
webView.loadUrl("file:///android_asset/Advice/Disclaimer.html");
break;
}
back.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
finish();
}
});
}
private void setWebLink() {
webView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
public void onLoadResource(WebView view, String url) {
if (myProgressDialog == null) {
myProgressDialog = new ProgressDialog(WebViewLink.this);
myProgressDialog.setMessage("Loading.... Please Wait");
myProgressDialog.show();
}
}
public void onPageFinished(WebView view, String url) {
if (myProgressDialog.isShowing()) {
myProgressDialog.dismiss();
}
}
});
}
}
推荐答案
现在的问题是在这行code:
The problem is in this line of code:
myProgressDialog = new ProgressDialog(WebViewLink.this);
当你是你 TabGroupActivity
然后子活动
(IES)需要父母的上下文
添加新窗口,对话框。试试这个方法:
when you are you TabGroupActivity
then child Activity
(ies) need parents' Context
to add new Windows, Dialogs. Try this way:
myProgressDialog = new ProgressDialog(WebViewLink.this.getParent());
和所有对话框
s是否相同。
这篇关于未捕获的处理程序:螺纹主力退出,由于未捕获的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!