Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid System services not available
    primarykey
    data
    text
    <p>I'm tyring to get data from my website and then put that info into a spinner. I've used some tutorials and i came up with this code</p> <pre><code>package com.thenewboston.christian; import java.util.ArrayList; import java.util.List; import org.apache.http.NameValuePair; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import android.app.Activity; import android.app.ProgressDialog; import android.os.AsyncTask; import android.os.Bundle; import android.util.Log; import android.widget.ArrayAdapter; import android.widget.Spinner; public class hospitalhttp extends Activity{ private ProgressDialog pDialog; JSONParser jParser = new JSONParser(); private static String url_all_products = "http://www.photosbychristian.com/ems/hospitals.php"; //private static final String TAG_HID = "hid"; private static final String TAG_HOSPITAL = "hospital"; JSONArray hosps = null; ArrayAdapter &lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_spinner_item ); @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.spinnertest); new LoadAllProducts().execute(); } class LoadAllProducts extends AsyncTask&lt;String, String, String&gt; { /** * Before starting background thread Show Progress Dialog * */ @Override protected void onPreExecute() { super.onPreExecute(); pDialog = new ProgressDialog(hospitalhttp.this); pDialog.setMessage("Loading hospitals. Please wait..."); pDialog.setIndeterminate(false); pDialog.setCancelable(false); pDialog.show(); } /** * getting All products from url * */ protected String doInBackground(String... args) { // Building Parameters List&lt;NameValuePair&gt; params = new ArrayList&lt;NameValuePair&gt;(); // getting JSON string from URL JSONObject json = jParser.makeHttpRequest(url_all_products, "GET", params); // Check your log cat for JSON reponse Log.d("All Products: ", json.toString()); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); try { // products found // Getting Array of Products hosps = json.getJSONArray("PA"); // looping through All Products for (int i = 0; i &lt; hosps.length(); i++) { JSONObject c = hosps.getJSONObject(i); // Storing each json item in variable //String id = c.getString(TAG_HID); String name = c.getString(TAG_HOSPITAL); adapter.add(name); } } 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 products pDialog.dismiss(); // updating UI from Background Thread runOnUiThread(new Runnable() { public void run() { /** * Updating parsed JSON data into ListView */ Spinner state = (Spinner) findViewById(R.id.spinner1); state.setAdapter(adapter); } }); } } } </code></pre> <p>I try and run my app and i get this error</p> <pre><code>02-22 22:29:48.131: E/AndroidRuntime(1200): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.thenewboston.christian/com.thenewboston.christian.hospitalhttp}: java.lang.IllegalStateException: System services not available to Activities before onCreate() </code></pre> <p>So i move all of this after the oncreate bolck and i still get the same error</p> <pre><code>private ProgressDialog pDialog; JSONParser jParser = new JSONParser(); private static String url_all_products = "http://www.photosbychristian.com/ems/hospitals.php"; //private static final String TAG_HID = "hid"; private static final String TAG_HOSPITAL = "hospital"; JSONArray hosps = null; ArrayAdapter &lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_spinner_item ); </code></pre> <p>And so i have no idea what to do know any help would be greatly appreciated </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload