android.view.InflateException:二进制XML文件行#40:二进制XML文件行#21:错误膨胀类android.widget.ListView

时间:2017-01-15 23:09:28

标签: java android listview bluetooth widget

我以前有过以下代码,但在禁用它以执行蓝牙配对的某些工作后,由于某种原因现在它崩溃了。

主要活动:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.game_buttons);

    TabHost tab = (TabHost) findViewById(R.id.tabHost);
    tab.setup();
    TabHost.TabSpec spec1 = tab.newTabSpec("Simulation");
    spec1.setIndicator("Simulation");
    spec1.setContent(R.id.layout1);
    tab.addTab(spec1);

    TabHost.TabSpec spec2 = tab.newTabSpec("Robots");
    spec2.setIndicator("Robots");
    spec2.setContent(R.id.layout2);
    tab.addTab(spec2);
    init();
    if (btAdapter == null) {
        Toast.makeText(getApplicationContext(), "No Bluetooth Detected", Toast.LENGTH_SHORT).show();
        finish();
    } else {
        if (!btAdapter.isEnabled()) {
            turnONBT();
        }

        getPairedDevices();
        startDiscovery();
    }
    ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, pairedDevices);
    listView.setAdapter(arrayAdapter);

}

XML布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/game_buttons"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".Breadcrumbs">

    <TabHost
        android:id="@+id/tabHost"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:id="@+id/line"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" >
            </TabWidget>

            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <include
                    android:id="@+id/layout1"
                    layout="@layout/crumb_selection"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    ></include>
                <include
                    android:id="@+id/layout2"
                    layout="@layout/paired_devices"
                    android:layout_height="match_parent"
                    android:layout_width="match_parent"
                    ></include>

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

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/paired_devices"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <LinearLayout
        android:id="@+id/BTConnections"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:text="BlueTooth Connections">

        <TextView
            android:id="@+id/pairedDevices"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Paired Devices:" />

        <ListView
            android:id="@+id/ConnectionsList"
            android:layout_width="match_parent"
            android:layout_height="100pt"
            android:layout_above="@+id/bConnectionNew"
            android:layout_below="@+id/paired_devices"
            android:onClick="run"
            android:dividerHeight="15dp"
            android:text="Paired Devices">
        </ListView>

        <Button
            android:id="@+id/newBTConnection"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="200dp"
            android:layout_height="75dp"
            android:layout_gravity="center_horizontal|center"
            android:layout_marginTop="25dp"
            android:onClick=""
            android:text="New Connection"
            android:textSize="24dp"
            android:textStyle="bold" />
        <Button
            android:id="@+id/startMindDroid"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="150dp"
            android:layout_height="75dp"
            android:layout_gravity="center_horizontal|center"
            android:layout_marginTop="25dp"
            android:onClick="robotButton_onCLick"
            android:text="MindDroid"
            android:textSize="28dp"
            android:textStyle="bold" />
    </LinearLayout>
</LinearLayout>

调试器输出:

E/AndroidRuntime: FATAL EXCEPTION: main
              Process: com.shiohigari.flocking.android, PID: 27171
              java.lang.RuntimeException: Unable to start activity ComponentInfo{com.shiohigari.flocking.android/com.shiohigari.flocking.android.Breadcrumbs}: android.view.InflateException: Binary XML file line #40: Binary XML file line #21: Error inflating class android.widget.ListView
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3254)
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3350)
                  at android.app.ActivityThread.access$1100(ActivityThread.java:222)
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1795)
                  at android.os.Handler.dispatchMessage(Handler.java:102)
                  at android.os.Looper.loop(Looper.java:158)
                  at android.app.ActivityThread.main(ActivityThread.java:7229)
                  at java.lang.reflect.Method.invoke(Native Method)
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
               Caused by: android.view.InflateException: Binary XML file line #40: Binary XML file line #21: Error inflating class android.widget.ListView
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:551)
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:429)
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:380)
                  at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:474)
                  at android.app.Activity.setContentView(Activity.java:2387)
                  at com.shiohigari.flocking.android.Breadcrumbs.onCreate(Breadcrumbs.java:98)
                  at android.app.Activity.performCreate(Activity.java:6876)
                  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135)
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3207)
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3350) 
                  at android.app.ActivityThread.access$1100(ActivityThread.java:222) 
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1795) 
                  at android.os.Handler.dispatchMessage(Handler.java:102) 
                  at android.os.Looper.loop(Looper.java:158) 
                  at android.app.ActivityThread.main(ActivityThread.java:7229) 
                  at java.lang.reflect.Method.invoke(Native Method) 
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 
               Caused by: android.view.InflateException: Binary XML file line #21: Error inflating class android.widget.ListView
                  at android.view.LayoutInflater.createView(LayoutInflater.java:657)
                  at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
                  at android.view.LayoutInflater.onCreateView(LayoutInflater.java:706)
                  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:774)
                  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:716)
                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:847)
                  at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810)
                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:855)
                  at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810)
                  at android.view.LayoutInflater.parseInclude(LayoutInflater.java:1001)
                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:843)
                  at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810)
                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:855)
                  at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810)
                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:855)
                  at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810)
                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:855)
                  at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810)
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:527)
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:429) 
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:380) 
                  at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:474) 
                  at android.app.Activity.setContentView(Activity.java:2387) 
                  at com.shiohigari.flocking.android.Breadcrumbs.onCreate(Breadcrumbs.java:98) 
                  at android.app.Activity.performCreate(Activity.java:6876) 
                  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135) 
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3207) 
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3350) 
                  at android.app.ActivityThread.access$1100(ActivityThread.java:222) 
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1795) 
                  at android.os.Handler.dispatchMessage(Handler.java:102) 
                  at android.os.Looper.loop(Looper.java:158) 
                  at android.app.ActivityThread.main(ActivityThread.java:7229) 
                  at java.lang.reflect.Method.invoke(Native Method) 
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 

错误行(#98)对应于setContentView()命令。任何帮助将不胜感激:D

0 个答案:

没有答案