android listview给出了nullpointerexception

El *_*uli 0 android android-listview

我有这个ListView,当我启动应用程序时,它给出一个空指针异常,但如果视图是GONE,它不会给出任何错误,

lVers = (ListView) view.findViewById(R.id.lVers);
Run Code Online (Sandbox Code Playgroud)

用适配器

RechercheAdapter adapter2 = new RechercheAdapter(getActivity(), R.layout.elem_recherche, listPaysVers);
lVers.setAdapter(adapter2);
Run Code Online (Sandbox Code Playgroud)

这是适配器类

public class RechercheAdapter extends ArrayAdapter<Pays> {

        Context context;
        ArrayList<Pays> data;

        public RechercheAdapter(Context context, int textViewResourceId, ArrayList<Pays> d) {
            super(context, textViewResourceId, d);
            this.data = d;
        }

        @Override
        public int getCount() {
            // TODO Auto-generated method stub
            return data.size();
        }

        @Override
        public Pays getItem(int position) {
            // TODO Auto-generated method stub
            return data.get(position);
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            Pays p = data.get(position);

            LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View v = inflater.inflate(R.layout.elem_recherche, null);

            ImageView drap = (ImageView) v.findViewById(R.id.drap);
            drap.setImageDrawable(Utils.getBitmapFromBase64FullSize(p.getDreapeau64(), getActivity()));

            TextView nom = (TextView) v.findViewById(R.id.nom);
            nom.setText(p.getPays());

            return convertView;
        }

    }
Run Code Online (Sandbox Code Playgroud)

当我尝试启动应用程序时,我得到一个nullpointerexception,

09-24 12:52:37.095: E/AndroidRuntime(30836): FATAL EXCEPTION: main
09-24 12:52:37.095: E/AndroidRuntime(30836): java.lang.NullPointerException
09-24 12:52:37.095: E/AndroidRuntime(30836):    at android.widget.AbsListView.obtainView(AbsListView.java:2467)
09-24 12:52:37.095: E/AndroidRuntime(30836):    at android.widget.ListView.makeAndAddView(ListView.java:1775)
09-24 12:52:37.095: E/AndroidRuntime(30836):    at android.widget.ListView.fillDown(ListView.java:678)
09-24 12:52:37.095: E/AndroidRuntime(30836):    at android.widget.ListView.fillFromTop(ListView.java:739)
09-24 12:52:37.095: E/AndroidRuntime(30836):    at android.widget.ListView.layoutChildren(ListView.java:1628)
09-24 12:52:37.095: E/AndroidRuntime(30836):    at android.widget.AbsListView.onLayout(AbsListView.java:2300)
09-24 12:52:37.095: E/AndroidRuntime(30836):    at android.view.View.layout(View.java:14072)
09-24 12:52:37.095: E/AndroidRuntime(30836):    at android.view.ViewGroup.layout(ViewGroup.java:4607)
09-24 12:52:37.095: E/AndroidRuntime(30836):    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1655)
09-24 12:52:37.095: E/AndroidRuntime(30836):    at android.widget.LinearLayout.layoutHorizontal(LinearLayout.java:1644)
09-24 12:52:37.095: E/AndroidRuntime(30836):    at android.widget.LinearLayout.onLayout(LinearLayout.java:1428)
09-24 12:52:37.095: E/AndroidRuntime(30836):    at android.view.View.layout(View.java:14072)
09-24 12:52:37.095: E/AndroidRuntime(30836):    at android.view.ViewGroup.layout(ViewGroup.java:4607)
09-24 12:52:37.095: E/AndroidRuntime(30836):    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1655)
09-24 12:52:37.095: E/AndroidRuntime(30836):    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1513)
09-24 12:52:37.095: E/AndroidRuntime(30836):    at android.widget.LinearLayout.onLayout(LinearLayout.java:1426)
09-24 12:52:37.095: E/AndroidRuntime(30836):    at android.view.View.layout(View.java:14072)
09-24 12:52:37.095: E/AndroidRuntime(30836):    at android.view.ViewGroup.layout(ViewGroup.java:4607)
09-24 12:52:37.095: E/AndroidRuntime(30836):    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1655)
09-24 12:52:37.095: E/AndroidRuntime(30836):    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1513)
09-24 12:52:37.095: E/AndroidRuntime(30836):    at android.widget.LinearLayout.onLayout(LinearLayout.java:1426)
09-24 12:52:37.095: E/AndroidRuntime(30836):    at android.view.View.layout(View.java:14072)
09-24 12:52:37.095: E/AndroidRuntime(30836):    at android.view.ViewGroup.layout(ViewGroup.java:4607)
09-24 12:52:37.095: E/AndroidRuntime(30836):    at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
09-24 12:52:37.095: E/AndroidRuntime(30836):    at android.view.View.layout(View.java:14072)
09-24 12:52:37.095: E/AndroidRuntime(30836):    at android.view.ViewGroup.layout(ViewGroup.java:4607)
09-24 12:52:37.095: E/AndroidRuntime(30836):    at android.widget.RelativeLayout.onLayout(RelativeLayout.java:948)
09-24 12:52:37.095: E/AndroidRuntime(30836):    at android.view.View.layout(View.java:14072)
09-24 12:52:37.095: E/AndroidRuntime(30836):    at android.view.ViewGroup.layout(ViewGroup.java:4607)
09-24 12:52:37.095: E/AndroidRuntime(30836):    at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
09-24 12:52:37.095: E/AndroidRuntime(30836):    at android.view.View.layout(View.java:14072)
09-24 12:52:37.095: E/AndroidRuntime(30836):    at android.view.ViewGroup.layout(ViewGroup.java:4607)
09-24 12:52:37.095: E/AndroidRuntime(30836):    at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
09-24 12:52:37.095: E/AndroidRuntime(30836):    at android.view.View.layout(View.java:14072)
09-24 12:52:37.095: E/AndroidRuntime(30836):    at android.view.ViewGroup.layout(ViewGroup.java:4607)
09-24 12:52:37.095: E/AndroidRuntime(30836):    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1655)
09-24 12:52:37.095: E/AndroidRuntime(30836):    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1513)
09-24 12:52:37.095: E/AndroidRuntime(30836):    at android.widget.LinearLayout.onLayout(LinearLayout.java:1426)
09-24 12:52:37.095: E/AndroidRuntime(30836):    at android.view.View.layout(View.java:14072)
09-24 12:52:37.095: E/AndroidRuntime(30836):    at android.view.ViewGroup.layout(ViewGroup.java:4607)
09-24 12:52:37.095: E/AndroidRuntime(30836):    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1655)
09-24 12:52:37.095: E/AndroidRuntime(30836):    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1513)
09-24 12:52:37.095: E/AndroidRuntime(30836):    at android.widget.LinearLayout.onLayout(LinearLayout.java:1426)
09-24 12:52:37.095: E/AndroidRuntime(30836):    at android.view.View.layout(View.java:14072)
09-24 12:52:37.095: E/AndroidRuntime(30836):    at android.view.ViewGroup.layout(ViewGroup.java:4607)
09-24 12:52:37.095: E/AndroidRuntime(30836):    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1655)
09-24 12:52:37.095: E/AndroidRuntime(30836):    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1513)
09-24 12:52:37.095: E/AndroidRuntime(30836):    at android.widget.LinearLayout.onLayout(LinearLayout.java:1426)
09-24 12:52:37.095: E/AndroidRuntime(30836):    at android.view.View.layout(View.java:14072)
09-24 12:52:37.095: E/AndroidRuntime(30836):    at android.view.ViewGroup.layout(ViewGroup.java:4607)
09-24 12:52:37.095: E/AndroidRuntime(30836):    at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
09-24 12:52:37.095: E/AndroidRuntime(30836):    at android.view.View.layout(View.java:14072)
09-24 12:52:37.095: E/AndroidRuntime(30836):    at android.view.ViewGroup.layout(ViewGroup.java:4607)
09-24 12:52:37.095: E/AndroidRuntime(30836):    at android.widget.RelativeLayout.onLayout(RelativeLayout.java:948)
09-24 12:52:37.095: E/AndroidRuntime(30836):    at android.view.View.layout(View.java:14072)
09-24 12:52:37.095: E/AndroidRuntime(30836):    at android.view.ViewGroup.layout(ViewGroup.java:4607)
09-24 12:52:37.095: E/AndroidRuntime(30836):    at android.widget.RelativeLayout.onLayout(RelativeLayout.java:948)
09-24 12:52:37.095: E/AndroidRuntime(30836):    at android.view.View.layout(View.java:14072)
09-24 12:52:37.095: E/AndroidRuntime(30836):    at android.view.ViewGroup.layout(ViewGroup.java:4607)
09-24 12:52:37.095: E/AndroidRuntime(30836):    at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
09-24 12:52:37.095: E/AndroidRuntime(30836):    at android.view.View.layout(View.java:14072)
09-24 12:52:37.095: E/AndroidRuntime(30836):    at android.view.ViewGroup.layout(ViewGroup.java:4607)
09-24 12:52:37.095: E/AndroidRuntime(30836):    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1655)
09-24 12:52:37.095: E/AndroidRuntime(30836):    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1513)
09-24 12:52:37.095: E/AndroidRuntime(30836):    at android.widget.LinearLayout.onLayout(LinearLayout.java:1426)
09-24 12:52:37.095: E/AndroidRuntime(30836):    at android.view.View.layout(View.java:14072)
09-24 12:52:37.095: E/AndroidRuntime(30836):    at android.view.ViewGroup.layout(ViewGroup.java:4607)
09-24 12:52:37.095: E/AndroidRuntime(30836):    at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
09-24 12:52:37.095: E/AndroidRuntime(30836): 
Run Code Online (Sandbox Code Playgroud)

任何人都知道发生了什么?谢谢

shi*_*edi 8

返回视图V不转换View或

   convertView=inflater.inflate(R.layout.elem_recherche, null);
Run Code Online (Sandbox Code Playgroud)