1

我正在使用日食。我确实添加了支持库。相同的代码可以在任何设备或模拟器上使用 Epi hiegher 然后 3.0,但不是 2.2 这是代码

  public class Main_View extends FragmentActivity{

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

xml文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <fragment
        android:id="@+id/fragment2"
        android:name="com.oent.bib_med.Cathegorie_List"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        />

    <fragment
        android:id="@+id/fragment1"
        android:name="com.oent.bib_med.Books_List"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="3"
         />



</LinearLayout>

片段类具有相同的代码

public class Books_List extends ListFragment{

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        String[] books = {"a","b","c","d","e","f","g","h","i"};

        ArrayAdapter <String> booksAdapter = 
                new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1,books );
        setListAdapter(booksAdapter);

    }

}

LoCcat: 10-06 00:41:33.044: E/AndroidRuntime(408): FATAL EXCEPTION: main 10-06 00:41:33.044: E/AndroidRuntime(408): java.lang.IllegalStateException: ArrayAdapter 需要资源 ID成为 TextView 10-06 00:41:33.044: E/AndroidRuntime(408): at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:347) 10-06 00:41:33.044: E/AndroidRuntime(408):在 android.widget.ArrayAdapter.getView(ArrayAdapter.java:323) 10-06 00:41:33.044: E/AndroidRuntime(408): 在 android.widget.AbsListView.obtainView(AbsListView.java:1315) 10-06 00 :41:33.044: E/AndroidRuntime(408): 在 android.widget.ListView.measureHeightOfChildren(ListView.java:1198) 10-06 00:41:33.044: E/AndroidRuntime(408): 在 android.widget.ListView。 onMeasure(ListView.java:1109) 10-06 00:41:33.044: E/AndroidRuntime(408): 在 android.view.View.measure(View.java:8171) 10-06 00:41:33。044: E/AndroidRuntime(408): 在 android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132) 10-06 00:41:33.044: E/AndroidRuntime(408): 在 android.widget.FrameLayout.onMeasure(FrameLayout .java:245) 10-06 00:41:33.044: E/AndroidRuntime(408): 在 android.view.View.measure(View.java:8171) 10-06 00:41:33.044: E/AndroidRuntime(408) ): 在 android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132) 10-06 00:41:33.044: E/AndroidRuntime(408): 在 android.widget.FrameLayout.onMeasure(FrameLayout.java:245) 10- 06 00:41:33.044: E/AndroidRuntime(408): 在 android.view.View.measure(View.java:8171) 10-06 00:41:33.044: E/AndroidRuntime(408): 在 android.view。 ViewGroup.measureChildWithMargins(ViewGroup.java:3132) 10-06 00:41:33.044: E/AndroidRuntime(408): 在 android.widget.FrameLayout.onMeasure(FrameLayout.java:245) 10-06 00:41:33.044:E/AndroidRuntime(408): 在 android.view.View.measure(View.java:8171) 10-06 00:41:33.044: E/AndroidRuntime(408): 在 android.view.ViewGroup.measureChildWithMargins(ViewGroup.java :3132) 10-06 00:41:33.044: E/AndroidRuntime(408): 在 android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1012) 10-06 00:41:33.044: E/AndroidRuntime(408):在 android.widget.LinearLayout.measureVertical(LinearLayout.java:381) 10-06 00:41:33.044: E/AndroidRuntime(408): 在 android.widget.LinearLayout.onMeasure(LinearLayout.java:304) 10-06 00 :41:33.044: E/AndroidRuntime(408): 在 android.view.View.measure(View.java:8171) 10-06 00:41:33.044: E/AndroidRuntime(408): 在 android.view.ViewGroup。 measureChildWithMargins(ViewGroup.java:3132) 10-06 00:41:33.044: E/AndroidRuntime(408): 在 android.widget.FrameLayout.onMeasure(FrameLayout.java:245) 10-06 00:41:33.044:E/AndroidRuntime(408): 在 android.view.View.measure(View.java:8171) 10-06 00:41:33.044: E/AndroidRuntime(408): 在 android.widget.LinearLayout.measureVertical(LinearLayout.java :526) 10-06 00:41:33.044: E/AndroidRuntime(408): 在 android.widget.LinearLayout.onMeasure(LinearLayout.java:304) 10-06 00:41:33.044: E/AndroidRuntime(408):在 android.view.View.measure(View.java:8171) 10-06 00:41:33.044: E/AndroidRuntime(408): 在 android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132) 10-06 00 :41:33.044:E / AndroidRuntime(408):在android.widget.FrameLayout.onMeasure(FrameLayout.java:245)10-06 00:41:33.044:E / AndroidRuntime(408):在android.view.View。测量(View.java:8171)10-06 00:41:33.044:E/AndroidRuntime(408):在 android.view.ViewRoot.performTraversals(ViewRoot.java:801)10-06 00:41:33.044:E/ AndroidRuntime(408):在 android.view。ViewRoot.handleMessage(ViewRoot.java:1727) 10-06 00:41:33.044: E/AndroidRuntime(408): 在 android.os.Handler.dispatchMessage(Handler.java:99) 10-06 00:41:33.044: E/AndroidRuntime(408): 在 android.os.Looper.loop(Looper.java:123) 10-06 00:41:33.044: E/AndroidRuntime(408): 在 android.app.ActivityThread.main(ActivityThread.java :4627) 10-06 00:41:33.044: E/AndroidRuntime(408): 在 java.lang.reflect.Method.invokeNative(Native Method) 10-06 00:41:33.044: E/AndroidRuntime(408): 在java.lang.reflect.Method.invoke(Method.java:521) 10-06 00:41:33.044: E/AndroidRuntime(408): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java :868) 10-06 00:41:33.044: E/AndroidRuntime(408): 在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 10-06 00:41:33.044: E/AndroidRuntime (408):在 dalvik.system.NativeStart。主要(本机方法)10-06 00:41:33.044:E/AndroidRuntime(408):引起:java.lang.ClassCastException:com.android.internal.widget.WeightedLinearLayout 10-06 00:41:33.044:E/ AndroidRuntime(408): 在 android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:340) 10-06 00:41:33.044: E/AndroidRuntime(408): ... 38 更多

4

1 回答 1

1

simple_list_item_activated_1低于 11 的 API 中不存在该布局。这就是它崩溃的原因。

于 2013-10-06T00:33:15.620 回答