Null Pointer异常尝试调用虚方法' int android.view.View.getImportantForAccessibility()

时间:2016-10-15 04:43:26

标签: java android nullpointerexception

我在片段中有自定义适配器的列表视图但是我无法解决它,我尝试了其他答案,这些答案指示我从getView()返回convertview但是它没有帮助。

MyIssueFragment.java

public class MyIssuesFragment extends Fragment
{
    private static final String TAG = MyIssuesFragment.class.getSimpleName();
    ArrayList<Issue> arrayList;
    ListView issueListView;
    public MyIssuesFragment()
    {
        // Required empty public constructor
    }
    public static MyIssuesFragment newInstance()
    {
        return new MyIssuesFragment();
    }
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        View rootView = inflater.inflate(R.layout.fragment_my_issues, container, false);
        arrayList = new ArrayList<>();
        HashMap<String,String> hashMap = new HashMap<>();
        hashMap.put("userid",HomeActivity.USER_ID);
        issueListView = (ListView) rootView.findViewById(R.id.list_view);
        PostRequestSend prs = new PostRequestSend("http://snapimpact.esy.es/php_codes/my_issues.php",hashMap);
        prs.setTaskDoneListener(new PostRequestSend.TaskDoneListener()
        {
            @Override
            public String onTaskDone(String str) throws JSONException
            {
                Log.e(TAG, "onTaskDone:  " + str );
                JSONArray jsArray = new JSONArray(str);
                int len = jsArray.length();
                for (int i = 0 ; i < len ; i++)
                {
                    arrayList.add(i,new Issue(jsArray.getJSONObject(i)));
                }


                return str;


            }
        });
        prs.execute();
        issueListView.setAdapter(new MyAdapter(arrayList,getContext()));
        return rootView;
    }
    public  class MyAdapter extends BaseAdapter{
        private Context context;
        private ArrayList<Issue> arr;
        public MyAdapter(ArrayList<Issue> arr , Context context)
        {
            this.arr = arr;
            this.context = context;
        }

        @Override
        public int getCount()
        {
            Log.e(TAG, "getCount: " + arr.size() );
            return arr.size();
        }
        @Override
        public Issue getItem(int position)
        {
            return arr.get(position);
        }
        @Override
        public long getItemId(int position)
        {
            return 0;
        }
        @Override
        public View getView(int position, View convertView, ViewGroup parent)
        {
            LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = layoutInflater.inflate(R.layout.single_issue_layout,null);
            return convertView;
        }
    }
}

single_issue_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
         android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent">
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:hint="aalo"
    android:id="@+id/id_1"/>
</LinearLayout>

fragment_my_issues.xml

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
             xmlns:tools="http://schemas.android.com/tools"
             android:layout_width="match_parent"
             android:layout_height="match_parent"

             tools:context="com.example.dam.snapimpact.MyIssuesFragment">

    <!-- TODO: Update blank fragment layout -->
<ListView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/list_view"/>

</FrameLayout>

logcat的

10-15 10:02:06.514 12114-12114/com.example.dam.snapimpact E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.dam.snapimpact, PID: 12114
java.lang.NullPointerException: Attempt to invoke virtual method 'int android.view.View.getImportantForAccessibility()' on a null object reference
at android.widget.AbsListView.obtainView(AbsListView.java:2363)
at android.widget.ListView.makeAndAddView(ListView.java:1876)
at android.widget.ListView.fillDown(ListView.java:702)
at android.widget.ListView.fillFromTop(ListView.java:763)
at android.widget.ListView.layoutChildren(ListView.java:1685)
at android.widget.AbsListView.onLayout(AbsListView.java:2148)
at android.view.View.layout(View.java:16651)
at android.view.ViewGroup.layout(ViewGroup.java:5440)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
at android.view.View.layout(View.java:16651)
at android.view.ViewGroup.layout(ViewGroup.java:5440)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
at android.view.View.layout(View.java:16651)
at android.view.ViewGroup.layout(ViewGroup.java:5440)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1079)
at android.view.View.layout(View.java:16651)
at android.view.ViewGroup.layout(ViewGroup.java:5440)
at android.support.design.widget.HeaderScrollingViewBehavior.layoutChild(HeaderScrollingViewBehavior.java:122)
at android.support.design.widget.ViewOffsetBehavior.onLayoutChild(ViewOffsetBehavior.java:42)
at android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onLayoutChild(AppBarLayout.java:1192)
at android.support.design.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:814)
at android.view.View.layout(View.java:16651)
at android.view.ViewGroup.layout(ViewGroup.java:5440)
at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:1187)
at android.view.View.layout(View.java:16651)
at android.view.ViewGroup.layout(ViewGroup.java:5440)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
at android.view.View.layout(View.java:16651)
at android.view.ViewGroup.layout(ViewGroup.java:5440)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1743)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1586)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1495)
at android.view.View.layout(View.java:16651)
at android.view.ViewGroup.layout(ViewGroup.java:5440)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
at android.view.View.layout(View.java:16651)
at android.view.ViewGroup.layout(ViewGroup.java:5440)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1743)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1586)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1495)
at android.view.View.layout(View.java:16651)
at android.view.ViewGroup.layout(ViewGroup.java:5440)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
at com.android.internal.policy.PhoneWindow$DecorView.onLayout(PhoneWindow.java:2678)
at android.view.View.layout(View.java:16651)
at android.view.ViewGroup.layout(ViewGroup.java:5440)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2183)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1943)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1119)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6060)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
at android.view.Choreographer.doCallbacks(Choreographer.java:670)
at android.view.Choreographer.doFrame(Choreographer.java:606)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
at android.os.Handler.handleCallback(Handler.java:746)
at android.os.Handler.dispatchMessage(

0 个答案:

没有答案