Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8491415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:24:59+00:00 2026-06-10T22:24:59+00:00

I am using Asynctask to retrieve the list from server in autocompletetextview but i

  • 0

I am using Asynctask to retrieve the list from server in autocompletetextview but i am getting force close.My code is:

public class Aixclass extends Activity 
{

    protected Void[] params1;
    String[] strarray;
    TextView myXmlContent;
    AutoCompleteTextView actv;
    static final String URL="http://cympac.com/apps/xmlfile.xml";
    static final String KEY_COMMAND = "command"; // parent node
    static final String KEY_WORD = "word";
    static final String KEY_EXPLANATION = "explanation";
    String stringXmlContent;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.newaix);
        TextView tv1=(TextView)findViewById(R.id.textView1);
        TextView tv2=(TextView)findViewById(R.id.textView2);
        TextView tv4=(TextView)findViewById(R.id.textView4);
        //TextView tv5=(TextView)findViewById(R.id.textView5);
        String text="Cympac Software Solutions Pvt Ltd. www.cympac.com";
        tv4.setText(text);
        tv4.setTextColor(Color.RED);
        Pattern pattern=Pattern.compile("www.cympac.com");
        Linkify.addLinks(tv4,pattern,"http://");
        tv4.setTextColor(Color.GREEN);


         actv=(AutoCompleteTextView)findViewById(R.id.autoCompleteTextView1);
        Button b1=(Button)findViewById(R.id.button1);
        Button b2=(Button)findViewById(R.id.button2);
        Button b3=(Button)findViewById(R.id.button3);
        Button b4=(Button)findViewById(R.id.button4);

        actv = (AutoCompleteTextView)findViewById(R.id.autoCompleteTextView1);
        actv.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                new Mytask1().execute(params1);

            }
        });





    }



    private class Mytask1 extends AsyncTask<Void,Void,String[]>
    {

        @Override
        protected String[] doInBackground(Void... params1) 
    {
        try{             
            URL url=new URL("http://cympac.com/apps/aixcomm.txt");
            BufferedReader buf = new BufferedReader(new InputStreamReader(url.openStream())); 

               String readString = new String();   


               ArrayList<String> val = new ArrayList();
               int i=0;

               while ((readString = buf.readLine()) != null) {
                   Log.d("line: ", readString);   
                   val.add(readString);
                   Log.d("values", val.get(i).toString());
                   i++;
               }

               /*String[] strarray = new String[val.size()];
                strarray = val.toArray(strarray);
                for(String s : strarray)
                Toast.makeText(getBaseContext(), "data:"+s, Toast.LENGTH_SHORT).show();*/


               String[] strarray = new String[val.size()];/// SEE THIS
               strarray = val.toArray(strarray);
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
        return strarray;
    }
        protected void onPostExecute(String[] result) 
        {
            ArrayAdapter<String> adapter = 
                new ArrayAdapter<String>(Aixclass.this,android.R.layout.select_dialog_item,strarray);
             actv.setThreshold(1);
             actv.setAdapter(adapter);
            super.onPostExecute(result);
        }





    }






}

but i am getting force close.without using asynctask i run the program,it worked on emulator but failed on real device.So i used aynctask but the above code is showing force close.when i click on autocompletetextview i get “Force close”
My logcat output is:

 08-30 14:44:40.894: E/AndroidRuntime(1026): FATAL EXCEPTION: main
08-30 14:44:40.894: E/AndroidRuntime(1026): java.lang.NullPointerException
08-30 14:44:40.894: E/AndroidRuntime(1026):     at java.util.Arrays$ArrayList.<init>(Arrays.java:49)
08-30 14:44:40.894: E/AndroidRuntime(1026):     at java.util.Arrays.asList(Arrays.java:171)
08-30 14:44:40.894: E/AndroidRuntime(1026):     at android.widget.ArrayAdapter.<init>(ArrayAdapter.java:125)
08-30 14:44:40.894: E/AndroidRuntime(1026):     at com.example.cd16.Aixclass$Mytask1.onPostExecute(Aixclass.java:205)
08-30 14:44:40.894: E/AndroidRuntime(1026):     at com.example.cd16.Aixclass$Mytask1.onPostExecute(Aixclass.java:1)
08-30 14:44:40.894: E/AndroidRuntime(1026):     at android.os.AsyncTask.finish(AsyncTask.java:417)
08-30 14:44:40.894: E/AndroidRuntime(1026):     at android.os.AsyncTask.access$300(AsyncTask.java:127)
08-30 14:44:40.894: E/AndroidRuntime(1026):     at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429)
08-30 14:44:40.894: E/AndroidRuntime(1026):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-30 14:44:40.894: E/AndroidRuntime(1026):     at android.os.Looper.loop(Looper.java:123)
08-30 14:44:40.894: E/AndroidRuntime(1026):     at android.app.ActivityThread.main(ActivityThread.java:4627)
08-30 14:44:40.894: E/AndroidRuntime(1026):     at java.lang.reflect.Method.invokeNative(Native Method)
08-30 14:44:40.894: E/AndroidRuntime(1026):     at java.lang.reflect.Method.invoke(Method.java:521)
08-30 14:44:40.894: E/AndroidRuntime(1026):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
08-30 14:44:40.894: E/AndroidRuntime(1026):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
08-30 14:44:40.894: E/AndroidRuntime(1026):     at dalvik.system.NativeStart.main(Native Method)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T22:25:01+00:00Added an answer on June 10, 2026 at 10:25 pm

    Problem is at this line while ((readString = buf.readLine()) != null) {. I guess String readString=new String() is the porblem.

    Just declare String as String readString;

    This may helps you

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a code which download the apk from server by using Asynctask, Currently
How to create and update listview using AsyncTask getting data from server.Actually i am
I'm using the following class (AsyncTask) to retrieve info from 8 different URL's. I
I am using AsyncTask to get data from a server and want to show
I was using AsyncTask class... My objective is to have a list and when
i am downloading data from website using asynctask and my code for async task
I am using AsyncTask to download images from remote server and show them in
I'm using AsyncTask to get all the data my app needs from a server.
I have been using Asynctask most of time, but in the current app the
I am using AsyncTask and want to use getApplication() to work with class Application.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.