Android GridView android.view.InflateException:二进制 XML 异常
再见,我创建了一个 GridView 画廊,网格视图项是 ImageView 和 TextView 的复合体,所以我使用了 inflate 文件 grid_folder_item.xml。 应用程序启动时抛出异常:
droidRuntime(286): FATAL EXCEPTION: main
11-05 12:27:37.860: E/AndroidRuntime(286): android.view.InflateException: Binary XML file line #10: Error inflating class Textview
11-05 12:27:37.860: E/AndroidRuntime(286): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:576)
11-05 12:27:37.860: E/AndroidRuntime(286): at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
11-05 12:27:37.860: E/AndroidRuntime(286): at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
11-05 12:27:37.860: E/AndroidRuntime(286): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
11-05 12:27:37.860: E/AndroidRuntime(286): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
11-05 12:27:37.860: E/AndroidRuntime(286): at it.bwpp.adapter.ImageGridAdapter.getView(ImageGridAdapter.java:44)
11-05 12:27:37.860: E/AndroidRuntime(286): at android.widget.AbsListView.obtainView(AbsListView.java:1315)
11-05 12:27:37.860: E/AndroidRuntime(286): at android.widget.GridView.onMeasure(GridView.java:932)
11-05 12:27:37.860: E/AndroidRuntime(286): at android.view.View.measure(View.java:8171)
11-05 12:27:37.860: E/AndroidRuntime(286): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
11-05 12:27:37.860: E/AndroidRuntime(286): at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
11-05 12:27:37.860: E/AndroidRuntime(286): at android.view.View.measure(View.java:8171)
11-05 12:27:37.860: E/AndroidRuntime(286): at android.widget.LinearLayout.measureVertical(LinearLayout.java:526)
11-05 12:27:37.860: E/AndroidRuntime(286): at android.widget.LinearLayout.onMeasure(LinearLayout.java:304)
11-05 12:27:37.860: E/AndroidRuntime(286): at android.view.View.measure(View.java:8171)
11-05 12:27:37.860: E/AndroidRuntime(286): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
11-05 12:27:37.860: E/AndroidRuntime(286): at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
11-05 12:27:37.860: E/AndroidRuntime(286): at android.view.View.measure(View.java:8171)
11-05 12:27:37.860: E/AndroidRuntime(286): at android.view.ViewRoot.performTraversals(ViewRoot.java:801)
11-05 12:27:37.860: E/AndroidRuntime(286): at android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
11-05 12:27:37.860: E/AndroidRuntime(286): at android.os.Handler.dispatchMessage(Handler.java:99)
11-05 12:27:37.860: E/AndroidRuntime(286): at android.os.Lo11-05 12:27:37.860: E/Anoper.loop(Looper.java:123)
11-05 12:27:37.860: E/AndroidRuntime(286): at android.app.ActivityThread.main(ActivityThread.java:4627)
11-05 12:27:37.860: E/AndroidRuntime(286): at java.lang.reflect.Method.invokeNative(Native Method)
11-05 12:27:37.860: E/AndroidRuntime(286): at java.lang.reflect.Method.invoke(Method.java:521)
11-05 12:27:37.860: E/AndroidRuntime(286): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-05 12:27:37.860: E/AndroidRuntime(286): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-05 12:27:37.860: E/AndroidRuntime(286): at dalvik.system.NativeStart.main(Native Method)
11-05 12:27:37.860: E/AndroidRuntime(286): Caused by: java.lang.ClassNotFoundException: android.view.Textview in loader dalvik.system.PathClassLoader[/data/app/it.bwpp.activity-1.apk]
11-05 12:27:37.860: E/AndroidRuntime(286): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
11-05 12:27:37.860: E/AndroidRuntime(286): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
11-05 12:27:37.860: E/AndroidRuntime(286): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
11-05 12:27:37.860: E/AndroidRuntime(286): at android.view.LayoutInflater.createView(LayoutInflater.java:466)
11-05 12:27:37.860: E/AndroidRuntime(286): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:544)
11-05 12:27:37.860: E/AndroidRuntime(286): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
11-05 12:27:37.860: E/AndroidRuntime(286): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
11-05 12:27:37.860: E/AndroidRuntime(286): ... 27 more
AVD 平台和构建目标 Android 2.2(API 级别 8) folder_item.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" >
<ImageView android:id="@+id/grid_folder_image" android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<Textview android:id="@+id/grid_folder_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:gravity="center_horizontal"
android:textColor="#000000">
</Textview>
</LinearLayout>
以下文件是应用程序的网格适配器:
package it.bwpp.adapter;
import it.bwpp.activity.R;
import it.bwpp.filemgr.PictureFolder;
import java.util.List;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;
public class ImageGridAdapter extends BaseAdapter {
private Context mContext;
private List<PictureFolder> picturesFolders;
public ImageGridAdapter(Context c, List<PictureFolder> folders) {
mContext = c;
this.picturesFolders = folders;
}
public int getCount() {
return picturesFolders.size();
}
public Object getItem(int position) {
return picturesFolders.get(position);
}
public long getItemId(int position) {
return picturesFolders.get(position).getPath().hashCode();
}
// create a new ImageView for each item referenced by the Adapter
public View getView(int position, View convertView, ViewGroup parent) {
View itemView = convertView;
if (convertView == null){
LayoutInflater li = ((Activity)mContext).getLayoutInflater();
itemView = li.inflate(R.layout.grid_folder_item, null);
ImageView imageView = (ImageView)itemView.findViewById(R.id.grid_folder_image);
imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(8, 8, 8, 8);
imageView.setImageBitmap(picturesFolders.get(position).getPreviewImage());
TextView tv = (TextView) itemView.findViewById(R.id.grid_folder_name);
tv.setText(picturesFolders.get(position).getName());
} else {
itemView = convertView;
}
return itemView;
}
}
请帮助我。 再见。
Bye, I have create a GridView gallery, the grid view item is compound of a ImageView and TextView, so I have used the inflate file grid_folder_item.xml.
when the application is started is the exception thrown:
droidRuntime(286): FATAL EXCEPTION: main
11-05 12:27:37.860: E/AndroidRuntime(286): android.view.InflateException: Binary XML file line #10: Error inflating class Textview
11-05 12:27:37.860: E/AndroidRuntime(286): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:576)
11-05 12:27:37.860: E/AndroidRuntime(286): at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
11-05 12:27:37.860: E/AndroidRuntime(286): at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
11-05 12:27:37.860: E/AndroidRuntime(286): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
11-05 12:27:37.860: E/AndroidRuntime(286): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
11-05 12:27:37.860: E/AndroidRuntime(286): at it.bwpp.adapter.ImageGridAdapter.getView(ImageGridAdapter.java:44)
11-05 12:27:37.860: E/AndroidRuntime(286): at android.widget.AbsListView.obtainView(AbsListView.java:1315)
11-05 12:27:37.860: E/AndroidRuntime(286): at android.widget.GridView.onMeasure(GridView.java:932)
11-05 12:27:37.860: E/AndroidRuntime(286): at android.view.View.measure(View.java:8171)
11-05 12:27:37.860: E/AndroidRuntime(286): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
11-05 12:27:37.860: E/AndroidRuntime(286): at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
11-05 12:27:37.860: E/AndroidRuntime(286): at android.view.View.measure(View.java:8171)
11-05 12:27:37.860: E/AndroidRuntime(286): at android.widget.LinearLayout.measureVertical(LinearLayout.java:526)
11-05 12:27:37.860: E/AndroidRuntime(286): at android.widget.LinearLayout.onMeasure(LinearLayout.java:304)
11-05 12:27:37.860: E/AndroidRuntime(286): at android.view.View.measure(View.java:8171)
11-05 12:27:37.860: E/AndroidRuntime(286): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
11-05 12:27:37.860: E/AndroidRuntime(286): at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
11-05 12:27:37.860: E/AndroidRuntime(286): at android.view.View.measure(View.java:8171)
11-05 12:27:37.860: E/AndroidRuntime(286): at android.view.ViewRoot.performTraversals(ViewRoot.java:801)
11-05 12:27:37.860: E/AndroidRuntime(286): at android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
11-05 12:27:37.860: E/AndroidRuntime(286): at android.os.Handler.dispatchMessage(Handler.java:99)
11-05 12:27:37.860: E/AndroidRuntime(286): at android.os.Lo11-05 12:27:37.860: E/Anoper.loop(Looper.java:123)
11-05 12:27:37.860: E/AndroidRuntime(286): at android.app.ActivityThread.main(ActivityThread.java:4627)
11-05 12:27:37.860: E/AndroidRuntime(286): at java.lang.reflect.Method.invokeNative(Native Method)
11-05 12:27:37.860: E/AndroidRuntime(286): at java.lang.reflect.Method.invoke(Method.java:521)
11-05 12:27:37.860: E/AndroidRuntime(286): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-05 12:27:37.860: E/AndroidRuntime(286): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-05 12:27:37.860: E/AndroidRuntime(286): at dalvik.system.NativeStart.main(Native Method)
11-05 12:27:37.860: E/AndroidRuntime(286): Caused by: java.lang.ClassNotFoundException: android.view.Textview in loader dalvik.system.PathClassLoader[/data/app/it.bwpp.activity-1.apk]
11-05 12:27:37.860: E/AndroidRuntime(286): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
11-05 12:27:37.860: E/AndroidRuntime(286): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
11-05 12:27:37.860: E/AndroidRuntime(286): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
11-05 12:27:37.860: E/AndroidRuntime(286): at android.view.LayoutInflater.createView(LayoutInflater.java:466)
11-05 12:27:37.860: E/AndroidRuntime(286): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:544)
11-05 12:27:37.860: E/AndroidRuntime(286): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
11-05 12:27:37.860: E/AndroidRuntime(286): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
11-05 12:27:37.860: E/AndroidRuntime(286): ... 27 more
AVD platform and build target Android 2.2 (API level 8)
folder_item.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" >
<ImageView android:id="@+id/grid_folder_image" android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<Textview android:id="@+id/grid_folder_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:gravity="center_horizontal"
android:textColor="#000000">
</Textview>
</LinearLayout>
The following file is the grid adapter of application:
package it.bwpp.adapter;
import it.bwpp.activity.R;
import it.bwpp.filemgr.PictureFolder;
import java.util.List;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;
public class ImageGridAdapter extends BaseAdapter {
private Context mContext;
private List<PictureFolder> picturesFolders;
public ImageGridAdapter(Context c, List<PictureFolder> folders) {
mContext = c;
this.picturesFolders = folders;
}
public int getCount() {
return picturesFolders.size();
}
public Object getItem(int position) {
return picturesFolders.get(position);
}
public long getItemId(int position) {
return picturesFolders.get(position).getPath().hashCode();
}
// create a new ImageView for each item referenced by the Adapter
public View getView(int position, View convertView, ViewGroup parent) {
View itemView = convertView;
if (convertView == null){
LayoutInflater li = ((Activity)mContext).getLayoutInflater();
itemView = li.inflate(R.layout.grid_folder_item, null);
ImageView imageView = (ImageView)itemView.findViewById(R.id.grid_folder_image);
imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(8, 8, 8, 8);
imageView.setImageBitmap(picturesFolders.get(position).getPreviewImage());
TextView tv = (TextView) itemView.findViewById(R.id.grid_folder_name);
tv.setText(picturesFolders.get(position).getName());
} else {
itemView = convertView;
}
return itemView;
}
}
Help me, please.
Bye.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你有
Textview
,应该是TextView
。You have
Textview
, should beTextView
.