volley NullPointerException
i am using volley.jar there's no error on compile time but there's runtime exception.
and i add volley.jar and add build path. what is problem?
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.layout(View.java:14898) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1682) at android.widget.LinearLayout.layoutHorizontal(LinearLayout.java:1671) at android.widget.LinearLayout.onLayout(LinearLayout.java: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.layoutChildren(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 up.java:4676) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1682) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1536) at android.widget.LinearLayout.onLayout(LinearLayout.java:1445) at android.view.View.layout(View.java:14898) at android.view.ViewGroup.layout(ViewGroup.java:4676) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453) at android.widget.FrameLayout.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(FrameLayout.java:453) at android.widget.FrameLayout.onLayout(FrameLayout.java:388) at android.view.View.layout(View.java:14898) at android.view.ViewGroup.layout(ViewGroup.java:4676) at android.support.v4.view.ViewPager.onLayout(ViewPager.java:1594) at android.view.View.layout(View.java:14898) at android.view.ViewGroup.layout(ViewGroup.java:4676) at android.widget.RelativeLayout.onLayout(RelativeLayout.java:10 55) at android.view.View.layout(View.java:14898) at android.view.ViewGroup.layout(ViewGroup.java:4676) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453) at 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(FrameLayout.java:453) at android.widget.FrameLayout.onLayout(FrameLayout.java:388) at android.view.View.layout(View.java:14898) at android.view.ViewGroup.layout(ViewGroup.java:4676) 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) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5068) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792) at com.android.internal.os.ZygoteInit.main(ZygoteInit.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" />
I solved this problems. There's some errors in my volleysingleton class getImageLoader method this code run well.
链接地址: http://www.djcxy.com/p/16636.html