当我尝试测试我的应用程序时,我的LazyAdapter类在尝试将文本分配给textView时似乎有错误。请帮我。我不知道出了什么问题。代码似乎是正确的,Eclipse没有向我显示我的结构中的任何错误。谢谢大家
import java.util.List;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ArrayAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;
public class LazyAdapter extends ArrayAdapter<RowItem> {
Context context;
public LazyAdapter(Context context, int resourceId, List<RowItem> items){
super(context, resourceId, items);
this.context = context;
}
public class ViewHolder{
TextView title;
TextView description;
TextView fine;
TextView courtApp;
RelativeLayout card;
}
public View getView(int position, View convertView, ViewGroup parent){
ViewHolder holder;
RowItem rowItem = getItem(position);
LayoutInflater mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null){
convertView = mInflater.inflate(R.layout.listview_element, null);
holder = new ViewHolder();
holder.card = (RelativeLayout) convertView.findViewById(R.id.card);
holder.fine = (TextView)convertView.findViewById(R.id.fine);
holder.title = (TextView)convertView.findViewById(R.id.title);
holder.description = (TextView)convertView.findViewById(R.id.description);
holder.courtApp = (TextView)convertView.findViewById(R.id.court_appearance);
convertView.setTag(holder);
}
else
holder = (ViewHolder)convertView.getTag();
holder.title.setText(rowItem.getTitle());
holder.description.setText(rowItem.getDesc());
holder.fine.setText(rowItem.getFine());
holder.courtApp.setText(rowItem.getCourtApp());
Animation animation = AnimationUtils.loadAnimation(context, R.anim.card_animation);
holder.card.startAnimation(animation);
return convertView;
}
}
以下是Logcat向我显示的错误。
02-27 02:44:27.228: E/AndroidRuntime(21918): java.lang.NullPointerException
02-27 02:44:27.228: E/AndroidRuntime(21918): at com.gordondev.nyctlchackprep.LazyAdapter.getView(LazyAdapter.java:53)
02-27 02:44:27.228: E/AndroidRuntime(21918): at android.widget.AbsListView.obtainView(AbsListView.java:2181)
02-27 02:44:27.228: E/AndroidRuntime(21918): at android.widget.ListView.makeAndAddView(ListView.java:1880)
02-27 02:44:27.228: E/AndroidRuntime(21918): at android.widget.ListView.fillDown(ListView.java:687)
02-27 02:44:27.228: E/AndroidRuntime(21918): at android.widget.ListView.fillDown(ListView.java:666)
02-27 02:44:27.228: E/AndroidRuntime(21918): at android.widget.ListView.fillFromTop(ListView.java:758)
02-27 02:44:27.228: E/AndroidRuntime(21918): at android.widget.ListView.layoutChildren(ListView.java:1695)
02-27 02:44:27.228: E/AndroidRuntime(21918): at android.widget.AbsListView.onLayout(AbsListView.java:2016)
02-27 02:44:27.228: E/AndroidRuntime(21918): at android.view.View.layout(View.java:14471)
02-27 02:44:27.228: E/AndroidRuntime(21918): at android.view.ViewGroup.layout(ViewGroup.java:4562)
02-27 02:44:27.228: E/AndroidRuntime(21918): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
02-27 02:44:27.228: E/AndroidRuntime(21918): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)
02-27 02:44:27.228: E/AndroidRuntime(21918): at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
02-27 02:44:27.228: E/AndroidRuntime(21918): at android.view.View.layout(View.java:14471)
02-27 02:44:27.228: E/AndroidRuntime(21918): at android.view.ViewGroup.layout(ViewGroup.java:4562)
02-27 02:44:27.228: E/AndroidRuntime(21918): at android.widget.FrameLayout.onLayout(FrameLayout.java:452)
02-27 02:44:27.228: E/AndroidRuntime(21918): at android.view.View.layout(View.java:14471)
02-27 02:44:27.228: E/AndroidRuntime(21918): at android.view.ViewGroup.layout(ViewGroup.java:4562)
02-27 02:44:27.228: E/AndroidRuntime(21918): at android.support.v4.view.ViewPager.onLayout(ViewPager.java:1589)
02-27 02:44:27.228: E/AndroidRuntime(21918): at android.view.View.layout(View.java:14471)
02-27 02:44:27.228: E/AndroidRuntime(21918): at android.view.ViewGroup.layout(ViewGroup.java:4562)
02-27 02:44:27.228: E/AndroidRuntime(21918): at android.widget.FrameLayout.onLayout(FrameLayout.java:452)
02-27 02:44:27.228: E/AndroidRuntime(21918): at android.view.View.layout(View.java:14471)
02-27 02:44:27.228: E/AndroidRuntime(21918): at android.view.ViewGroup.layout(ViewGroup.java:4562)
02-27 02:44:27.228: E/AndroidRuntime(21918): at com.android.internal.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:349)
02-27 02:44:27.228: E/AndroidRuntime(21918): at android.view.View.layout(View.java:14471)
02-27 02:44:27.228: E/AndroidRuntime(21918): at android.view.ViewGroup.layout(ViewGroup.java:4562)
02-27 02:44:27.228: E/AndroidRuntime(21918): at android.widget.FrameLayout.onLayout(FrameLayout.java:452)
02-27 02:44:27.228: E/AndroidRuntime(21918): at android.view.View.layout(View.java:14471)
02-27 02:44:27.228: E/AndroidRuntime(21918): at android.view.ViewGroup.layout(ViewGroup.java:4562)
02-27 02:44:27.228: E/AndroidRuntime(21918): at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1984)
02-27 02:44:27.228: E/AndroidRuntime(21918): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1738)
02-27 02:44:27.228: E/AndroidRuntime(21918): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1008)
02-27 02:44:27.228: E/AndroidRuntime(21918): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5505)
02-27 02:44:27.228: E/AndroidRuntime(21918): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
02-27 02:44:27.228: E/AndroidRuntime(21918): at android.view.Choreographer.doCallbacks(Choreographer.java:562)
02-27 02:44:27.228: E/AndroidRuntime(21918): at android.view.Choreographer.doFrame(Choreographer.java:532)
02-27 02:44:27.228: E/AndroidRuntime(21918): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
02-27 02:44:27.228: E/AndroidRuntime(21918): at android.os.Handler.handleCallback(Handler.java:730)
02-27 02:44:27.228: E/AndroidRuntime(21918): at android.os.Handler.dispatchMessage(Handler.java:92)
02-27 02:44:27.228: E/AndroidRuntime(21918): at android.os.Looper.loop(Looper.java:213)
02-27 02:44:27.228: E/AndroidRuntime(21918): at android.app.ActivityThread.main(ActivityThread.java:5225)
02-27 02:44:27.228: E/AndroidRuntime(21918): at java.lang.reflect.Method.invokeNative(Native Method)
02-27 02:44:27.228: E/AndroidRuntime(21918): at java.lang.reflect.Method.invoke(Method.java:525)
02-27 02:44:27.228: E/AndroidRuntime(21918): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
02-27 02:44:27.228: E/AndroidRuntime(21918): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
02-27 02:44:27.228: E/AndroidRuntime(21918): at dalvik.system.NativeStart.main(Native Method)
02-27 02:49:27.658: I/Process(21918): Sending signal. PID: 21918 SIG: 9
我弄清楚问题是什么。它是与xml布局文件。我指的是错误的xml文件。特别感谢InnocentKiller。
答案 0 :(得分:0)
private List<RowItem> items;
public LazyAdapter(Context context, int resourceId, List<RowItem> items){
super(context, resourceId, items);
this.context = context;this.items=items; }RowItem rowItem = items.get(position);