1

I'm trying to call a json webservice continuously when there is a letter is added or deleted in a Autocomplete textview. Everything untill here works fine here. But when I try to select an option from the list generated by the autocomplete textview, now the Json is again called and the App Crashes. (ie) The value selected in the autocomplete is again passed to json get method as a parameter and the app is crashed. Can anyone help me resolving this issue.

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

selectIndustry_button.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            // TODO Auto-generated method stub

        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count,
                int after) {
            // TODO Auto-generated method stub

        }

        @Override
        public void afterTextChanged(Editable s) {
            // TODO Auto-generated method stub
            SearchCPS_WS();
        }
    });


private void SearchCPS_WS() {

AsyncHttpClient client = new AsyncHttpClient();
        RequestParams params = new RequestParams();

        Log.i("WebService", "WebService: "+Httppost_Links.SEARCH_COMPANY_NAME_ADD_COMPANY+textInAutoComplete+"5@0");

        client.get(Httppost_Links.SEARCH_COMPANY_NAME_ADD_COMPANY+textInAutoComplete+"/5@0", params,
                new AsyncHttpResponseHandler() {

                    @Override
                    public void onSuccess(String response) {
                        // TODO Auto-generated method stub

                        Log.i("SearchCPS_WS response: ",
                                "SearchCPS_WS response: " + response);


}

Here's my stack:

05-06 08:34:11.002: E/AndroidRuntime(5451): FATAL EXCEPTION: main
    05-06 08:34:11.002: E/AndroidRuntime(5451): Process: com.bvibes, PID: 5451
    05-06 08:34:11.002: E/AndroidRuntime(5451): java.lang.IllegalArgumentException: Illegal character in path at index 78: http://beta.teambv.us/mobile/services/json/SearchCompanyNameList.json/Fountain Powerboat Industries, Inc./5@0?
    05-06 08:34:11.002: E/AndroidRuntime(5451):     at java.net.URI.create(URI.java:727)
    05-06 08:34:11.002: E/AndroidRuntime(5451):     at org.apache.http.client.methods.HttpGet.<init>(HttpGet.java:75)
    05-06 08:34:11.002: E/AndroidRuntime(5451):     at com.loopj.android.http.AsyncHttpClient.get(AsyncHttpClient.java:338)
    05-06 08:34:11.002: E/AndroidRuntime(5451):     at com.loopj.android.http.AsyncHttpClient.get(AsyncHttpClient.java:317)
    05-06 08:34:11.002: E/AndroidRuntime(5451):     at com.bvibes.Profile_Activity.SearchCPS_WS(Profile_Activity.java:156)
    05-06 08:34:11.002: E/AndroidRuntime(5451):     at com.bvibes.Profile_Activity.access$0(Profile_Activity.java:147)
    05-06 08:34:11.002: E/AndroidRuntime(5451):     at com.bvibes.Profile_Activity$3.afterTextChanged(Profile_Activity.java:128)
    05-06 08:34:11.002: E/AndroidRuntime(5451):     at android.widget.TextView.sendAfterTextChanged(TextView.java:7424)
    05-06 08:34:11.002: E/AndroidRuntime(5451):     at android.widget.TextView.setText(TextView.java:3822)
    05-06 08:34:11.002: E/AndroidRuntime(5451):     at android.widget.TextView.setText(TextView.java:3671)
    05-06 08:34:11.002: E/AndroidRuntime(5451):     at android.widget.EditText.setText(EditText.java:80)
    05-06 08:34:11.002: E/AndroidRuntime(5451):     at android.widget.TextView.setText(TextView.java:3646)
    05-06 08:34:11.002: E/AndroidRuntime(5451):     at android.widget.AutoCompleteTextView.replaceText(AutoCompleteTextView.java:945)
    05-06 08:34:11.002: E/AndroidRuntime(5451):     at android.widget.AutoCompleteTextView.performCompletion(AutoCompleteTextView.java:891)
    05-06 08:34:11.002: E/AndroidRuntime(5451):     at android.widget.AutoCompleteTextView.access$500(AutoCompleteTextView.java:91)
    05-06 08:34:11.002: E/AndroidRuntime(5451):     at android.widget.AutoCompleteTextView$DropDownItemClickListener.onItemClick(AutoCompleteTextView.java:1192)
    05-06 08:34:11.002: E/AndroidRuntime(5451):     at android.widget.AdapterView.performItemClick(AdapterView.java:299)
    05-06 08:34:11.002: E/AndroidRuntime(5451):     at android.widget.AbsListView.performItemClick(AbsListView.java:1113)
    05-06 08:34:11.002: E/AndroidRuntime(5451):     at android.widget.AbsListView$PerformClick.run(AbsListView.java:2904)
    05-06 08:34:11.002: E/AndroidRuntime(5451):     at android.widget.AbsListView$3.run(AbsListView.java:3638)
    05-06 08:34:11.002: E/AndroidRuntime(5451):     at android.os.Handler.handleCallback(Handler.java:733)
    05-06 08:34:11.002: E/AndroidRuntime(5451):     at android.os.Handler.dispatchMessage(Handler.java:95)
    05-06 08:34:11.002: E/AndroidRuntime(5451):     at android.os.Looper.loop(Looper.java:136)
    05-06 08:34:11.002: E/AndroidRuntime(5451):     at android.app.ActivityThread.main(ActivityThread.java:5017)
    05-06 08:34:11.002: E/AndroidRuntime(5451):     at java.lang.reflect.Method.invokeNative(Native Method)
    05-06 08:34:11.002: E/AndroidRuntime(5451):     at java.lang.reflect.Method.invoke(Method.java:515)
    05-06 08:34:11.002: E/AndroidRuntime(5451):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
    05-06 08:34:11.002: E/AndroidRuntime(5451):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
    05-06 08:34:11.002: E/AndroidRuntime(5451):     at dalvik.system.NativeStart.main(Native Method)
Skynet
  • 7,522
  • 5
  • 40
  • 78
Parthiban M
  • 1,096
  • 1
  • 9
  • 29
  • Cant dream about it, without code. – Skynet May 06 '15 at 12:24
  • after all the autocomplete textview gives a list of results, when I click on that list my app crahes stating: "Illegal character in path at index 76" – Parthiban M May 06 '15 at 12:31
  • Post your code and the entire stacktrace, we cant help you unless we see the code. Explaining your issue on the fly is akin to teaching maths without a pen and paper. – Skynet May 06 '15 at 12:33
  • dont use a `TextWatcher`: ACTV uses an Adapter and its Filterable features calling getFilter().filter() in order to filter out provided text constraint – pskink May 06 '15 at 12:43

1 Answers1

2

This happens because you have spaces in your URL, this part:

Fountain Powerboat Industries, Inc.

You might replace those with %20 according to URI specification.

Eugene
  • 55,777
  • 85
  • 212
  • 324
  • You are right. The whole problem boils down to an illegal URL (as stated by the exeption anyways). – Ridcully May 06 '15 at 12:58
  • @Ridcully this is how you should use it without any TextWatcher and AsyncHttpClient: http://stackoverflow.com/a/19860624/2252830 but rather using internal `Filter` feature – pskink May 06 '15 at 13:26