1

Errors: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length

Application run but display no output in autocompletetextview

englishSentence is jsonObject. and i have getter and setter methods in TranslatorModel class for json Objects.

public class MainActivity extends AppCompatActivity {


    private AutoCompleteTextView autoCompleteTextView;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        autoCompleteTextView = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView);


        new HttpGetTask().execute("http://192.168.0.107/abc/translator.php");

    }

    public class HttpGetTask extends AsyncTask<String, String, List<TranslatorModel>> {


        @Override
        protected List<TranslatorModel> doInBackground(String... params) {
            HttpURLConnection connection = null;
            BufferedReader reader = null;


            try {
                URL url = new URL(params[0]);
                connection = (HttpURLConnection) url.openConnection();
                connection.connect();

                InputStream stream = connection.getInputStream();

                reader = new BufferedReader(new InputStreamReader(stream));

                StringBuffer buffer = new StringBuffer();

                String line = "";
                while ((line = reader.readLine()) != null) {
                    buffer.append(line);
                }

                String finalJson = buffer.toString();
                JSONArray parentArray = new JSONArray(finalJson);

                List<TranslatorModel> translatorModelList = new ArrayList<>();


                for(int i= 0; i<parentArray.length();i++) {

                    JSONObject finalObject = parentArray.getJSONObject(i);

                    TranslatorModel translatorModel = new TranslatorModel();


                        translatorModel.setEnglish(finalObject.getString("englishSentence"));


                        translatorModelList.add(translatorModel);
                    }



                return translatorModelList;

            } catch (MalformedURLException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } catch (JSONException e) {
                e.printStackTrace();
            } finally {
                if (connection != null) {
                    connection.disconnect();
                }

                try {
                    if (reader != null) {
                        reader.close();
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return null;
        }


        @Override
        protected void onPostExecute(List<TranslatorModel> data) {


            AutoCompleteAdapter adapter = new AutoCompleteAdapter(getApplicationContext(),android.R.layout.simple_list_item_1,data);

            autoCompleteTextView.setAdapter(adapter);
            autoCompleteTextView.setThreshold(1);



            super.onPostExecute(data);
        }
    }

    public class AutoCompleteAdapter extends ArrayAdapter {

        private List<TranslatorModel> translatorModelList;
        private int resource;
        private LayoutInflater inflater;


        public AutoCompleteAdapter(Context context, int resource, List<TranslatorModel> objects) {
            super(context, resource, objects);

            translatorModelList = objects;
            this.resource = resource;
            inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);

        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {

            ViewHolder holder = null;


            if (convertView == null) {
                convertView = inflater.inflate(resource, null);

                holder = new ViewHolder();


                holder.autoCompleteTextView = (AutoCompleteTextView) convertView.findViewById(R.id.autoCompleteTextView);



                convertView.setTag(holder);
            } else {
                holder = (ViewHolder) convertView.getTag();
            }

            holder.autoCompleteTextView.setText(translatorModelList.get(position).getEnglish());

            return convertView;
        }

        class ViewHolder {


            private AutoCompleteTextView autoCompleteTextView;

        }
    }
}
Safiullah
  • 39
  • 6
  • Did you get some json as response? Can you post an example? Maybe the structur of the json string is another than you think. – beeb Jan 03 '17 at 19:38
  • Structure is right . i know about json response structure . problem in autocompletetextview. i declared two times autocompletetextview class in my code. on for OnCreateView . one for ViewHolder class. and assigned them same xml id – Safiullah Jan 03 '17 at 19:48
  • see [this](http://stackoverflow.com/a/19860624/2252830), you are using the wrong approach of data filtering (note: this it your 5th question regarding this `ACTV` filtering) – pskink Jan 03 '17 at 19:49
  • [{"sentenceID":"1","englishSentence":"Where are you ?"}] – Safiullah Jan 03 '17 at 19:56
  • Thanks everyone , finally found the required solution for this problem – Safiullah Jan 07 '17 at 20:48

0 Answers0