我想使用三个选项卡来利用我的三个 web 视图来显示特定域。一切都建立起来,但是当我尝试启动应用程序时,它会在我运行它时强制关闭,如果我调试它——它会在布局和视图中保持打开状态(调试时它基本上什么都不做。)
日志猫 说
无法启动活动 ComponentInfo{com.company.client/com.company.client.MainActivity}:java.lang.IllegalStateException:您是否忘记调用“public void setup(LocalActivityManager activityGroup)”?**
我怎么称呼它?
这是我的代码:
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
public class MainActivity extends Activity {
TabHost th;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
th = (TabHost) findViewById(R.id.tabhost);
th.setup();
TabSpec firstSpec=th.newTabSpec("Classes & Events");
firstSpec.setIndicator("Classes & Events", null);
Intent firstIntent= new Intent(this, WebViewActivity.class);
firstIntent.putExtra("backswipe", false);
firstSpec.setContent(firstIntent);
th.addTab(firstSpec);
TabSpec secondSpec=th.newTabSpec("Twitter");
secondSpec.setIndicator("Twitter", null);
Intent secondIntent= new Intent(this, WebViewActivity2.class);
secondSpec.setContent(secondIntent);
th.addTab(secondSpec);
TabSpec thirdSpec=th.newTabSpec("Facebook");
thirdSpec.setIndicator("Facebook", null);
Intent thirdIntent= new Intent(this, WebViewActivity3.class);
thirdSpec.setContent(thirdIntent);
th.addTab(thirdSpec);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
Web 视图代码
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.webkit.WebView;
public class WebViewActivity extends Activity {
public WebView webView_A;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
webView_A = (WebView) findViewById(R.id.tab1);
webView_A.getSettings().setJavaScriptEnabled(true);
webView_A.loadUrl("http://www.eventbrite.com");
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.web_view, menu);
return true;
}
}
XML 主要布局
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFB84D" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="-3dip"
android:layout_weight="0" >
</TabWidget>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" >
</FrameLayout>
</LinearLayout>
</TabHost>
这是logcat。
05-23 01:23:06.886: W/dalvikvm(14673): threadid=1: 线程退出未捕获异常 (group=0x4160e930) 05-23 01:23:06.910: E/AndroidRuntime(14673):致命异常: main 05-23 01:23:06.910: E/AndroidRuntime(14673): java.lang.RuntimeException: 无法启动活动 ComponentInfo{com.company.client/com.company.client.MainActivity}: java.lang.IllegalStateException: 没有你忘记调用'public void setup(LocalActivityManager activityGroup)'? E/AndroidRuntime(14673): at java.lang.reflect.Method.invokeNative(Native Method) 05-23 01:23:06.910: E/AndroidRuntime(14673): at java.lang.reflect.Method.invoke(Method. java:511) 05-23 01:23:06.910: E/AndroidRuntime(14673): 在 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795) 05-23 01:23:06.910: E/AndroidRuntime(14673): 在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562) 05-23 01:23:06.910: E/AndroidRuntime(14673): 在 dalvik.system.NativeStart.main (本机方法)05-23 01:23:06.910:E/AndroidRuntime(14673):原因:java.lang.IllegalStateException:您是否忘记调用“public void setup(LocalActivityManager activityGroup)”?05-23 01:23:06.910: E/AndroidRuntime(14673): 在 android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:
那么,如何在选项卡中激活我的 WebViewActivities 并按照 logcat 告诉我的操作?