2011-10-25 30 views
0

我想打開一個谷歌地圖應用程序,我在一個選項卡,但它沒有工作,它不斷收到強制關閉消息,當我運行它。我創建的主要活動文件[TabtestingActivity]它創建的標籤[HelloGoogleActivity類包含地圖代碼,不受標籤工作正常]在Android中的選項卡中打開谷歌地圖不工作

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); 
    } 
} 

如果我創建一個類只有一個文本它,它工作正常標籤,但是當我添加地圖類時,它停止工作。 這是我的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> 

有沒有問題,我的main.xml?

這是logcat的:

10-26 00:47:10.207: ERROR/AndroidRuntime(303): FATAL EXCEPTION: main 
10-26 00:47:10.207: ERROR/AndroidRuntime(303): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.tabtest/com.example.tabtest.TabstestingActivity}: android.view.InflateException: Binary XML file line #12: Error inflating class com.google.android.maps.MapView 
10-26 00:47:10.207: ERROR/AndroidRuntime(303):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663) 
10-26 00:47:10.207: ERROR/AndroidRuntime(303):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679) 
10-26 00:47:10.207: ERROR/AndroidRuntime(303):  at android.app.ActivityThread.access$2300(ActivityThread.java:125) 
10-26 00:47:10.207: ERROR/AndroidRuntime(303):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033) 
10-26 00:47:10.207: ERROR/AndroidRuntime(303):  at android.os.Handler.dispatchMessage(Handler.java:99) 
10-26 00:47:10.207: ERROR/AndroidRuntime(303):  at android.os.Looper.loop(Looper.java:123) 
10-26 00:47:10.207: ERROR/AndroidRuntime(303):  at android.app.ActivityThread.main(ActivityThread.java:4627) 
10-26 00:47:10.207: ERROR/AndroidRuntime(303):  at java.lang.reflect.Method.invokeNative(Native Method) 
10-26 00:47:10.207: ERROR/AndroidRuntime(303):  at java.lang.reflect.Method.invoke(Method.java:521) 
10-26 00:47:10.207: ERROR/AndroidRuntime(303):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 
10-26 00:47:10.207: ERROR/AndroidRuntime(303):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 
10-26 00:47:10.207: ERROR/AndroidRuntime(303):  at dalvik.system.NativeStart.main(Native Method) 
10-26 00:47:10.207: ERROR/AndroidRuntime(303): Caused by: android.view.InflateException: Binary XML file line #12: Error inflating class com.google.android.maps.MapView 
10-26 00:47:10.207: ERROR/AndroidRuntime(303):  at android.view.LayoutInflater.createView(LayoutInflater.java:513) 
10-26 00:47:10.207: ERROR/AndroidRuntime(303):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:565) 
10-26 00:47:10.207: ERROR/AndroidRuntime(303):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:618) 
10-26 00:47:10.207: ERROR/AndroidRuntime(303):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:621) 
10-26 00:47:10.207: ERROR/AndroidRuntime(303):  at android.view.LayoutInflater.inflate(LayoutInflater.java:407) 
10-26 00:47:10.207: ERROR/AndroidRuntime(303):  at android.view.LayoutInflater.inflate(LayoutInflater.java:320) 
10-26 00:47:10.207: ERROR/AndroidRuntime(303):  at android.view.LayoutInflater.inflate(LayoutInflater.java:276) 
10-26 00:47:10.207: ERROR/AndroidRuntime(303):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198) 
10-26 00:47:10.207: ERROR/AndroidRuntime(303):  at android.app.Activity.setContentView(Activity.java:1647) 
10-26 00:47:10.207: ERROR/AndroidRuntime(303):  at com.example.tabtest.TabstestingActivity.onCreate(TabstestingActivity.java:15) 
10-26 00:47:10.207: ERROR/AndroidRuntime(303):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 
10-26 00:47:10.207: ERROR/AndroidRuntime(303):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627) 
10-26 00:47:10.207: ERROR/AndroidRuntime(303):  ... 11 more 
10-26 00:47:10.207: ERROR/AndroidRuntime(303): Caused by: java.lang.reflect.InvocationTargetException 
10-26 00:47:10.207: ERROR/AndroidRuntime(303):  at com.google.android.maps.MapView.<init>(MapView.java:238) 
10-26 00:47:10.207: ERROR/AndroidRuntime(303):  at java.lang.reflect.Constructor.constructNative(Native Method) 
10-26 00:47:10.207: ERROR/AndroidRuntime(303):  at java.lang.reflect.Constructor.newInstance(Constructor.java:446) 
10-26 00:47:10.207: ERROR/AndroidRuntime(303):  at android.view.LayoutInflater.createView(LayoutInflater.java:500) 
10-26 00:47:10.207: ERROR/AndroidRuntime(303):  ... 22 more 
10-26 00:47:10.207: ERROR/AndroidRuntime(303): Caused by: java.lang.IllegalArgumentException: MapViews can only be created inside instances of MapActivity. 
10-26 00:47:10.207: ERROR/AndroidRuntime(303):  at com.google.android.maps.MapView.<init>(MapView.java:282) 
10-26 00:47:10.207: ERROR/AndroidRuntime(303):  at com.google.android.maps.MapView.<init>(MapView.java:255) 
10-26 00:47:10.207: ERROR/AndroidRuntime(303):  ... 26 more 
+0

請發佈您在logcat中看到的異常,並附上您的問題 – Craigy

+0

注意到您在mapview – railwayparade

回答

0

跟蹤是很清楚,

"10-26 00:47:10.207: ERROR/AndroidRuntime(303): Caused by: java.lang.IllegalArgumentException: MapViews can only be created inside instances of MapActivity." 

不能使用的MapView一個MapActivity之外。

+0

thanx上有多餘的layout_weight,沒有注意到:)現在工作正常:) – ukama