Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You are getting this error because you are trying to access the View object from the doInBackground method, like Name.setText( course.getString(TAG_Name)); You must move all your UI updates to the onPostExecute method.</p> <p>Can you test this implementation: </p> <pre><code>import android.app.Activity; import java.util.ArrayList; import java.util.List; import org.apache.http.NameValuePair; import org.apache.http.message.BasicNameValuePair; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import android.app.ProgressDialog; import android.content.Intent; import android.os.AsyncTask; import android.os.Bundle; import android.util.Log; import android.widget.TextView; public class ViewCourseStudent extends Activity { TextView Name; TextView Description; TextView OfficeHours; TextView CreditHours; TextView MaxAbsenceDays; TextView ExamsDates ; String CourseID ; // Progress Dialog private ProgressDialog pDialog; // JSON parser class JSONParser jsonParser = new JSONParser(); // single course url private static final String url_course_detials = "http://10.0.2.2/SmsPhp/view_course.php"; //JSON Node names private static final String TAG_SUCCESS = "success"; private static final String TAG_CourseID = "CourseID"; private static final String TAG_course = "course"; private static final String TAG_Name = "Name"; private static final String TAG_OfficeHours = "OfficeHours"; private static final String TAG_CreditHours = "CreditHours"; private static final String TAG_Description = "Description"; private static final String TAG_MaxAbsenceDays = "MaxAbsenceDays"; private static final String TAG_ExamsDates = "ExamsDates"; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.view_course); Intent i = getIntent(); CourseID = i.getStringExtra(TAG_CourseID); // Getting complete course details in background thread new GetCourseDetails().execute(); } /** * Background Async Task to Get complete course details * */ class GetCourseDetails extends AsyncTask&lt;String, String, String&gt; { private JSONObject course; /** * Before starting background thread Show Progress Dialog * */ @Override protected void onPreExecute() { super.onPreExecute(); pDialog = new ProgressDialog(ViewCourseStudent.this); pDialog.setMessage("Loading course details. Please wait..."); pDialog.setIndeterminate(false); pDialog.setCancelable(true); pDialog.show(); } @Override protected String doInBackground(String... arg0) { // updating UI from Background Thread // Check for success tag int success; try { // Building Parameters List&lt;NameValuePair&gt; params = new ArrayList&lt;NameValuePair&gt;(); params.add(new BasicNameValuePair("CourseID", CourseID)); // getting course details by making HTTP request // Note that product details url will use GET request JSONObject json = jsonParser.makeHttpRequest( url_course_detials, "GET", params); // check your log for json response Log.d("Single course Details", json.toString()); // json success tag success = json.getInt(TAG_SUCCESS); if (success == 1) { // successfully received product details JSONArray courseObj = json .getJSONArray(TAG_course); // JSON Array // get first course object from JSON Array course = courseObj.getJSONObject(0); }else{ // course with course id not found course = null; } } catch (JSONException e) { e.printStackTrace(); } return null; } /** * After completing background task Dismiss the progress dialog * **/ protected void onPostExecute(String file_url) { // dismiss the dialog once got all details pDialog.dismiss(); if(course != null){ Name = (TextView) findViewById(R.id.C_Name); Description = (TextView) findViewById(R.id.C_Des); CreditHours = (TextView) findViewById(R.id.C_Hours); OfficeHours=(TextView) findViewById(R.id.C_Ohour); MaxAbsenceDays=(TextView) findViewById(R.id.C_absence); ExamsDates=(TextView) findViewById(R.id.Add_C_Exam); // display product data in EditText Name.setText( course.getString(TAG_Name)); Description.setText( course.getString(TAG_Description)); OfficeHours.setText( course.getString(TAG_OfficeHours)); MaxAbsenceDays.setText( course.getString(TAG_MaxAbsenceDays)); ExamsDates.setText( course.getString(TAG_ExamsDates)); CreditHours.setText( course.getString(TAG_CreditHours)); } } } } </code></pre>
    singulars
    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