I have a main Activity called LoginActivity
, which when clicking on a Button connects to a database. I wanted to make the connection in a new class called MiTurno
.
My problem is that it gives me an error when doing a Toast (this to show errors like INCORRECT PASSWORD , etc) from this new class and I do not know how to correct it.
This is the LoginActivity.java code (see comments):
package com.windroid.dinas;
.....
public class LoginActivity extends AppCompatActivity {
GlobalVariables globalVariables;
EditText miUser;
EditText miPass;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
globalVariables = (GlobalVariables)getApplicationContext();
miUser = (EditText) findViewById(R.id.eUser);
miPass = (EditText) findViewById(R.id.ePass);
}
public void Login(View view) {
new MiTurno().execute("http://10.0.3.2/baradm/sesion.php?id="+miUser.getText().toString());
}
and this is the MyTurn class that is done in a new class called MyTurning.java:
package com.windroid.dinas;
......
public class MiTurno extends AsyncTask<String, Void, String> {
GlobalVariables globalVariables;
public GlobalVariables getGlobalVariables() {
return globalVariables;
}
@Override
protected String doInBackground(String... urls) {
// params comes from the execute() call: params[0] is the url.
try {
return downloadUrl(urls[0]);
} catch (IOException e) {
return "Unable to retrieve web page. URL may be invalid.";
}
}
// onPostExecute displays the results of the AsyncTask.
@Override
protected void onPostExecute(String result) {
try {
JSONArray ja = new JSONArray(result);
if (!ja.getString(1).equals(miUser.getText().toString())) {
//----> AQUI SE GENERA EL ERROR Y NO SE COMO SOLUCIONARLO
Toast toast = Toast.makeText(LoginActivity.this, "USUARIO NO EXISTE", Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}