的NullPointerException

的NullPointerException

我的NullPointerException得到了ArrayAdapter。我从连接到本地主机的数据库中获取一个值,当我将该值发布到日志cat并删除textview.settext("something")时,我的错误就消失了。但当我初始化TextView并在其中放入一些内容时,错误再次出现。
这是我的片段:

public class MySimpleArrayAdapter extends ArrayAdapter<String> {
    private final Context context;
    private final List<String> values;
    //private final List<String> arr;

    public MySimpleArrayAdapter(Context context, List<String> values) {
        super(context, R.layout.rowlayout, values);
        this.context = context;
        this.values = values;
    }

    static class ViewHolder {
        public TextView text;
        public ImageView image;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Log.i("List",values.get(position).toString());
        LayoutInflater inflater = (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        ViewHolder viewHolder = new ViewHolder();
        View rowView = inflater.inflate(R.layout.rowlayout, parent, false);
        TextView textView = (TextView) rowView.findViewById(R.id.txtlarge);
        textView.setText("hahhaha");

        return rowView;
    }

    private Drawable LoadImageFromWebOperations(String url)
    {
        try
        {
            InputStream is = (InputStream) new URL(url).getContent();
            Drawable d = Drawable.createFromStream(is, "src name");
            return d;
        }
        catch (Exception e)
        {
            Log.w("LoadImageFromWebOperations",e.toString());
            return null;
        }
    }
}

我的错误在这里:
07-09 02:20:47.433: E/AndroidRuntime(1168): FATAL EXCEPTION: main
07-09 02:20:47.433: E/AndroidRuntime(1168): java.lang.NullPointerException
07-09 02:20:47.433: E/AndroidRuntime(1168):     at com.database_demo.MySimpleArrayAdapter.getView(MySimpleArrayAdapter.java:57)
07-09 02:20:47.433: E/AndroidRuntime(1168):     at android.widget.AbsListView.obtainView(AbsListView.java:1315)
07-09 02:20:47.433: E/AndroidRuntime(1168):     at android.widget.ListView.makeAndAddView(ListView.java:1727)
07-09 02:20:47.433: E/AndroidRuntime(1168):     at android.widget.ListView.fillDown(ListView.java:652)
07-09 02:20:47.433: E/AndroidRuntime(1168):     at android.widget.ListView.fillFromTop(ListView.java:709)
07-09 02:20:47.433: E/AndroidRuntime(1168):     at android.widget.ListView.layoutChildren(ListView.java:1580)
07-09 02:20:47.433: E/AndroidRuntime(1168):     at android.widget.AbsListView.onLayout(AbsListView.java:1147)
07-09 02:20:47.433: E/AndroidRuntime(1168):     at android.view.View.layout(View.java:7035)
07-09 02:20:47.433: E/AndroidRuntime(1168):     at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
07-09 02:20:47.433: E/AndroidRuntime(1168):     at android.view.View.layout(View.java:7035)
07-09 02:20:47.433: E/AndroidRuntime(1168):     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1249)
07-09 02:20:47.433: E/AndroidRuntime(1168):     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1125)
07-09 02:20:47.433: E/AndroidRuntime(1168):     at android.widget.LinearLayout.onLayout(LinearLayout.java:1042)
07-09 02:20:47.433: E/AndroidRuntime(1168):     at android.view.View.layout(View.java:7035)
07-09 02:20:47.433: E/AndroidRuntime(1168):     at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
07-09 02:20:47.433: E/AndroidRuntime(1168):     at android.view.View.layout(View.java:7035)
07-09 02:20:47.433: E/AndroidRuntime(1168):     at android.view.ViewRoot.performTraversals(ViewRoot.java:1045)
07-09 02:20:47.433: E/AndroidRuntime(1168):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
07-09 02:20:47.433: E/AndroidRuntime(1168):     at android.os.Handler.dispatchMessage(Handler.java:99)
07-09 02:20:47.433: E/AndroidRuntime(1168):     at android.os.Looper.loop(Looper.java:123)
07-09 02:20:47.433: E/AndroidRuntime(1168):     at android.app.ActivityThread.main(ActivityThread.java:4627)
07-09 02:20:47.433: E/AndroidRuntime(1168):     at java.lang.reflect.Method.invokeNative(Native Method)
07-09 02:20:47.433: E/AndroidRuntime(1168):     at java.lang.reflect.Method.invoke(Method.java:521)
07-09 02:20:47.433: E/AndroidRuntime(1168):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-09 02:20:47.433: E/AndroidRuntime(1168):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-09 02:20:47.433: E/AndroidRuntime(1168):     at dalvik.system.NativeStart.main(Native Method)

请帮忙谢谢

最佳答案

替换

View rowView = inflater.inflate(R.layout.rowlayout, parent, false);


View rowView = inflater.inflate(R.layout.rowlayout, null);

关于android - 使用自定义数组适配器的NullPointerException,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11390695/

10-10 04:07