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

  • SEARCH
  • Home
  • 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 6687349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:16:42+00:00 2026-05-26T05:16:42+00:00

I am parsing a plist from the server and based on the condition I

  • 0

I am parsing a plist from the server and based on the condition I have a spinner to display and select the value from it.

This is my code which implements that

public class RaconTours extends Activity implements OnClickListener {

@Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        btn = (ImageButton) findViewById(R.id.arrowBtn);
        btn.setOnClickListener(this);
        tourArray = new ArrayList<Tour>();
        btnProfile = (ImageButton) findViewById(R.id.profileBtn);
        spinner = (Spinner) findViewById(R.id.spinner);

        checkSDcardSupport();
        dialog = ProgressDialog.show(RaconTours.this, "", "Loading...",
                true, true);
        splashThread = new Thread() {
            @Override
            public void run() {
                try {
                    /**** Specify the path of the plist file ****/
                    File f = new File(RaconTours.PATH
                            + Constants.TOUR_MASTER_PLIST);
                    if (!f.exists()) {
                        f.createNewFile();
                    }
                    if (f.length() <= 0) {
                        URL plistUrl = new URL(Constants.TOUR_PLIST_URL);
                        TourDescription.httpDownload(f, plistUrl);
                    }
                } catch (MalformedURLException mue) {
                    mue.printStackTrace();
                } catch (IOException ioe) {
                    ioe.printStackTrace();
                }
                /**** Call the method to parse the downloaded plist file ****/
                parsePlist();
                if(dialog!=null){
                    dialog.dismiss();
                }
            }
        };
        splashThread.start();



    }

Now inside parsePlist method,

    public void parsePlist() {


            try {
                /**** Opens and reads the downloaded file ****/

                InputStream is = new BufferedInputStream(new FileInputStream(
                        RaconTours.PATH + Constants.TOUR_MASTER_PLIST));
                XMLPropertyListConfiguration plist = new XMLPropertyListConfiguration(
                        is);

                HashMap<String, Object> dict = plist.mPlistHashMap;
                // check if more than 1 city exists, if they exist display a spinner to select the city
                if (dict.size() > 2) {
                    try {
                    spinner.setVisibility(View.VISIBLE);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    //dict.remove("venueicons");
                    for (Object objSpinner: dict.keySet()) {
                        spin =  (String) objSpinner.toString();
                        // add the keys to the string array list
                        spinnerKeys.add(spin);
                    }
                    // set the array list as the data for the adapter
                    ArrayAdapter<String> spinnerData=new ArrayAdapter<String>(this,
                            android.R.layout.simple_spinner_item,
                            spinnerKeys);

                    spinnerData.setDropDownViewResource(
                            android.R.layout.simple_spinner_dropdown_item);
                        spinner.setAdapter(spinnerData);

                    spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                        public void onItemSelected(AdapterView<?> parent,
                                View view, int pos, long id) {
                            Object item = parent.getItemAtPosition(pos);
                            city = item.toString();
                        }

                        public void onNothingSelected(AdapterView<?> parent) {
                            Toast.makeText(getApplicationContext(), "Please select a city", Toast.LENGTH_SHORT).show();
                        }
                    });

                }
                for (Object key : dict.keySet()) {

                    if (key.toString().equals("venueicons")) {
                        continue;
                    }
                    city = key.toString();

                    HashMap<String, Object> cityDict = (HashMap<String, Object>) dict
                            .get(city);
                    for (Object cityKey : cityDict.keySet()) {

                         tour = new Tour();
    .....
            }
    }
catch (FileNotFoundException fnfe) {
    fnfe.printStackTrace();
}

Here am checking the size of dict is greater that 2, i.e.

if (dict.size() >2) {
…

}

Based on this I am making the spinner visible, but it is giving me the

10-17 08:24:33.240: WARN/System.err(4538): android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
10-17 08:24:33.250: WARN/System.err(4538):     at android.view.ViewRoot.checkThread(ViewRoot.java:2932)
10-17 08:24:33.250: WARN/System.err(4538):     at android.view.ViewRoot.focusableViewAvailable(ViewRoot.java:1712)
10-17 08:24:33.260: WARN/System.err(4538):     at android.view.ViewGroup.focusableViewAvailable(ViewGroup.java:452)
10-17 08:24:33.270: WARN/System.err(4538):     at android.view.ViewGroup.focusableViewAvailable(ViewGroup.java:452)
10-17 08:24:33.270: WARN/System.err(4538):     at android.view.ViewGroup.focusableViewAvailable(ViewGroup.java:452)
10-17 08:24:33.290: WARN/System.err(4538):     at android.view.View.setFlags(View.java:4633)
10-17 08:24:33.290: WARN/System.err(4538):     at android.view.View.setVisibility(View.java:3116)
10-17 08:24:33.290: WARN/System.err(4538):     at com.racontrs.Racontours.RaconTours.parsePlist(RaconTours.java:157)
10-17 08:24:33.300: WARN/System.err(4538):     at com.racontrs.Racontours.RaconTours$1.run(RaconTours.java:85)

for the line

spinner.setVisibility(View.VISIBLE);

Any answer for this?

  • 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-05-26T05:16:42+00:00Added an answer on May 26, 2026 at 5:16 am

    Your splashThread runs on it’s own thread (not the UI-thread) meaning that the call to parseList will also run on a non-UI-thread which results in changes to UI being an ‘illegal’ action.

    You should look into AsyncTask – It might serve a better purpose, since it has method that runs on the UI-thread for making UI changes.

    AsyncTask-example

    Replace your method parsePList() with the following:

    private class PListParser extends AsyncTask<Void, Void, Boolean> {
      public Boolean doInBackground( Void... params ) {
        //do the things your method parsePList does here.
    
        if( dict.size() > 2 )
          return true;
        else
          return false;
      }
    
      public void onPostExecute( Boolean result ) {
        //result is the return-value of the doInBackground-method
        if( result )
          spinner.setVisibility( View.VISIBLE );
        else
          spinner.setVisibility( View.GONE );
      }
    }
    

    Then instead of calling parsePList() you do this: new PListParser().execute()

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

Sidebar

Related Questions

I'm working on porting some ancient code (10.2 era) from NSCoding/plist based archiving to
I'm parsing a (not well formed) Apple Plist File with java. My Code looks
I have home work for parsing XML This is the xml : <?xml version=1.0
I am making an app which basically presents data (from plist) to user in
I have a plist containing an array with three elements all of which are
I have a list of URLs from which I want to scrape an attribute.
I'm parsing text from a file and storing it in a string. The problem
I have a txt file with values(All english words) and am parsing the values
I have been trying to get this to work for about three solid days
I am parsing some xml and storing the result in a plist save it

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.