Android GridView android.view.InflateException: двоичное исключение XML - PullRequest
0 голосов
/ 05 ноября 2011

Пока, я создал галерею 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.

1 Ответ

4 голосов
/ 05 ноября 2011

У вас есть Textview, должно быть TextView.

...