无法启动activity ComponentInfo android.view.InflateException:二进制XML文件第16行

无法启动activity ComponentInfo android.view.InflateException:二进制XML文件第16行,android,android-fragments,android-emulator,Android,Android Fragments,Android Emulator,我只想使用actionbar选项卡中的listfragment创建一个包含图像的Listview。下面是错误日志 12-31 11:25:13.131: D/AndroidRuntime(4199): Shutting down VM 12-31 11:25:13.131: W/dalvikvm(4199): threadid=1: thread exiting with uncaught exception (group=0x40a71930) 12-31 11:25:13.161: E/An

我只想使用actionbar选项卡中的listfragment创建一个包含图像的Listview。下面是错误日志

12-31 11:25:13.131: D/AndroidRuntime(4199): Shutting down VM
12-31 11:25:13.131: W/dalvikvm(4199): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
12-31 11:25:13.161: E/AndroidRuntime(4199): FATAL EXCEPTION: main
12-31 11:25:13.161: E/AndroidRuntime(4199): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.sunil.actionbartab/com.sunil.actionbartab.MainActivity}: android.view.InflateException: Binary XML file line #16: Error inflating class fragment
12-31 11:25:13.161: E/AndroidRuntime(4199):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
12-31 11:25:13.161: E/AndroidRuntime(4199):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
12-31 11:25:13.161: E/AndroidRuntime(4199):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
12-31 11:25:13.161: E/AndroidRuntime(4199):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)`enter code here`
12-31 11:25:13.161: E/AndroidRuntime(4199):     at android.os.Handler.dispatchMessage(Handler.java:99)
12-31 11:25:13.161: E/AndroidRuntime(4199):     at android.os.Looper.loop(Looper.java:137)
12-31 11:25:13.161: E/AndroidRuntime(4199):     at android.app.ActivityThread.main(ActivityThread.java:5041)
12-31 11:25:13.161: E/AndroidRuntime(4199):     at java.lang.reflect.Method.invokeNative(Native Method)
12-31 11:25:13.161: E/AndroidRuntime(4199):     at java.lang.reflect.Method.invoke(Method.java:511)
12-31 11:25:13.161: E/AndroidRuntime(4199):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
12-31 11:25:13.161: E/AndroidRuntime(4199):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
12-31 11:25:13.161: E/AndroidRuntime(4199):     at dalvik.system.NativeStart.main(Native Method)
12-31 11:25:13.161: E/AndroidRuntime(4199): Caused by: android.view.InflateException: Binary XML file line #16: Error inflating class fragment
12-31 11:25:13.161: E/AndroidRuntime(4199):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
12-31 11:25:13.161: E/AndroidRuntime(4199):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
12-31 11:25:13.161: E/AndroidRuntime(4199):     at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
12-31 11:25:13.161: E/AndroidRuntime(4199):     at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
12-31 11:25:13.161: E/AndroidRuntime(4199):     at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
12-31 11:25:13.161: E/AndroidRuntime(4199):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
12-31 11:25:13.161: E/AndroidRuntime(4199):     at android.app.Activity.setContentView(Activity.java:1881)
12-31 11:25:13.161: E/AndroidRuntime(4199):     at com.sunil.actionbartab.MainActivity.onCreate(MainActivity.java:29)
12-31 11:25:13.161: E/AndroidRuntime(4199):     at android.app.Activity.performCreate(Activity.java:5104)
12-31 11:25:13.161: E/AndroidRuntime(4199):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
12-31 11:25:13.161: E/AndroidRuntime(4199):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
12-31 11:25:13.161: E/AndroidRuntime(4199):     ... 11 more
12-31 11:25:13.161: E/AndroidRuntime(4199): Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.sunil.actionbartb.AndroidList: make sure class name exists, is public, and has an empty constructor that is public
12-31 11:25:13.161: E/AndroidRuntime(4199):     at android.support.v4.app.Fragment.instantiate(Fragment.java:395)
12-31 11:25:13.161: E/AndroidRuntime(4199):     at android.support.v4.app.Fragment.instantiate(Fragment.java:363)
12-31 11:25:13.161: E/AndroidRuntime(4199):     at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:264)
12-31 11:25:13.161: E/AndroidRuntime(4199):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
12-31 11:25:13.161: E/AndroidRuntime(4199):     ... 21 more
12-31 11:25:13.161: E/AndroidRuntime(4199): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.sunil.actionbartb.AndroidList" on path: /data/app/com.sunil.actionbartab-1.apk
12-31 11:25:13.161: E/AndroidRuntime(4199):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
12-31 11:25:13.161: E/AndroidRuntime(4199):     at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
12-31 11:25:13.161: E/AndroidRuntime(4199):     at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
12-31 11:25:13.161: E/AndroidRuntime(4199):     at android.support.v4.app.Fragment.instantiate(Fragment.java:385)
12-31 11:25:13.161: E/AndroidRuntime(4199):     ... 24 more
活动主体

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >

<fragment
    android:id="@+id/country_fragment"
    android:name="com.sunil.actionbartab.MainActivity"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" />

</RelativeLayout>
AndroidList.Java

package com.sunil.actionbartab;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.SimpleAdapter;

public class AndroidList extends ListFragment {


String[] Forts = new String[] {
        "Pune",
        "Thane",
        "Satara",
        "Raigad",
        "Nashik",
        "Kolhapur",

    };
     int[] citylogo = new int[]{
    R.drawable.pune,
    R.drawable.thane,
    R.drawable.raigad,
    R.drawable.nashik,
    R.drawable.kolhapur,};

    String[] cityinfo = new String[]{
    "Pune is known to have existed as a town since 847 AD. It was the first capital of the Maratha Empire under Chhatrapati Shivaji Raje Bhosale",
    "Thane  is a city in Maharashtra, India, at the head of the Thane Creek.Thane also known as 'the city of lakes' is the administrative headquarters of Thane district",
    "It is located in the Konkan region. The district was renamed after Raigad, the fort that was the former capital of the Maratha leader Shivaji Maharaj",
    "Nashik is a located on the banks of the Godavari River, the holy river which flows through old Nashik",
    "Kolhapur is a sixth largest city of Maharashtra situated in the southwest part of the state of Maharashtra." +
    "Before Independence, it was a 19 gun salute princely state ruled by the royal Bhosale Chhatrapatis of the Maratha Empire.",



};
  @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    /*return inflater.inflate(R.layout.list_fragment, container, false);*/
      // Each row in the list stores country name, currency and flag
    List<HashMap<String,String>> aList = new ArrayList<HashMap<String,String>>();

    for(int i=0;i<10;i++){
        HashMap<String, String> hm = new HashMap<String,String>();
        hm.put("txt", "Forts : " + Forts[i]);
        hm.put("cur","Cityinfo : " + cityinfo[i]);
        hm.put("citylogo", Integer.toString(citylogo[i]) );
        aList.add(hm);
    }

    // Keys used in Hashmap
    String[] from = { "flag","txt","cur" };

    // Ids of views in listview_layout
    int[] to = { R.id.citylogo,R.id.fort,R.id.cityinfo};

    // Instantiating an adapter to store each items
    // R.layout.listview_layout defines the layout of each item
    SimpleAdapter adapter = new SimpleAdapter(getActivity().getBaseContext(), aList, R.layout.englishlist, from, to);

    setListAdapter(adapter);

    return super.onCreateView(inflater, container, savedInstanceState);
}

首先,关闭xml中的RelativeLayout

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:tools="http://schemas.android.com/tools"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     tools:context=".MainActivity" >

    <fragment
      android:id="@+id/country_fragment"
      android:name="com.sunil.actionbartab.MainActivity"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content" />
    </RelativeLayout>

好像有个打字错误,actionbartb而不是actionbartab。如果您最近修复了代码中的此错误,请清理并重新生成应用程序。

仍然会收到相同的错误
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:tools="http://schemas.android.com/tools"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     tools:context=".MainActivity" >

    <fragment
      android:id="@+id/country_fragment"
      android:name="com.sunil.actionbartab.MainActivity"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content" />
    </RelativeLayout>
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        return super.onCreateView(inflater, container, savedInstanceState);
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        List<HashMap<String,String>> aList = new ArrayList<HashMap<String,String>>();

for(int i=0;i<10;i++){
    HashMap<String, String> hm = new HashMap<String,String>();
    hm.put("txt", "Forts : " + Forts[i]);
    hm.put("cur","Cityinfo : " + cityinfo[i]);
    hm.put("citylogo", Integer.toString(citylogo[i]) );
    aList.add(hm);
}

// Keys used in Hashmap
String[] from = { "flag","txt","cur" };

// Ids of views in listview_layout
int[] to = { R.id.citylogo,R.id.fort,R.id.cityinfo};

// Instantiating an adapter to store each items
// R.layout.listview_layout defines the layout of each item
SimpleAdapter adapter = new SimpleAdapter(getActivity().getBaseContext(), aList, R.layout.englishlist, from, to);

setListAdapter(adapter);
    }
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.sunil.actionbartb.AndroidList" on path: /data/app/com.sunil.actionbartab-1.apk