5

私はアンドロイドが初めてです。Java の知識があり、Eclipse を使用しています。現在、タブ内にマップを表示しようとしており、チュートリアル/コードを参考にしています。:)

このエラーについていくつかの質問を見てきましたが、まだ何が間違っているのかわかりません。私はここからコードを使用しています: http://vkroz.wordpress.com/2009/07/03/programming-android-%E2%80%93-map-view-within-tab-view/

明らかな何かが欠けているだけですか?

実行時例外 e の値:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.mapintab/com.test.mapintab.MapInTabActivity}: ... android.view.InflateException: Binary XML file line #24: Error inflating class <unknown>

24行目はちょうど</LinearLayout>

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 android:id="@+id/emptylayout1" android:orientation="vertical"
                    android:layout_width="fill_parent" android:layout_height="fill_parent"/>

                <TextView android:id="@+id/textview2"
                    android:layout_width="fill_parent" android:layout_height="fill_parent"
                    android:text="Details Details Details Details"/>

        </FrameLayout>
    </LinearLayout> 
</TabHost>

私のコードの残りの部分はリンクされているものと同じですが、ここにも貼り付けます。

MapInTabActivity.java

package com.test.mapintab;

import android.app.TabActivity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.FrameLayout;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;

public class MapInTabActivity extends TabActivity {

    TabHost mTabHost;
    FrameLayout mFrameLayout;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        mTabHost = getTabHost();
        TabSpec tabSpec = mTabHost.newTabSpec("tab_test1");
        tabSpec.setIndicator("Map");
        Context ctx = this.getApplicationContext();
        Intent i = new Intent(ctx, MapInTabActivity.class);
        tabSpec.setContent(i);

        mTabHost.addTab(tabSpec);
        mTabHost.addTab(mTabHost.newTabSpec("tab_test2").setIndicator("Details").setContent(R.id.textview2));
        mTabHost.setCurrentTab(0);

    }

}

MapTabView.java:

package com.test.mapintab;

import android.os.Bundle;

import com.google.android.maps.MapActivity;

public class MapTabView extends MapActivity{

    @Override
    protected void onCreate(Bundle icicle){
        super.onCreate(icicle);
        setContentView(R.layout.maptabview);
    }

    @Override
    protected boolean isRouteDisplayed(){
        return false;
    }

}

maptabview.xml:

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/maptablayout"
    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="0HRMcD5o6WrBVhmwbWpeyeavZ67PXWOvJeeCx2g"/>

</RelativeLayout>

マニフェスト:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.test.mapintab"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="8" />
    <uses-permission android:name="android.permission.INTERNET"></uses-permission>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
    <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"></uses-permission>

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <uses-library android:name="com.google.android.maps"/>

        <activity
            android:name=".MapInTabActivity" android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

       <activity android:name=".MapTabView" android:label="@string/mapview_name">
           <intent-filter>
              <category android:name="android.intent.category.EMBED"></category>
              <action android:name="android.intent.action.MAIN"></action>
           </intent-filter>
        </activity>

    </application>
</manifest>

そしてlogcatの残りの部分(重要な部分は最初に指摘した部分だと思いますが、私が知らない何かが他にあるかもしれません)。

02-05 09:49:21.239: W/dalvikvm(357): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
02-05 09:49:22.616: E/AndroidRuntime(357): FATAL EXCEPTION: main
02-05 09:49:22.616: E/AndroidRuntime(357): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.mapintab/com.test.mapintab.MapInTabActivity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.mapintab/com.test.mapintab.MapInTabActivity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.mapintab/com.test.mapintab.MapInTabActivity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.mapintab/com.test.mapintab.MapInTabActivity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.mapintab/com.test.mapintab.MapInTabActivity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.mapintab/com.test.mapintab.MapInTabActivity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.mapintab/com.test.mapintab.MapInTabActivity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.mapintab/com.test.mapintab.MapInTabActivity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.mapintab/com.test.mapintab.MapInTabActivity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.mapintab/com.test.mapintab.MapInTabActivity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.mapintab/com.test.mapintab.MapInTabActivity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.mapintab/com.test.mapintab.MapInTabActivity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.mapintab/com.test.mapintab.MapInTabActivity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.mapintab/com.test.mapintab.MapInTabActivity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.mapintab/com.test.mapintab.MapInTabActivity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.mapintab/com.test.mapintab.MapInTabActivity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.mapintab/com.test.mapintab.MapInTabActivity}: android.view.InflateException: Binary XML file line #24: Error inflating class <unknown>
02-05 09:49:22.616: E/AndroidRuntime(357):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
02-05 09:49:22.616: E/AndroidRuntime(357):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
02-05 09:49:22.616: E/AndroidRuntime(357):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
02-05 09:49:22.616: E/AndroidRuntime(357):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
02-05 09:49:22.616: E/AndroidRuntime(357):  at android.os.Handler.dispatchMessage(Handler.java:99)
02-05 09:49:22.616: E/AndroidRuntime(357):  at android.os.Looper.loop(Looper.java:123)
02-05 09:49:22.616: E/AndroidRuntime(357):  at android.app.ActivityThread.main(ActivityThread.java:4627)
02-05 09:49:22.616: E/AndroidRuntime(357):  at java.lang.reflect.Method.invokeNative(Native Method)
02-05 09:49:22.616: E/AndroidRuntime(357):  at java.lang.reflect.Method.invoke(Method.java:521)
02-05 09:49:22.616: E/AndroidRuntime(357):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
02-05 09:49:22.616: E/AndroidRuntime(357):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
02-05 09:49:22.616: E/AndroidRuntime(357):  at dalvik.system.NativeStart.main(Native Method)
02-05 09:49:22.616: E/AndroidRuntime(357): Caused by: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.mapintab/com.test.mapintab.MapInTabActivity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.mapintab/com.test.mapintab.MapInTabActivity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.mapintab/com.test.mapintab.MapInTabActivity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.mapintab/com.test.mapintab.MapInTabActivity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.mapintab/com.test.mapintab.MapInTabActivity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.mapintab/com.test.mapintab.MapInTabActivity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.mapintab/com.test.mapintab.MapInTabActivity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.mapintab/com.test.mapintab.MapInTabActivity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.mapintab/com.test.mapintab.MapInTabActivit
4

3 に答える 3

1

これを修正します。

Binary XML file line #24: Error inflating class <unknown>

また、エミュレーターにはGoogle APIバージョンを使用していますか? 他のバージョンにはこのライブラリがありません。

アップデート

http://developer.android.com/resources/tutorials/views/hello-mapview.html

于 2012-02-05T10:22:10.557 に答える
1

あなたがフォローしているリンクの例を試しました。私の最後ではうまくいきます。マニフェスト ファイルには、マニフェスト ファイルで MapTabView アクティビティを宣言していないことが示されています。これをマニフェストで使用します

<activity android:name=".MapTabView" android:label="@string/mapview_name">
   <intent-filter>
      <category android:name="android.intent.category.EMBED"></category>
      <action android:name="android.intent.action.MAIN"></action>
   </intent-filter>
</activity>

お役に立てれば !

于 2012-02-05T10:26:13.360 に答える
-1

コードを借用するときはいつでも、すべてを理解していることを確認する必要があります。問題はあなたの意図にあるようです。あなたが持っている:

Context ctx = this.getApplicationContext();

通常、インテントはアプリケーション コンテキストではなくアクティビティ コンテキストに関連付けられているため、それを確認します。

于 2012-02-05T10:27:10.617 に答える