Reputation: 49
Hello guys I am trying to acces class which works with asynctasks, but strangely i get that annoying error maybe you can help me, error shows on serverRequest.Storenaryste();
here is the code:
................................................................................
uzsisakyti.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Global.naryste = trukme +" "+ "rad" +" "+ kaina.getText().toString();
naris();
}
});
private void naris() {
ServerRequests serverRequest = new ServerRequests(this);
serverRequest.Storenaryste();
}
ServerRequest class :
public class Storenaryste extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
ArrayList<NameValuePair> dataToSend = new ArrayList<>();
dataToSend.add(new BasicNameValuePair("pastas",Global.elpastas ));
dataToSend.add(new BasicNameValuePair("slaptazodis",Global.slaptazodis ));
dataToSend.add(new BasicNameValuePair("naryste",Global.naryste));
HttpParams httpRequestParams = getHttpRequestParams();
HttpClient client = new DefaultHttpClient(httpRequestParams);
HttpPost post = new HttpPost(SERVER_ADDRESS
+ "Naryste.php");
try {
post.setEntity(new UrlEncodedFormEntity(dataToSend));
client.execute(post);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
private HttpParams getHttpRequestParams() {
HttpParams httpRequestParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpRequestParams,
CONNECTION_TIMEOUT);
HttpConnectionParams.setSoTimeout(httpRequestParams,
CONNECTION_TIMEOUT);
return httpRequestParams;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
progressDialog.dismiss();
}
}
Upvotes: 2
Views: 6062
Reputation: 12348
You are trying to start your AsyncTask
like this:
ServerRequests serverRequest = new ServerRequests(this);
serverRequest.Storenaryste();
This seems a little strange to me, you should do like this instead:
new Storenaryste().execute();
Which should work.
Also check the docs for AsyncTask for how to use it correctly:
http://developer.android.com/reference/android/os/AsyncTask.html
Upvotes: 1
Reputation: 27535
Change you function to
private void naris() {
new Storenaryste().execute();
}
Upvotes: 0