排除NullPointerException
我正在使用volley.jar编译时没有错误,但有运行时异常。
并添加volley.jar并添加构建路径。 什么是问题?
java.lang.NullPointerException at com.android.volley.toolbox.NetworkImageView.loadImageIfNecessary(NetworkImageView.java:150)at com.android.volley.toolbox.NetworkImageView.onLayout(NetworkImageView.java:199)at android.view.View。在android.widget.LinearLayout.onLayout(LinearLayout.java:1671)上的android.widget.LinearLayout.setChildFrame(LinearLayout.java:1682)的布局(View.java:14898) :1447)at android.view.View.layout(View.java:14898)at android.view.ViewGroup.layout(ViewGroup.java:4676)at android.widget.ListView.setupChild(ListView.java:1894)at android .widget.ListView.makeAndAddView(ListView.java:1805)at android.widget.ListView.fillDown(ListView.java:698)at android.widget.ListView.fillFromTop(ListView.java:759)at android.widget.ListView。 layout.Children(ListView.java:1637)at android.widget.AbsListView.onLayout(AbsListView.java:2144)at android.view.View.layout(View.java:14898)at android.view.ViewGroup.layout(ViewGro android.widget.LinearLayout.setLineout.java:1445(android.widget.Lineout.java:1682)android.widget.LinearLayout.layoutVertical(LinearLayout.java:1536)android.widget.LinearLayout.onLayout(LinearLayout.java:1445) )在android.widget上的android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)上的android.view.ViewGroup.layout(ViewGroup.java:4676)上的android.view.View.layout(View.java:14898) .framework.ayout.onLayout(FrameLayout.java:388)at android.view.View.layout(View.java:14898)at android.view.ViewGroup.layout(ViewGroup.java:4676)at android.widget.FrameLayout.layoutChildren( (android.view.java:14898)android.view.ViewGroup.layout(ViewGroup.java:4676)在android.widget.FrameLayout.onLayout(FrameLayout.java:388)上的FrameLayout.java:453) )在android.view.View.Group.layout(ViewGroup.java:4676)处的android.view.View.layout(View.java:14898)处的android.support.v4.view.ViewPager.onLayout(ViewPager.java:1594)在android.widget.RelativeLayout.onLayout(RelativeLayout.java:10 55)android.view.View.layout(View.java:14898)在android.view.ViewGroup.layout(ViewGroup.java:4676)android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)在android。 widget.FrameLayout.onLayout(FrameLayout.java:388)at android.view.View.layout(View.java:14898)at android.view.ViewGroup.layout(ViewGroup.java:4676)at com.android.internal.widget .ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:374)at android.view.View.layout(View.java:14898)at android.view.ViewGroup.layout(ViewGroup.java:4676)at android.widget.FrameLayout.layoutChildren( (android.view.java:14898)android.view.ViewGroup.layout(ViewGroup.java:4676)在android.widget.FrameLayout.onLayout(FrameLayout.java:388)上的FrameLayout.java:453) )at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2014)at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1771)at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1013)at android.view .ViewRootImpl $ TraversalRunnabl e.run(ViewRootImpl.java:5746)at android.view.Choreographer $ CallbackRecord.run(Choreographer.java:761)at android.view.Choreographer.doCallbacks(Choreographer.java:574)at android.view.Choreographer.doFrame (Choreographer.java:544)at android.view.Choreographer $ FrameDisplayEventReceiver.run(Choreographer.java:747)at android.os.Handler.handleCallback(Handler.java:733)at android.os.Handler.dispatchMessage(Handler。 java:95)在android.os.Looper.loop(Looper.java:136)在android.app.ActivityThread.main(ActivityThread.java:5068)在java.lang.reflect.Method.invokeNative(本地方法)在java 。com.android.internal.os.ZygoteInit.main(ZygoteInit)上的com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:792).lang.reflect.Method.invoke(Method.java:515) .java:608)at dalvik.system.NativeStart.main(Native Method)
CustomAdapter.java
public class CustomAdapter extends BaseAdapter {
Context context;
List<Games> rowItems;
public CustomAdapter(Context context, List<Games> rowItems) {
this.context = context;
this.rowItems = rowItems;
}
@Override
public int getCount() {
return rowItems.size();
}
@Override
public Object getItem(int position) {
return rowItems.get(position);
}
@Override
public long getItemId(int position) {
return rowItems.indexOf(getItem(position));
}
/* private view holder class */
private class ViewHolder {
NetworkImageView profile_pic;
TextView member_name;
TextView status;
TextView contactType;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
LayoutInflater mInflater = (LayoutInflater) context
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = mInflater.inflate(R.layout.list_item, null);
holder = new ViewHolder();
holder.member_name = (TextView) convertView
.findViewById(R.id.member_name);
holder.profile_pic = (NetworkImageView) convertView
.findViewById(R.id.profile_pic);
holder.status = (TextView) convertView.findViewById(R.id.status);
holder.contactType = (TextView) convertView
.findViewById(R.id.contact_type);
Games row_pos = rowItems.get(position);
ImageLoader il = VolleySingleton.getInstance().getImageLoader();
holder.profile_pic.setImageUrl(IMAGE_URL ,il);
holder.member_name.setText(row_pos.getChampionId());
holder.status.setText(row_pos.getGameMode());
holder.contactType.setText(row_pos.getStats().getItem0());
Log.d("aaa", "position : " + position );
Log.d("aaa", "row_pos.getChampionId()" + row_pos.getChampionId());
Log.d("aaa", "row_pos.getGameMode()" + row_pos.getGameMode());
Log.d("aaa", "row_pos.getStats().getItem0()" + row_pos.getStats().getItem0());
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
Games row_pos = rowItems.get(position);
ImageLoader il = VolleySingleton.getInstance().getImageLoader();
holder.profile_pic.setImageUrl(IMAGE_URL,il);
holder.member_name.setText(row_pos.getChampionId());
holder.status.setText(row_pos.getGameMode());
holder.contactType.setText(row_pos.getStats().getItem0());
Log.d("aaa", "position : " + position );
Log.d("aaa", "row_pos.getChampionId()" + row_pos.getChampionId());
Log.d("aaa", "row_pos.getGameMode()" + row_pos.getGameMode());
Log.d("aaa", "row_pos.getStats().getItem0()" + row_pos.getStats().getItem0());
}
return convertView;
}
}
list_item.xml
的LinearLayout
<com.android.volley.toolbox.NetworkImageView
android:id="@+id/profile_pic"
android:layout_width="70dp"
android:layout_height="70dp"
android:contentDescription="desc"
android:paddingLeft="10dp"
android:paddingRight="10dp" />
<TextView
android:id="@+id/member_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_toRightOf="@+id/profile_pic"
android:paddingBottom="10dp"
android:text="txt"
android:textSize="20sp" />
<TextView
android:id="@+id/status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/member_name"
android:layout_below="@+id/member_name"
android:text="txt"
android:textSize="16sp" />
<TextView
android:id="@+id/contact_type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/member_name"
android:layout_alignBottom="@+id/member_name"
android:layout_alignParentRight="true"
android:text="txt" />
我解决了这个问题。 这段代码运行良好,在我的volleysingleton类getImageLoader方法中有一些错误。
链接地址: http://www.djcxy.com/p/16635.html上一篇: volley NullPointerException
下一篇: TextView with custom style causing strange inflate exception