LayoutInflater.inflate时出现InflateException

时间:2011-07-15 21:50:51

标签: android-layout

代码在第二行崩溃:

LayoutInflater li = LayoutInflater.from(MyContext);
vView = li.inflate(R.layout.video, null);

布局 - video.xml

<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:id="@+id/GridItem"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:orientation="vertical"
   android:gravity="center_horizontal"
   android:background="#000080">

<imageview android:id="@+id/grid_item_image"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content">
  </imageview>

   <textview android:id="@+id/grid_item_text"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="TextView"
      android:gravity="center_horizontal"
      android:textColor="#000000">
   </textview>

</linearlayout>

致电堆栈:

07-15 16:40:57.909: WARN/dalvikvm(7936): threadid=1: thread exiting with uncaught exception (group=0x40018560)
07-15 16:40:57.997: ERROR/AndroidRuntime(7936): FATAL EXCEPTION: main
07-15 16:40:57.997: ERROR/AndroidRuntime(7936): android.view.InflateException: Binary XML file line #1: Error inflating class linearlayout
07-15 16:40:57.997: ERROR/AndroidRuntime(7936):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581)
07-15 16:40:57.997: ERROR/AndroidRuntime(7936):     at android.view.LayoutInflater.inflate(LayoutInflater.java:386)
07-15 16:40:57.997: ERROR/AndroidRuntime(7936):     at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
07-15 16:40:57.997: ERROR/AndroidRuntime(7936):     at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
07-15 16:40:57.997: ERROR/AndroidRuntime(7936):     at com.nitin.videosurf.VideoAdapter.getView(VideoAdapter.java:71)
07-15 16:40:57.997: ERROR/AndroidRuntime(7936):     at android.widget.AbsListView.obtainView(AbsListView.java:1456)
07-15 16:40:57.997: ERROR/AndroidRuntime(7936):     at android.widget.GridView.onMeasure(GridView.java:944)
07-15 16:40:57.997: ERROR/AndroidRuntime(7936):     at android.view.View.measure(View.java:8322)
07-15 16:40:57.997: ERROR/AndroidRuntime(7936):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
07-15 16:40:57.997: ERROR/AndroidRuntime(7936):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
07-15 16:40:57.997: ERROR/AndroidRuntime(7936):     at android.view.View.measure(View.java:8322)
07-15 16:40:57.997: ERROR/AndroidRuntime(7936):     at android.widget.LinearLayout.measureVertical(LinearLayout.java:531)
07-15 16:40:57.997: ERROR/AndroidRuntime(7936):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:309)
07-15 16:40:57.997: ERROR/AndroidRuntime(7936):     at android.view.View.measure(View.java:8322)
07-15 16:40:57.997: ERROR/AndroidRuntime(7936):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
07-15 16:40:57.997: ERROR/AndroidRuntime(7936):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
07-15 16:40:57.997: ERROR/AndroidRuntime(7936):     at android.view.View.measure(View.java:8322)
07-15 16:40:57.997: ERROR/AndroidRuntime(7936):     at android.view.ViewRoot.performTraversals(ViewRoot.java:839)
07-15 16:40:57.997: ERROR/AndroidRuntime(7936):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1859)
07-15 16:40:57.997: ERROR/AndroidRuntime(7936):     at android.os.Handler.dispatchMessage(Handler.java:99)
07-15 16:40:57.997: ERROR/AndroidRuntime(7936):     at android.os.Looper.loop(Looper.java:123)
07-15 16:40:57.997: ERROR/AndroidRuntime(7936):     at android.app.ActivityThread.main(ActivityThread.java:3806)
07-15 16:40:57.997: ERROR/AndroidRuntime(7936):     at java.lang.reflect.Method.invokeNative(Native Method)
07-15 16:40:57.997: ERROR/AndroidRuntime(7936):     at java.lang.reflect.Method.invoke(Method.java:507)
07-15 16:40:57.997: ERROR/AndroidRuntime(7936):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
07-15 16:40:57.997: ERROR/AndroidRuntime(7936):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
07-15 16:40:57.997: ERROR/AndroidRuntime(7936):     at dalvik.system.NativeStart.main(Native Method)
07-15 16:40:57.997: ERROR/AndroidRuntime(7936): Caused by: java.lang.ClassNotFoundException: android.view.linearlayout in loader dalvik.system.PathClassLoader[/data/app/com.nitin.videosurf-2.apk]
07-15 16:40:57.997: ERROR/AndroidRuntime(7936):     at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
07-15 16:40:57.997: ERROR/AndroidRuntime(7936):     at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
07-15 16:40:57.997: ERROR/AndroidRuntime(7936):     at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
07-15 16:40:57.997: ERROR/AndroidRuntime(7936):     at android.view.LayoutInflater.createView(LayoutInflater.java:471)
07-15 16:40:57.997: ERROR/AndroidRuntime(7936):     at android.view.LayoutInflater.onCreateView(LayoutInflater.java:549)
07-15 16:40:57.997: ERROR/AndroidRuntime(7936):     at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
07-15 16:40:57.997: ERROR/AndroidRuntime(7936):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
07-15 16:40:57.997: ERROR/AndroidRuntime(7936):     ... 26 more

1 个答案:

答案 0 :(得分:4)

这是一个简单而愚蠢的问题:<linearlayout> <imageview> <textview>等需要大写到<LinearLayout> <ImageView> <TextView>