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 8973903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:33:15+00:00 2026-06-15T18:33:15+00:00

Below is the code I am having problems with. The php file works like

  • 0

Below is the code I am having problems with. The php file works like a charm, as you can see if you go to the value the url_all_dates variable holds. Below this class is my .xml layout file for the list_item. The app runs but doesn’t display any of the dates in the database.:

public class RequestTour extends ListActivity {

    // Progress Dialog
    private ProgressDialog pDialog;

    // Creating JSON Parser object
    JSONParser jParser = new JSONParser();

    ArrayList<HashMap<String, String>> datesList;

    // url to get all dates list
    private static String url_all_dates = "http://www.prayingmantesconcepts.com/androidfinal/get_all_avail_dates.php";

    // JSON Node names
    private static final String TAG_SUCCESS = "success";
    private static final String TAG_DATES = "dates";
    private static final String TAG_DATEID = "dateID";
    private static final String TAG_DATE = "date";

    // dates JSONArray
    JSONArray dates = null;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dates);//put dates layout here.

        // Hashmap for ListView
        datesList = new ArrayList<HashMap<String, String>>();

        // Loading dates in Background Thread
        new LoadAllDates().execute();

        // Get listview
        ListView lv = getListView();

        // on seleting single date
        // launching Book Tour Screen
        lv.setOnItemClickListener(new OnItemClickListener() {

            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {
                // getting values from selected ListItem
                String dateID = ((TextView) view.findViewById(R.id.dateID)).getText()
                        .toString();

                // Starting new intent
                Intent in = new Intent(getApplicationContext(),
                        BookTour.class);
                // sending dateID to next activity
                in.putExtra(TAG_DATEID, dateID);

                // starting new activity and expecting some response back
                startActivityForResult(in, 100);
            }
        });

    }

    // Response from Edit Product Activity
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        // if result code 100
        if (resultCode == 100) {
            // if result code 100 is received 
            // means user booked a tour
            // reload this screen again
            Intent intent = getIntent();
            finish();
            startActivity(intent);
        }

    }

    /**
     * Background Async Task to Load all dates by making HTTP Request
     * */
    class LoadAllDates extends AsyncTask<String, String, String> {

        /**
         * Before starting background thread Show Progress Dialog
         * */
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            pDialog = new ProgressDialog(RequestTour.this);
            pDialog.setMessage("Loading dates. Please wait...");
            pDialog.setIndeterminate(false);
            pDialog.setCancelable(false);
            pDialog.show();
        }

        /**
         * getting All dates from url
         * */
        protected String doInBackground(String... args) {
            // Building Parameters
            List<NameValuePair> params = new ArrayList<NameValuePair>();
            // getting JSON string from URL
            JSONObject json = jParser.makeHttpRequest(url_all_dates, "GET", params);

            // Check your log cat for JSON response
            Log.d("All Dates: ", json.toString());

            try {
                // Checking for SUCCESS TAG
                int success = json.getInt(TAG_SUCCESS);

                if (success == 1) {
                    //  found
                    // Getting Array of 
                     dates = json.getJSONArray(TAG_DATES);

                    // looping through All Dates Available for Request
                    for (int i = 0; i < dates.length(); i++) {
                        JSONObject c = dates.getJSONObject(i);

                        // Storing each json item in variable
                        String id = c.getString(TAG_DATEID);
                        String date = c.getString(TAG_DATE);

                        // creating new HashMap
                        HashMap<String, String> map = new HashMap<String, String>();

                        // adding each child node to HashMap key => value
                        map.put(TAG_DATEID, id);
                        map.put(TAG_DATE, date);

                        // adding HashList to ArrayList
                        datesList.add(map);
                    }
                } else {
                    // no  found
                    // Launch Add New product Activity
                    Intent i = new Intent(getApplicationContext(),
                            Main.class);
                    // Closing all previous activities
                    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(i);
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }

            return null;
        }

        /**
         * After completing background task Dismiss the progress dialog
         * **/
        protected void onPostExecute(String file_url) {
            // dismiss the dialog after getting all 
            pDialog.dismiss();
            // updating UI from Background Thread
            runOnUiThread(new Runnable() {
                public void run() {
                    /**
                     * Updating parsed JSON data into ListView
                     * */
                    ListAdapter adapter = new SimpleAdapter(
                            RequestTour.this, datesList,
                            R.layout.list_item, new String[] { TAG_DATEID,
                                    TAG_DATE},
                            new int[] { R.id.dateID, R.id.date });
                    // updating listview
                    setListAdapter(adapter);
                }
            });

        }

    }
}


<!------------------------------------------------------------------------------------>


list_item.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <!-- Date id (dateID) - will be HIDDEN - used to pass to other activity -->
    <TextView
        android:id="@+id/dateID"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:visibility="gone" />


    <!-- Date Label -->
    <TextView
        android:id="@+id/date"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:paddingTop="6dip"
        android:paddingLeft="6dip"
        android:textSize="17dip"
        android:textStyle="bold" />

</LinearLayout>
  • 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-15T18:33:16+00:00Added an answer on June 15, 2026 at 6:33 pm

    FIRST ISSUE :
    here

                // no  found
                // Launch Add New product Activity
                Intent i = new Intent(getApplicationContext(),
                        Main.class);
                // Closing all previous activities
                i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(i);
    

    you are trying to access Ui elements from background Thread .move these lines of code to onPostExecute for Updating UI from AsyncTask after doInBackground is completed.


    SECOND ISSUE :

    here

      protected void onPostExecute(String file_url) {
                // dismiss the dialog after getting all 
                pDialog.dismiss();
                // updating UI from Background Thread
                runOnUiThread(new Runnable() {
                    public void run() {
                        /**
                         * Updating parsed JSON data into ListView
                         * */
    
                    }
                });
    

    because we are able to access UI elements in onPostExecute method of AsyncTask so no need to use runOnUiThread for updating UI elements in onPostExecute like in your case you are trying to use access ListAdapter or ListView inside runOnUiThread in onPostExecute


    SOLUTION :

    Change your LoadAllDates code as by using AsyncTask in proper way:

    class LoadAllDates extends AsyncTask<String, String,
                                        ArrayList<HashMap<String, String>>> {
        datesList=new ArrayList<HashMap<String, String>>;
            @Override
            protected void onPreExecute() {
                super.onPreExecute();
              //YOUR CODE HERE
            }
    
    
            protected ArrayList<HashMap<String, String>> 
                                    doInBackground(String... args) {
             // Building Parameters
             List<NameValuePair> params = new ArrayList<NameValuePair>();
            // getting JSON string from URL
            JSONObject json = 
                        jParser.makeHttpRequest(url_all_dates, "GET", params);
    
                // Check your log cat for JSON response
                Log.d("All Dates: ", json.toString());
    
                try {
                    // Checking for SUCCESS TAG
                    int success = json.getInt(TAG_SUCCESS);
    
                    if (success == 1) {
                        //  found
                        // Getting Array of 
                         dates = json.getJSONArray(TAG_DATES);
    
                        // looping through All Dates Available for Request
                        for (int i = 0; i < dates.length(); i++) {
                            JSONObject c = dates.getJSONObject(i);
    
                            // Storing each json item in variable
                            String id = c.getString(TAG_DATEID);
                            String date = c.getString(TAG_DATE);
    
                            // creating new HashMap
                            HashMap<String, String> map = 
                                        new HashMap<String, String>();
    
                            // adding each child node to HashMap key => value
                            map.put(TAG_DATEID, id);
                            map.put(TAG_DATE, date);
    
                            // adding HashList to ArrayList
                            datesList.add(map);
                        }
                    } else {
                        // no  found
    
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
    
                return ArrayList<HashMap<String, String>>;
            }
    
            /**
             * After completing background task Dismiss the progress dialog
             * **/
            protected void onPostExecute(
                         ArrayList<HashMap<String, String>> file_url) {
                // dismiss the dialog after getting all 
                pDialog.dismiss();
                // updating UI from Background Thread
    
                      if(file_url.size()>0)
                       {
                        ListAdapter adapter = new SimpleAdapter(
                                RequestTour.this, file_url,
                                R.layout.list_item, new String[] { TAG_DATEID,
                                        TAG_DATE},
                                new int[] { R.id.dateID, R.id.date });
                        // updating listview
                        setListAdapter(adapter);
                      }
                     else{
                        // Launch Add New product Activity
                        Intent i = new Intent(getApplicationContext(),
                                Main.class);
                        // Closing all previous activities
                        i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                        startActivity(i);
                        }
    
    
            }
    
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having problems with this code below. I would like someone tell me why
The code below works perfectly fine with Firefox, however, I am having problems with
I am having two problems with my code below. <?php $validSubmission = isset($_POST['resetpass']) &&
I'm having some problems trying to get the code below to output the data
I am having a problem using the signedCMS.decode routine. See the code below. The
I am having a problem with the below code. I am not sure why
I am having a very specific problem in JQuery The code below is used
I having below code for different artifacts, Entity public class ChooseFirst { public int
I am having the below code. import xml.dom.minidom def get_a_document(name): return xml.dom.minidom.parse(name) doc =
I am actually having a list of text boxes. I am using below code

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.