如何在选项卡中使用WebView并调用“(LocalActivityManager activityGroup)”?

问题描述 投票:1回答:4

我想使用三个标签来利用我的三个Web视图显示特定域。一切都可以找到,但是当我尝试启动该应用程序时,它会在我运行它和调试它时强制关闭-它通过布局和视图保持打开状态(调试时基本上不执行任何操作。)

logcat说

无法启动活动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;

}

}

WebView代码

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:线程退出 未捕获的异常(组= 0x4160e930) 05-23 01:23:06.910:E / AndroidRuntime(14673):FATAL EXCEPTION: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)'? 05-23 01:23:06.910:E / AndroidRuntime(14673):位于android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2307) 05-23 01:23:06.910:E / AndroidRuntime(14673):位于android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2357) 05-23 01:23:06.910:E / AndroidRuntime(14673):在android.app.ActivityThread.access $ 600(ActivityThread.java:153) 05-23 01:23:06.910:E / AndroidRuntime(14673):位于android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1247) 05-23 01:23:06.910:E / AndroidRuntime(14673):位于android.os.Handler.dispatchMessage(Handler.java:99) 05-23 01:23:06.910:E / AndroidRuntime(14673):位于android.os.Looper.loop(Looper.java:137) 05-23 01:23:06.910:E / AndroidRuntime(14673):位于android.app.ActivityThread.main(ActivityThread.java:5226) 05-23 01:23:06.910:E / AndroidRuntime(14673):at java.lang.reflect.Method.invokeNative(本机方法) 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 设置(LocalActivityManager activityGroup)'? 05-23 01:23:06.910:E / AndroidRuntime(14673):位于android.widget.TabHost $ IntentContentStrategy.getContentView(TabHost.java:747) 05-23 01:23:06.910:E / AndroidRuntime(14673):位于android.widget.TabHost.setCurrentTab(TabHost.java:413) 05-23 01:23:06.910:E / AndroidRuntime(14673):位于android.widget.TabHost.addTab(TabHost.java:240) 05-23 01:23:06.910:E / AndroidRuntime(14673):位于com.company.client.MainActivity.onCreate(MainActivity.java:28) 05-23 01:23:06.910:E / AndroidRuntime(14673):位于android.app.Activity.performCreate(Activity.java:5104) 05-23 01:23:06.910:E / AndroidRuntime(14673):位于android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080) 05-23 01:23:06.910:E / AndroidRuntime(14673):位于android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2261) 05-23 01:23:06.910:E / AndroidRuntime(14673):...还有11个]]

所以,如何使我的WebViewActivities在选项卡中处于活动状态,并执行logcat告诉我的操作?

我想使用三个标签来利用我的三个Web视图显示特定域。一切都可以找到,但是当我尝试启动该应用程序时,它会在我运行它以及调试时强制关闭...

android android-activity android-webview android-tabhost android-logcat
4个回答
0
投票

我注意到的第一个错误是,您试图在添加Tab后设置内容:


0
投票

Tab-Activity背后的基本概念如下


0
投票

LogCat告诉您您已正确初始化Tabhost。您应该使用“ void setup(LocalActivityManager activityGroup)”。


0
投票

我认为您只需要做的是

© www.soinside.com 2019 - 2024. All rights reserved.