eclipse Android 无法启动活动,错误膨胀类?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9148400/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 17:40:10  来源:igfitidea点击:

Android unable to start activity, error inflating class?

androideclipsedebuggingandroid-activityruntimeexception

提问by Ephemeros

I'm new to android. I have some java knowledge, and I'm using Eclipse. At the moment I'm trying to display a map within a tab, and am looking at tutorials/code to help me. :)

我是安卓新手。我有一些 Java 知识,我正在使用 Eclipse。目前我正在尝试在选项卡中显示地图,并且正在查看教程/代码来帮助我。:)

I've seen a few questions asking about this error, but I can't figure out what I'm doing wrong, still. I'm using code from here: http://vkroz.wordpress.com/2009/07/03/programming-android-%E2%80%93-map-view-within-tab-view/

我已经看到一些关于此错误的问题,但我仍然无法弄清楚我做错了什么。我正在使用这里的代码:http: //vkroz.wordpress.com/2009/07/03/programming-android-%E2%80%93-map-view-within-tab-view/

Am I just missing something obvious?

我只是错过了一些明显的东西吗?

The value of the runtime exception e:

运行时异常 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>

Line 24 is just </LinearLayout>

第 24 行只是 </LinearLayout>

The whole of main.xml:

整个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>

The rest of my code is the same as linked, but I'll paste it here too.

我的其余代码与链接相同,但我也会将其粘贴到此处。

MapInTabActivity.java

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:

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:

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>

Manifest:

显现:

<?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>

And the rest of logcat (I think the important part was the bit I pointed out at the top, but maybe there's something else I don't know about).

和 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.access00(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

回答by JoxTraex

Fix this:

解决这个问题:

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

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

Also for your emulator are you use the Google APIsversion? The other versions do NOThave this library.

同样对于您的模拟器,您是否使用Google API版本?其他版本没有这个库。

UPDATE

更新

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

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

回答by Som

I tried the example that link you are following. Its working fine in my end. Your Manifest file says, you have not declared the MapTabView activity in the Manifest file. Use this in your manifest

我尝试了您正在关注的链接示例。它在我最后工作正常。您的清单文件说,您尚未在清单文件中声明 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>

Hope this helps !

希望这可以帮助 !

回答by AJcodez

Whenever you borrow code you should make sure you understand all of it, because a lot can go wrong. It seems like the problem is with your intent. You have:

每当你借用代码时,你应该确保你理解了它的全部内容,因为很多都可能出错。问题似乎出在您的意图上。你有:

Context ctx = this.getApplicationContext();

Usually intents are tied to activity contexts not application contexts so I would check that.

通常意图与活动上下文相关,而不是应用程序上下文,所以我会检查一下。