public class FragmentCatalog extends Fragment { View view; @BindView(R.id.listView) ListView listView; @BindView(R.id.tabLayout) TabLayout tabLayout; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { view = inflater.inflate(R.layout.fragment_catalog, container, false); ButterKnife.bind(this, view); tabLayout.addTab(tabLayout.newTab().setIcon(R.drawable.share2x).setText("Поделиться")); tabLayout.addTab(tabLayout.newTab().setIcon(R.drawable.save2x).setText("Сохранить")); tabLayout.addTab(tabLayout.newTab().setIcon(R.drawable.calculate2x).setText("Калькулятор")); new Async().execute(); return view; } ////////////////////////////////////////////////////// class Async extends AsyncTask{ JSONArray jsonArrayResponse; int intDrawables[] = {R.drawable.f2x, R.drawable.ff2x, R.drawable.land2x, R.drawable.rooms2x, R.drawable.square2x}; String stringDrawablesName[] = {"", "", "land", "rooms", "square"}; ProgressDialog progressDialog; int indexDrawables=0; @Override protected void onPreExecute() { super.onPreExecute(); progressDialog=new ProgressDialog(getActivity()); progressDialog.setMessage("Загрузка данных"); progressDialog.show(); } @Override protected Object doInBackground(Object[] objects) { try { String str=HttpRequest.get("http://app.maralin.ru/application.php?type=catalog&action=list&limit=10&page=1") .getResponse().getResponseText(); jsonArrayResponse=new JSONArray(new JSONObject(str)); } catch (IOException | JSONException e) { e.printStackTrace(); } return null; } @Override protected void onPostExecute(Object o) { super.onPostExecute(o); listView.setAdapter(new BaseAdapter() { @Override public int getCount() { return jsonArrayResponse.length(); } @Override public Object getItem(int i) { return null; } @Override public long getItemId(int i) { return 0; } @Override public View getView(int position, View view, ViewGroup viewGroup) { view = getActivity().getLayoutInflater().inflate(R.layout.fragment_catalog_adap, viewGroup, false); LinearLayout linearLayout = (LinearLayout) view.findViewById(R.id.layout); try { JSONArray jsonArrayDops=jsonArrayResponse.getJSONObject(position).getJSONArray("dops"); for (int i = 0; i < jsonArrayDops.length(); i++) { String nameImageIcon=jsonArrayDops.getJSONObject(i).getString("key"); for (int j = 0; j < stringDrawablesName.length; j++) { if (nameImageIcon.equals(stringDrawablesName[j])){ indexDrawables=j; break; } } TextView textView = new TextView(getActivity()); textView.setText(jsonArrayDops.getJSONObject(i).getString("value")); textView.setTextSize(12); ImageView imageView = new ImageView(getActivity()); imageView.setImageResource(intDrawables[indexDrawables]); imageView.setAdjustViewBounds(true); linearLayout.addView(imageView); linearLayout.addView(textView); } } catch (JSONException e) { e.printStackTrace(); } return view; } }); progressDialog.dismiss(); } } } 

This code was working recently. After the update - began to crash. Neither can I understand what the problem is.

Already cleaned the project and google and all that is possible. Everything is useless.


  FATAL EXCEPTION: AsyncTask #2 java.lang.RuntimeException: An error occured while executing doInBackground() Caused by: java.lang.NoSuchMethodError: org.json.JSONArray.<init> at com.eranewgames.maralinru.Fragments.FragmentCatalog$Async.doInBackground(FragmentCatalog.java:68) 

Here the cursor stops.

  jsonArrayResponse=new JSONArray(new JSONObject(str)); 

 compileSdkVersion 24 buildToolsVersion "24.0.1" defaultConfig { minSdkVersion 15 targetSdkVersion 24 versionCode 1 versionName "1.0" } 

 Caused by: java.lang.NoSuchMethodError: org.json.JSONArray.<init> at com.eranewgames.maralinru.Fragments.FragmentCatalog$Async.doInBackground(FragmentCatalog.java:65) 
  • and the problem on all devices? It looks as if the system library did not load. Cleaning project tried to do? Which targetSdkVersion / compileSdkVersion in the project? - pavel
  • Tested on Genymotion API 16. - Andro
  • one
    Try to run on a real device, or lower targetSdkVersion. - pavel
  • @pavel, To get easy. 3 hours to nowhere. Target changed to 23 as you said. Thanks you. I **** *** google !!! - Andro

0