android – 错误膨胀类ImageView

前端之家收集整理的这篇文章主要介绍了android – 错误膨胀类ImageView前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我间歇性地得到了InflateException / ClassNotFoundException错误.我之前在SO中看到过类似的错误但它们是由拼写错误引起的.我正确地拼写了’ ImageView’所以我不知道是什么导致了错误.

发生错误代码是:

  1. v = View.inflate(getContext(),R.layout.event_show_row_layout,null);

这是布局xml:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.  
  4. android:layout_width="fill_parent"
  5. android:layout_height="wrap_content"
  6. android:orientation="vertical" >
  7.  
  8. <RelativeLayout
  9. android:layout_width="fill_parent"
  10. android:layout_height="wrap_content"
  11. android:orientation="horizontal"
  12. android:paddingLeft="10dip"
  13. android:paddingRight="10dip" >
  14.  
  15. <TextView
  16. android:id="@+id/fromTextView"
  17. android:layout_width="wrap_content"
  18. android:layout_height="wrap_content"
  19. android:textSize="12sp"
  20. android:textStyle="italic" />
  21.  
  22. <TextView
  23. android:id="@+id/timeTextView"
  24. android:layout_width="fill_parent"
  25. android:layout_height="wrap_content"
  26. android:gravity="right"
  27. android:textSize="12sp"
  28. android:textStyle="italic" />
  29. </RelativeLayout>
  30.  
  31. <RelativeLayout
  32. android:id="@+id/layoutPostImage"
  33. android:layout_width="match_parent"
  34. android:layout_height="wrap_content"
  35. android:padding="4dp" >
  36.  
  37. <ImageView
  38. android:id="@+id/postImageView"
  39. android:layout_width="match_parent"
  40. android:layout_height="wrap_content"
  41. android:layout_alignParentLeft="true"
  42. android:layout_alignParentTop="true"
  43. android:layout_margin="2dp"
  44. android:adjustViewBounds="true"
  45. android:background="@drawable/timeline_image_border"
  46. android:contentDescription="@string/hello"
  47. android:paddingBottom="6dp"
  48. android:scaleType="fitXY"
  49. android:src="@drawable/timeline_image_dummy" />
  50. </RelativeLayout>
  51.  
  52. <RelativeLayout
  53. android:id="@+id/wordsRelativeLayout"
  54. android:layout_width="wrap_content"
  55. android:layout_height="wrap_content" >
  56.  
  57. <TextView
  58. android:id="@+id/wordsTextView"
  59. android:layout_width="fill_parent"
  60. android:layout_height="wrap_content"
  61. android:gravity="center_vertical|center_horizontal"
  62. android:paddingLeft="50dp"
  63. android:paddingRight="50dp"
  64. android:text="@string/hello" />
  65.  
  66. <ImageView
  67. android:id="@+id/topLeftQuoteImageView"
  68. android:layout_width="wrap_content"
  69. android:layout_height="wrap_content"
  70. android:layout_alignParentLeft="true"
  71. android:layout_alignParentTop="true"
  72. android:layout_marginLeft="10dp"
  73. android:layout_marginTop="10dp"
  74. android:adjustViewBounds="true"
  75. android:contentDescription="@string/hello"
  76. android:maxHeight="25dp"
  77. android:maxWidth="25dp"
  78. android:scaleType="fitXY"
  79. android:src="@drawable/po_quotes_mobile1" />
  80.  
  81. <ImageView
  82. android:id="@+id/bottomRightQuoteImageView"
  83. android:layout_width="wrap_content"
  84. android:layout_height="wrap_content"
  85. android:layout_alignParentBottom="true"
  86. android:layout_alignParentRight="true"
  87. android:layout_marginBottom="12dp"
  88. android:layout_marginRight="12dp"
  89. android:adjustViewBounds="true"
  90. android:contentDescription="@string/hello"
  91. android:maxHeight="25dp"
  92. android:maxWidth="25dp"
  93. android:scaleType="fitXY"
  94. android:src="@drawable/po_quotes_mobile2" />
  95. </RelativeLayout>
  96.  
  97. <RelativeLayout
  98. android:layout_width="fill_parent"
  99. android:layout_height="wrap_content"
  100. android:layout_marginTop="5dp" >
  101.  
  102. <Button
  103. android:id="@+id/commentButton"
  104. android:layout_width="84dp"
  105. android:layout_height="24dp"
  106. android:layout_alignParentLeft="true"
  107. android:layout_marginLeft="5dp"
  108. android:background="@drawable/es_comment_btn" />
  109.  
  110. <Button
  111. android:id="@+id/buttonLike"
  112. android:layout_width="84dp"
  113. android:layout_height="24dp"
  114. android:layout_marginLeft="5dp"
  115. android:layout_toRightOf="@id/commentButton"
  116. android:background="@drawable/es_like_btn" />
  117.  
  118. <Button
  119. android:id="@+id/buttonNumberLike"
  120. android:layout_width="wrap_content"
  121. android:layout_height="24dp"
  122. android:layout_gravity="center"
  123. android:layout_marginLeft="5dp"
  124. android:layout_toRightOf="@id/buttonLike"
  125. android:background="@drawable/like_counter"
  126. android:textColor="@android:color/white"
  127. android:textSize="12sp" />
  128.  
  129. <Button
  130. android:id="@+id/buttonDelete"
  131. android:layout_width="38dp"
  132. android:layout_height="24dp"
  133. android:layout_alignParentRight="true"
  134. android:layout_marginRight="5dp"
  135. android:background="@drawable/es_more_btn" />
  136. </RelativeLayout>
  137.  
  138. <TextView
  139. android:id="@+id/commentsTextView"
  140. android:layout_width="fill_parent"
  141. android:layout_height="wrap_content"
  142. android:layout_marginBottom="10dp"
  143. android:layout_marginLeft="10dp"
  144. android:layout_marginRight="10dp"
  145. android:layout_marginTop="10dp"
  146. android:background="#FFF9F8F1"
  147. android:text="@string/hello"
  148. android:textColor="@android:color/black"
  149. android:textSize="12sp" />
  150.  
  151. <TextView
  152. android:id="@+id/spacerTextView"
  153. android:layout_width="fill_parent"
  154. android:layout_height="wrap_content"
  155. android:layout_marginLeft="10dp"
  156. android:layout_marginRight="10dp"
  157. android:layout_marginTop="10dp" />
  158.  
  159. </LinearLayout>

这是错误日志:

  1. E/AndroidRuntime(15849): FATAL EXCEPTION: main
  2. E/AndroidRuntime(15849): android.view.InflateException: Binary XML file line #36: Error inflating class ImageView
  3. E/AndroidRuntime(15849): at org.holoeverywhere.LayoutInflater.createViewFromTag(LayoutInflater.java:454)
  4. E/AndroidRuntime(15849): at org.holoeverywhere.LayoutInflater.rInflate(LayoutInflater.java:737)
  5. E/AndroidRuntime(15849): at org.holoeverywhere.LayoutInflater.rInflate(LayoutInflater.java:740)
  6. E/AndroidRuntime(15849): at org.holoeverywhere.LayoutInflater.inflate(LayoutInflater.java:542)
  7. E/AndroidRuntime(15849): at org.holoeverywhere.LayoutInflater.inflate(LayoutInflater.java:492)
  8. E/AndroidRuntime(15849): at org.holoeverywhere.LayoutInflater.inflate(LayoutInflater.java:487)
  9. E/AndroidRuntime(15849): at android.view.View.inflate(View.java:8807)
  10. E/AndroidRuntime(15849): at com.mypackage.adapters.PostAdapter.getPostView(PostAdapter.java:283)
  11. E/AndroidRuntime(15849): at com.mypackage.adapters.PostAdapter.getView(PostAdapter.java:268)
  12. E/AndroidRuntime(15849): at android.widget.HeaderViewListAdapter.getView(HeaderViewListAdapter.java:220)
  13. E/AndroidRuntime(15849): at android.widget.AbsListView.obtainView(AbsListView.java:1430)
  14. E/AndroidRuntime(15849): at android.widget.ListView.makeAndAddView(ListView.java:1745)
  15. E/AndroidRuntime(15849): at android.widget.ListView.fillDown(ListView.java:670)
  16. E/AndroidRuntime(15849): at android.widget.ListView.fillFromTop(ListView.java:727)
  17. E/AndroidRuntime(15849): at android.widget.ListView.layoutChildren(ListView.java:1598)
  18. E/AndroidRuntime(15849): at android.widget.AbsListView.onLayout(AbsListView.java:1260)
  19. E/AndroidRuntime(15849): at android.view.View.layout(View.java:7175)
  20. E/AndroidRuntime(15849): at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
  21. E/AndroidRuntime(15849): at android.view.View.layout(View.java:7175)
  22. E/AndroidRuntime(15849): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
  23. E/AndroidRuntime(15849): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
  24. E/AndroidRuntime(15849): at android.widget.LinearLayout.onLayout(LinearLayout.java:1047)
  25. E/AndroidRuntime(15849): at android.view.View.layout(View.java:7175)
  26. E/AndroidRuntime(15849): at android.widget.RelativeLayout.onLayout(RelativeLayout.java:912)
  27. E/AndroidRuntime(15849): at android.view.View.layout(View.java:7175)
  28. E/AndroidRuntime(15849): at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
  29. E/AndroidRuntime(15849): at android.view.View.layout(View.java:7175)
  30. E/AndroidRuntime(15849): at net.simonvt.menudrawer.LeftDrawer.onLayout(LeftDrawer.java:64)
  31. E/AndroidRuntime(15849): at android.view.View.layout(View.java:7175)
  32. E/AndroidRuntime(15849): at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
  33. E/AndroidRuntime(15849): at android.view.View.layout(View.java:7175)
  34. E/AndroidRuntime(15849): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
  35. E/AndroidRuntime(15849): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
  36. E/AndroidRuntime(15849): at android.widget.LinearLayout.onLayout(LinearLayout.java:1047)
  37. E/AndroidRuntime(15849): at android.view.View.layout(View.java:7175)
  38. E/AndroidRuntime(15849): at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
  39. E/AndroidRuntime(15849): at android.view.View.layout(View.java:7175)
  40. E/AndroidRuntime(15849): at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
  41. E/AndroidRuntime(15849): at android.view.View.layout(View.java:7175)
  42. E/AndroidRuntime(15849): at android.view.ViewRoot.performTraversals(ViewRoot.java:1140)
  43. E/AndroidRuntime(15849): at android.view.ViewRoot.handleMessage(ViewRoot.java:1859)
  44. E/AndroidRuntime(15849): at android.os.Handler.dispatchMessage(Handler.java:99)
  45. E/AndroidRuntime(15849): at android.os.Looper.loop(Looper.java:130)
  46. E/AndroidRuntime(15849): at android.app.ActivityThread.main(ActivityThread.java:3683)
  47. E/AndroidRuntime(15849): at java.lang.reflect.Method.invokeNative(Native Method)
  48. E/AndroidRuntime(15849): at java.lang.reflect.Method.invoke(Method.java:507)
  49. E/AndroidRuntime(15849): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
  50. E/AndroidRuntime(15849): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
  51. E/AndroidRuntime(15849): at dalvik.system.NativeStart.main(Native Method)
  52. E/AndroidRuntime(15849): Caused by: java.lang.ClassNotFoundException: Could not find class: ImageView
  53. E/AndroidRuntime(15849): at org.holoeverywhere.LayoutInflater.onCreateView(LayoutInflater.java:607)
  54. E/AndroidRuntime(15849): at org.holoeverywhere.LayoutInflater.createViewFromTag(LayoutInflater.java:448)
  55. E/AndroidRuntime(15849): ... 48 more

解决方法

试着改变
  1. v = View.inflate(getContext(),null);

  1. v = View.inflate(getApplicationContext(),null);

猜你在找的Android相关文章