private ProgressDialog progressDialog; JSONParser jsonParser = new JSONParser(); TextView dateFrom; TextView dateBack; private static String url_create_new_ticket = "http://test.devcolibri.com/create_product.php"; private static String TAG_SUCCES = "succes"; class NewBillet extends AsyncTask<String, String, String> { @Override protected void onPreExecute(){ super.onPreExecute(); progressDialog = new ProgressDialog(MainActivity.this); progressDialog.setMessage("Бронирование биллета"); progressDialog.setIndeterminate(false); progressDialog.setCancelable(true); progressDialog.show(); } protected String doInBackground(String[]args){ dateFrom = (TextView)findViewById(R.id.dateStart); dateBack = (TextView)findViewById(R.id.dateEnd); String dateFromToDB = dateFrom.getText().toString(); String dateBackToDB = dateBack.getText().toString(); String pay_status = "no"; List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair("real_date_from", dateFromToDB)); params.add(new BasicNameValuePair("real_date_back", dateBackToDB)); params.add(new BasicNameValuePair("pay_status", pay_status)); JSONObject json = jsonParser.makeHttpRequest(url_create_new_ticket, "POST", params); Log.d("Create new tickets", json.toString()); try{ int success = json.getInt(TAG_SUCCES); if (success == 1){ startActivity(new Intent(getApplicationContext(), Tickets.class)); finish(); } } catch (JSONException e){ e.printStackTrace(); } return null; } protected void onPostExecute(String file_url){ progressDialog.dismiss(); } } 

}

Lines

  String dateFromToDB = dateFrom.getText().toString(); String dateBackToDB = dateBack.getText().toString(); 

The above error is highlighted and pops up. How can it be caused and how to fix it?

    1 answer 1

    Error due to the fact that you are trying to get the text from the view, while not being in the UI-trad. Try this

      new NewBillet().execute(dateFrom.getText().toString(), dateBack.getText().toString()); 

    and further

     protected String doInBackground(String... args){ String dateFromToDB = args[0]; String dateBackToDB = args[1]; 

    etc