我无法理解 logcat 中出现的这个错误
日志错误:
11-20 18:45:42.125: E/AndroidRuntime(458): 致命异常: main 11-20 18:45:42.125: E/AndroidRuntime(458): java.lang.ClassCastException: android.widget.ImageView 11-20 18:45:42.125: E/AndroidRuntime(458): 在 com.example.orderplacemnet.Product_Details$MyProductAdapter.getView(Product_Details.java:75) 11-20 18:45:42.125: E/AndroidRuntime(458): 在 android .widget.AbsListView.obtainView(AbsListView.java:1315) 11-20 18:45:42.125: E/AndroidRuntime(458): at android.widget.ListView.measureHeightOfChildren(ListView.java:1198) 11-20 18:45 :42.125: E/AndroidRuntime(458): 在 android.widget.ListView.onMeasure(ListView.java:1109) 11-20 18:45:42.125: E/AndroidRuntime(458): 在 android.view.View.measure( View.java:8171) 11-20 18:45:42.125: E/AndroidRuntime(458): 在 android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132) 11-20 18:45:42.125:E/AndroidRuntime(458): 在 android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1012) 11-20 18:45:42.125: E/AndroidRuntime(458): 在 android.widget.LinearLayout.measureVertical(LinearLayout.java :381) 11-20 18:45:42.125: E/AndroidRuntime(458): 在 android.widget.LinearLayout.onMeasure(LinearLayout.java:304) 11-20 18:45:42.125: E/AndroidRuntime(458):在 android.view.View.measure(View.java:8171) 11-20 18:45:42.125: E/AndroidRuntime(458): 在 android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132) 11-20 18 :45:42.125: E/AndroidRuntime(458): 在 android.widget.FrameLayout.onMeasure(FrameLayout.java:245) 11-20 18:45:42.125: E/AndroidRuntime(458): 在 android.view.View。测量(View.java:8171)11-20 18:45:42.125:E/AndroidRuntime(458):在 android.widget.LinearLayout.measureVertical(LinearLayout.java:526)11-20 18:45:42.125:E/AndroidRuntime(458): 在 android.widget.LinearLayout.onMeasure(LinearLayout.java:304) 11-20 18:45:42.125: E/AndroidRuntime(458): 在 android.view.View.measure(View.java :8171) 11-20 18:45:42.125: E/AndroidRuntime(458): 在 android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132) 11-20 18:45:42.125: E/AndroidRuntime(458):在 android.widget.FrameLayout.onMeasure(FrameLayout.java:245) 11-20 18:45:42.125: E/AndroidRuntime(458): 在 android.view.View.measure(View.java:8171) 11-20 18 :45:42.125: E/AndroidRuntime(458): 在 android.view.ViewRoot.performTraversals(ViewRoot.java:801) 11-20 18:45:42.125: E/AndroidRuntime(458): 在 android.view.ViewRoot。 handleMessage(ViewRoot.java:1727) 11-20 18:45:42.125: E/AndroidRuntime(458): 在 android.os.Handler.dispatchMessage(Handler.java:99) 11-20 18:45:42.125: E/ AndroidRuntime(458):在 android.os。Looper.loop(Looper.java:123) 11-20 18:45:42.125: E/AndroidRuntime(458): 在 android.app.ActivityThread.main(ActivityThread.java:4627) 11-20 18:45:42.125: E/AndroidRuntime(458): at java.lang.reflect.Method.invokeNative(Native Method) 11-20 18:45:42.125: E/AndroidRuntime(458): at java.lang.reflect.Method.invoke(Method. java:521) 11-20 18:45:42.125: E/AndroidRuntime(458): 在 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 11-20 18:45:42.125: E/AndroidRuntime(458): 在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 11-20 18:45:42.125: E/AndroidRuntime(458): 在 dalvik.system.NativeStart.main (本机方法)invokeNative(本机方法)11-20 18:45:42.125:E/AndroidRuntime(458):在 java.lang.reflect.Method.invoke(Method.java:521)11-20 18:45:42.125:E/AndroidRuntime (458): 在 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 11-20 18:45:42.125: E/AndroidRuntime(458): 在 com.android.internal.os。 ZygoteInit.main(ZygoteInit.java:626) 11-20 18:45:42.125: E/AndroidRuntime(458): at dalvik.system.NativeStart.main(Native Method)invokeNative(本机方法)11-20 18:45:42.125:E/AndroidRuntime(458):在 java.lang.reflect.Method.invoke(Method.java:521)11-20 18:45:42.125:E/AndroidRuntime (458): 在 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 11-20 18:45:42.125: E/AndroidRuntime(458): 在 com.android.internal.os。 ZygoteInit.main(ZygoteInit.java:626) 11-20 18:45:42.125: E/AndroidRuntime(458): at dalvik.system.NativeStart.main(Native Method)在 dalvik.system.NativeStart.main(本机方法)在 dalvik.system.NativeStart.main(本机方法)
package com.example.orderplacemnet;
import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
public class Product_Details extends Activity
{
String[] text = { "One", "Two", "Three", "Four", "Five"};
int[] image = { R.drawable.rose_five, R.drawable.rose, R.drawable.rose_two,
R.drawable.rose_three, R.drawable.rose_four};
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_product__details);
ListView l1 = (ListView) findViewById(R.id.ListView01);
l1.setAdapter(new MyProductAdapter(text,image));
}
class MyProductAdapter extends BaseAdapter
{
String[] data_text;
int[] data_image;
MyProductAdapter()
{
data_text = null;
data_image = null;
}
MyProductAdapter(String[] text, int[] image)
{
data_text = text;
data_image = image;
}
public int getCount()
{
return data_text.length;
}
public String getItem(int position)
{
return null;
}
public long getItemId(int position)
{
return position;
}
public View getView(int position, View convertView, ViewGroup parent)
{
LayoutInflater inflater = getLayoutInflater();
View row;
row = inflater.inflate(R.layout.listview, parent, false);
TextView textview = (TextView) row.findViewById(R.id.TextView01);
ImageView imageview = (ImageView) row.findViewById(R.id.ImageView01);
textview.setText(data_text[position]);
imageview.setImageResource(data_image[position]);
return (row);
}
}
}
这是我的列表行布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#fff200"
android:gravity="left|center"
android:paddingBottom="5dp"
android:paddingLeft="5dp"
android:paddingTop="5dp" >
<TextView
android:id="@+id/TextView01"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginLeft="10dp"
android:textSize="20dp"
android:textStyle="bold" >
</TextView>
<ImageView
android:id="@+id/ImageView01"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.76"
android:contentDescription="@string/productlist" />
</LinearLayout>