Android popup window list view

953 Views Asked by At

I have a popup window in my project. I got a groups posts in a listview. If i click a post in listview a popup window will open and it includes post,post comments and likes; user can like and write comment for that post in that window. But i couldn't bind my comment datas to popup window's listview. Below is my codes and logcat data:

ListView lstcomment = (ListView)popup.getContentView().findViewById(R.id.lstcomments);
            CommentAdapter cmm = new CommentAdapter(this, commentarName, commentarPicture, commentarComment);
            System.out.println(cmm.getCount());
            if(cmm.getCount()>0)
            {
                lstcomment.setAdapter(cmm);
            }
            else
            {
                lstcomment.setVisibility(View.GONE);
                nocomment.setVisibility(View.VISIBLE);
            }

Logcat

08-25 02:54:27.680: E/AndroidRuntime(21581): FATAL EXCEPTION: main
08-25 02:54:27.680: E/AndroidRuntime(21581): java.lang.NullPointerException
08-25 02:54:27.680: E/AndroidRuntime(21581):    at com.invemo.vodafonelivecoursetest.CommentAdapter.getCount(CommentAdapter.java:39)
08-25 02:54:27.680: E/AndroidRuntime(21581):    at com.invemo.vodafonelivecoursetest.MainActivity.showFbPopup(MainActivity.java:1342)
08-25 02:54:27.680: E/AndroidRuntime(21581):    at com.invemo.vodafonelivecoursetest.MainActivity.access$9(MainActivity.java:1297)
08-25 02:54:27.680: E/AndroidRuntime(21581):    at com.invemo.vodafonelivecoursetest.MainActivity$3.onItemClick(MainActivity.java:343)
08-25 02:54:27.680: E/AndroidRuntime(21581):    at android.widget.AdapterView.performItemClick(AdapterView.java:315)
08-25 02:54:27.680: E/AndroidRuntime(21581):    at android.widget.AbsListView.performItemClick(AbsListView.java:1058)
08-25 02:54:27.680: E/AndroidRuntime(21581):    at android.widget.AbsListView$PerformClick.run(AbsListView.java:2514)
08-25 02:54:27.680: E/AndroidRuntime(21581):    at android.widget.AbsListView$1.run(AbsListView.java:3168)
08-25 02:54:27.680: E/AndroidRuntime(21581):    at android.os.Handler.handleCallback(Handler.java:605)
08-25 02:54:27.680: E/AndroidRuntime(21581):    at android.os.Handler.dispatchMessage(Handler.java:92)
08-25 02:54:27.680: E/AndroidRuntime(21581):    at android.os.Looper.loop(Looper.java:137)
08-25 02:54:27.680: E/AndroidRuntime(21581):    at android.app.ActivityThread.main(ActivityThread.java:4425)
08-25 02:54:27.680: E/AndroidRuntime(21581):    at java.lang.reflect.Method.invokeNative(Native Method)
08-25 02:54:27.680: E/AndroidRuntime(21581):    at java.lang.reflect.Method.invoke(Method.java:511)
08-25 02:54:27.680: E/AndroidRuntime(21581):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-25 02:54:27.680: E/AndroidRuntime(21581):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:606)
08-25 02:54:27.680: E/AndroidRuntime(21581):    at dalvik.system.NativeStart.main(Native Method)

If i write my comment data to logcat via System.out.println i can get data but i couldn't wrote them to listview.

My Adapter's code:

package com.invemo.vodafonelivecoursetest;


public class CommentAdapter extends BaseAdapter {

private Activity activity;
private String[]  profilePicture;
private String[] contentMessage;
private String[] sender;
private static LayoutInflater inflater=null;
public ImageLoader imageLoader; 

public CommentAdapter(Activity a, String[] senders, String[] profilePictures, String[] announceContents) {
    activity = a;
    this.profilePicture=profilePictures;
    this.contentMessage=announceContents;
    this.sender=senders;
    inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    imageLoader=new ImageLoader(activity.getApplicationContext());
}



@Override
public int getCount() {
    return sender.length;
}

@Override
public Object getItem(int position) {
    return position;
}

@Override
public long getItemId(int position) {
    return position;
}
public static class ViewHolder {
    public TextView textTitle;
    public ImageView image;
    public TextView contentArea;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {

    View vi = convertView;
    ViewHolder holder;
    if (convertView == null) {
        vi = inflater.inflate(R.layout.announce_item, null);
        holder = new ViewHolder();
        holder.textTitle = (TextView) vi.findViewById(R.id.textView1);
        holder.image = (ImageView) vi.findViewById(R.id.imageView1);
        holder.contentArea=(TextView)vi.findViewById(R.id.textView2);
        vi.setTag(holder);
    } else
        holder = (ViewHolder) vi.getTag();

    holder.textTitle.setText(sender[position]);
    holder.contentArea.setText(contentMessage[position]);
    holder.contentArea.setAutoLinkMask(Linkify.WEB_URLS);
    holder.image.setTag(profilePicture[position]);
    imageLoader.DisplayImage(profilePicture[position], activity, holder.image);
    return vi;
}

}
1

There are 1 best solutions below

3
On

It looks like commentarName must be null. Are you sure you are assigning it a value before the count method calls .length on it?