Saturday 24 August 2013

Strange issue filling up a customized listView

Strange issue filling up a customized listView

Im having some problems trying to fill my listView. The entries of the
listviews have an special design cause are for youtube´s videos. They are
composed of two strings (title and description) and image. I get a
nullPointerException, but I havent been able to find out the reason yet.
listVideos its filled properly, using a thread which connects with youtube
and using JSON gets every video in a playlist. videosListView is a normal
listView and R.layout.entry is a linearLayout containing an image and
another linearLayout(Video title and description).
My code:
private void fillListView(Message msg){
ArrayList<Video> listVideos = (ArrayList)
msg.getData().get("VideosList");
videosListView.setAdapter(new AdapterList(context, R.layout.entry,
listVideos){
@Override
public void onEntry(Object entry, View view) {
if (entry != null) {
TextView superiorText = (TextView)
view.findViewById(R.id.textView_superior);
if (superiorText != null)
superiorText.setText(((Video) entry).getTitle());
TextView inferiorText = (TextView)
view.findViewById(R.id.textView_inferior);
if (inferiorText != null)
inferiorText.setText(((Video) entry).getUrl());
ImageView thumb = (ImageView)
view.findViewById(R.id.imageView_imagen);
String aux = ((Video)entry).getThumbUrl();
ImageDownloader downloader = new ImageDownloader();
downloader.download(aux, thumb);
}
}
});`
Just in case, adapterList class looks like this:
public abstract class AdapterList extends BaseAdapter{
private ArrayList<?> entries;
private int R_layout_IdView;
private Context context;
public AdapterList(Context context, int R_layout_IdView, ArrayList<?> entry){
super();
this.entries = entry;
this.R_layout_IdView = R_layout_IdView;
this.context = context;
}
@Override
public View getView(int posicion, View view, ViewGroup pariente) {
if (view == null) {
LayoutInflater vi = (LayoutInflater)
context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = vi.inflate(R_layout_IdView, null);
}
onEntry (entries.get(posicion), view);
return view;
}
@Override
public int getCount() {
return entries.size();
}
@Override
public Object getItem(int position) {
return entries.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
public abstract void onEntry(Object object, View view);
}
The error log:
08-24 13:34:51.828: E/AndroidRuntime(7580): FATAL EXCEPTION: main
08-24 13:34:51.828: E/AndroidRuntime(7580): java.lang.NullPointerException
08-24 13:34:51.828: E/AndroidRuntime(7580): at
guidelines.youtube.Youtube.fillListView(Youtube.java:67)
08-24 13:34:51.828: E/AndroidRuntime(7580): at
guidelines.youtube.Youtube.access$0(Youtube.java:63)
08-24 13:34:51.828: E/AndroidRuntime(7580): at
guidelines.youtube.Youtube$1.handleMessage(Youtube.java:59)
08-24 13:34:51.828: E/AndroidRuntime(7580): at
android.os.Handler.dispatchMessage(Handler.java:99)
08-24 13:34:51.828: E/AndroidRuntime(7580): at
android.os.Looper.loop(Looper.java:137)
08-24 13:34:51.828: E/AndroidRuntime(7580): at
android.app.ActivityThread.main(ActivityThread.java:4645)
08-24 13:34:51.828: E/AndroidRuntime(7580): at
java.lang.reflect.Method.invokeNative(Native Method)
08-24 13:34:51.828: E/AndroidRuntime(7580): at
java.lang.reflect.Method.invoke(Method.java:511)
08-24 13:34:51.828: E/AndroidRuntime(7580): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:809)
08-24 13:34:51.828: E/AndroidRuntime(7580): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576)
08-24 13:34:51.828: E/AndroidRuntime(7580): at
dalvik.system.NativeStart.main(Native Method)
Any idea where the error comes from?? Thanks!

No comments:

Post a Comment