在android中的选项卡中打开google地图不起作用
我正试图打开一个谷歌地图应用程序,我在一个标签上做了,但它不工作,当我运行它时,它会不断收到强制关闭消息。我创建了主活动文件[TabtestingActivity],该文件创建了选项卡[HellogogLeactivity类包含映射代码,没有选项卡也可以正常工作]在android中的选项卡中打开google地图不起作用,android,google-maps,tabs,Android,Google Maps,Tabs,我正试图打开一个谷歌地图应用程序,我在一个标签上做了,但它不工作,当我运行它时,它会不断收到强制关闭消息。我创建了主活动文件[TabtestingActivity],该文件创建了选项卡[HellogogLeactivity类包含映射代码,没有选项卡也可以正常工作] public class TabstestingActivity extends TabActivity { public void onCreate(Bundle savedInstanceState) { super.on
public class TabstestingActivity extends TabActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Resources res = getResources();
TabHost tabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Reusable TabSpec for each tab
Intent intent; // Reusable Intent for each tab
intent = new Intent().setClass(this, HelloGoogleActivity.class);
spec = tabHost.newTabSpec("tabOne");
spec.setContent(intent);
spec.setIndicator("Tab One",res.getDrawable(R.drawable.tabselect));
tabHost.addTab(spec);
tabHost.setCurrentTab(0);
}
}
如果我创建了一个只包含文本的类,它可以很好地处理选项卡,但是当我添加map类时,它就会停止工作。
这是我的main.xml:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@android:id/tabcontent
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.google.android.maps.MapView
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:apiKey="my key"
android:layout_weight="1"/>
</RelativeLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
痕迹很清楚,
"10-26 00:47:10.207: ERROR/AndroidRuntime(303): Caused by: java.lang.IllegalArgumentException: MapViews can only be created inside instances of MapActivity."
您不能在MapActivity
之外使用MapView。请将您在logcat中看到的异常与您的问题一起发布。注意,MapView上有多余的布局权重
"10-26 00:47:10.207: ERROR/AndroidRuntime(303): Caused by: java.lang.IllegalArgumentException: MapViews can only be created inside instances of MapActivity."