NoSuchMethodError:android中的com.android.app.fragment getContext

前端之家收集整理的这篇文章主要介绍了NoSuchMethodError:android中的com.android.app.fragment getContext前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在GridView类别和类别图像中的PHP webservices得到此错误在数组列表中我必须在网格视图中显示它们thrpough web services但是getData()中出现了错误,因为NoSuchMethodError
请尽量帮助我,谢谢.
@Override
public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.activity_customerhomepage,container,false);
    gridView = (GridView) rootView.findViewById(R.id.gridView);
    ids = new ArrayList<>();
    categorys = new ArrayList<>();
    category_imgs = new ArrayList<>();

    //Calling the getData method
    getData();
    return rootView;
}

private void getData() {

    final ProgressDialog loading = ProgressDialog.show(getContext(),"Please wait...","Fetching data...",false,false);

    //Creating a json array request to get the json from our api
    JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(DATA_URL,new Response.Listener<JSONArray>() {
                @Override
                public void onResponse(JSONArray response) {
                    //Dismissing the progressdialog on response
                    loading.dismiss();

                    //Displaying our grid
                    showGrid(response);
                }
            },new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {

                }
            }
    );

Logcat错误

03-20 22:35:58.002 23736-23736/? E/AndroidRuntime: FATAL EXCEPTION: main
03-20 22:35:58.002 23736-23736/? E/AndroidRuntime: Process: com.android.app.a2aapp,PID: 23736
03-20 22:35:58.002 23736-23736/? E/AndroidRuntime: java.lang.NoSuchMethodError: com.android.app.a2aapp.HomeFragment.getContext
03-20 22:35:58.002 23736-23736/? E/AndroidRuntime:     at com.android.app.a2aapp.HomeFragment.getData(HomeFragment.java:67)
03-20 22:35:58.002 23736-23736/? E/AndroidRuntime:     at com.android.app.a2aapp.HomeFragment.onCreateView(HomeFragment.java:61)
03-20 22:35:58.002 23736-23736/? E/AndroidRuntime:     at android.app.Fragment.performCreateView(Fragment.java:1700)
03-20 22:35:58.002 23736-23736/? E/AndroidRuntime:     at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:890)
03-20 22:35:58.002 23736-23736/? E/AndroidRuntime:     at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1062)
03-20 22:35:58.002 23736-23736/? E/AndroidRuntime:     at android.app.BackStackRecord.run(BackStackRecord.java:684)
03-20 22:35:58.002 23736-23736/? E/AndroidRuntime:     at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1447)
03-20 22:35:58.002 23736-23736/? E/AndroidRuntime:     at android.app.Activity.performStart(Activity.java:5257)
03-20 22:35:58.002 23736-23736/? E/AndroidRuntime:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2171)
03-20 22:35:58.002 23736-23736/? E/AndroidRuntime:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2257)
03-20 22:35:58.002 23736-23736/? E/AndroidRuntime:     at android.app.ActivityThread.access$800(ActivityThread.java:139)
03-20 22:35:58.002 23736-23736/? E/AndroidRuntime:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
03-20 22:35:58.002 23736-23736/? E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:102)
03-20 22:35:58.002 23736-23736/? E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:136)
03-20 22:35:58.002 23736-23736/? E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5086)
03-20 22:35:58.002 23736-23736/? E/AndroidRuntime:     at java.lang.reflect.Method.invokeNative(Native Method)
03-20 22:35:58.002 23736-23736/? E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Method.java:515)
03-20 22:35:58.002 23736-23736/? E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
03-20 22:35:58.002 23736-23736/? E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
03-20 22:35:58.002 23736-23736/? E/AndroidRuntime:     at dalvik.system.NativeStart.main(Native Method)

解决方法

方法 getContext()在API级别23上可用.
尝试使用 getActivity().
原文链接:https://www.f2er.com/android/313820.html

猜你在找的Android相关文章