开发者

why i am not getting ListView data from ArrayList?

开发者 https://www.devze.com 2023-04-01 18:32 出处:网络
Here is my code of fetching the data from ArrayList : getTables=new Runnable() { @Override public void run()

Here is my code of fetching the data from ArrayList :

 getTables=new Runnable()
    {
        @Override
        public void run() 
        {
            db.open();
            try 
            {  

                tables =  db.showAllTable();    
                 for(int i=0;i<db.showAllTable().size();i++)
                 {
                        System.out.println("=====>"+(i+1));
                        System.out.println("Table :"+tables.get(i).toString());
                 }

                 customAdapter=new ImageAdapter(ListofTests.this, R.layout.list_row,tables);

            } 
            catch (Exception e) 
            {
                e.printStackTrace();
            }
            //setListAdapter(customAdapter);
            runOnUiThread(hideProgressBar);
            db.close();
        }
    };

And Here is My ImageAdapter class:

class ImageAdapter extends ArrayAdapter<Object> 
{

    private ArrayList<Object> tables;
    //ImageLoader imageLoader;
    Context m_context;
    public ImageAdapter(Context context, int textViewResourceId,ArrayList<Object> items) 
    {
        super(context, textViewResourceId, items);
        m_context=context;
        //this.tables = tables;
    }
    public View getView(final int position, View convertView, ViewGroup parent) 
    {
        View v = convertView;
        ViewHolder holder = null;

        if (v == null) 
        {

            try
            {
            holder=new ViewHolder();
            //imageLoader=new ImageLoader(CustomSearch.this);
            LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = vi.inflate(R.layout.list_row, null);
            holder.table_name=(TextView) v.findViewById(R.id.table_name);

            v.setTag(holder);

            }
            catch(Exception e)
            {
                System.out.println("Excption Caught"+e);
            }
        }
        else
            holder=(ViewHolder)v.getTag();

        Object table = tables.get(position);

        if(table!=null)
        {
            holder.table_name.setText("Hello");
        }

        return v;

    }
}

Now i dont know where i am wrong. I cant able to see the List of data in list view. Please help me regarding this. Thanks.

Error Log:

09-02 14:14:13.654: ERROR/AndroidRuntime(771): FATAL EXCEPTION: main

09-02 14:14:13.654: ERROR/AndroidRuntime(771): java.lang.NullPointerException 09-02 14:14:13.654: ERROR/AndroidRuntime(771): at com.quiz.spellingquiz.ListofTests$ImageAdapter.getView(ListofTests.java:143) 09-02 14:14:13.654: ERROR/AndroidRuntime(771): at android.widget.AbsListView.obtainView(AbsListView.java:1315) 09-02 14:14:13.654: ERROR/AndroidRuntime(771): at android.widget.ListView.measureHeightOfChildren(ListView.java:1198) 09-02 14:14:13.654: ERROR/AndroidRuntime(771): at android.widget.ListView.onMeasure(ListView.java:1109) 09-02 14:14:13.654: ERROR/AndroidRuntime(771): at android.view.View.measure(View.java:8171) 09-02 14:14:13.654: ERROR/AndroidRuntime(771): at android.widget.RelativeLayout.measureChild(RelativeLayout.java:563) 09-02 14:14:13.654: ERROR/AndroidRuntime(771): at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:378) 09-02 14:14:13.654: ERROR/AndroidRuntime(771): at android.view.View.measure(View.java:8171) 09-02 14:14:13.654: ERROR/AndroidRuntime(771): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132) 09-02 14:14:13.654: ERROR/AndroidRuntime(771): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1012) 09-02 14:14:13.654: ERROR/AndroidRuntime(771): at android.widget.LinearLayout.measureVertical(LinearLayout.java:381) 09-02 14:14:13.654: ERROR/AndroidRuntime(771): at android.widget.LinearLayout.onMeasure(LinearLayout.java:304) 09-02 14:14:13.654: ERROR/AndroidRuntime(771): at android.view.View.measure(View.java:8171) 09-02 14:14:13.654: ERROR/AndroidRuntime(771): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132) 09-02 14:14:13.654: ERROR/AndroidRuntime(771): at android.widget.FrameLayout.onMeasure(FrameLayout.java:245) 09-02 14:14:13.654: ERROR/AndroidRuntime(771): at android.view.View.measure(View.java:8171) 09-02 14:14:13.654: ERROR/AndroidRuntime(771): at android.widget.LinearLayout.measureVertical(LinearLayout.java:526) 09-02 14:14:13.开发者_开发问答654: ERROR/AndroidRuntime(771): at android.widget.LinearLayout.onMeasure(LinearLayout.java:304) 09-02 14:14:13.654: ERROR/AndroidRuntime(771): at android.view.View.measure(View.java:8171) 09-02 14:14:13.654: ERROR/AndroidRuntime(771): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132) 09-02 14:14:13.654: ERROR/AndroidRuntime(771): at android.widget.FrameLayout.onMeasure(FrameLayout.java:245) 09-02 14:14:13.654: ERROR/AndroidRuntime(771): at android.view.View.measure(View.java:8171) 09-02 14:14:13.654: ERROR/AndroidRuntime(771): at android.view.ViewRoot.performTraversals(ViewRoot.java:801) 09-02 14:14:13.654: ERROR/AndroidRuntime(771): at android.view.ViewRoot.handleMessage(ViewRoot.java:1727) 09-02 14:14:13.654: ERROR/AndroidRuntime(771): at android.os.Handler.dispatchMessage(Handler.java:99) 09-02 14:14:13.654: ERROR/AndroidRuntime(771): at android.os.Looper.loop(Looper.java:123) 09-02 14:14:13.654: ERROR/AndroidRuntime(771): at android.app.ActivityThread.main(ActivityThread.java:4627) 09-02 14:14:13.654: ERROR/AndroidRuntime(771): at java.lang.reflect.Method.invokeNative(Native Method) 09-02 14:14:13.654: ERROR/AndroidRuntime(771): at java.lang.reflect.Method.invoke(Method.java:521) 09-02 14:14:13.654: ERROR/AndroidRuntime(771): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 09-02 14:14:13.654: ERROR/AndroidRuntime(771): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 09-02 14:14:13.654: ERROR/AndroidRuntime(771): at dalvik.system.NativeStart.main(Native Method)


You never set tables in your Adapter

I think you want this:

 public ImageAdapter(Context context, int textViewResourceId,ArrayList<Object> items) 
    {
        super(context, textViewResourceId, items);
        m_context=context;
        this.tables = items; // set to items instead of tables (which doesnt exist in the argument list)
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消