I wanted to know how I can do so that if response
is equal to id
of Facebook, go to activity
, and that otherwise go to another activity
.
When I try with:
if (profil.getId().toString() == response)
and I run my application, I get a sign that the application was stopped. Could someone help me please?
Code:
public class MainoRegistro extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maino_registro);
final Profile profil = Profile.getCurrentProfile();
RequestQueue queue = Volley.newRequestQueue(this);
final String URL = "http://midominio.com/consulta.php?facebookid="+profil.getId().toString();
StringRequest stringRequest = new StringRequest(Request.Method.GET, URL, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
response = response.replaceAll("\"","").replace("]","").replace("[","");
if (response == profil.getId()){
Registrado();
}else {
registro();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
LoginManager.getInstance().logOut();
IrPantallaLogin();
}
});
queue.add(stringRequest);
}
private void registro() {
Intent intent = new Intent(MainoRegistro.this,Registro.class);
finish();
startActivity(intent);
}
private void Registrado() {
Intent intent = new Intent(MainoRegistro.this,MainActivity.class);
finish();
startActivity(intent);
}
Now that I put the .trim () method the app stops and in the logcat it tells me the following:
java.lang.RuntimeException: Unable to start activity ComponentInfo {com.mathiastoledo.talkit / com.mathiastoledo.tal kit.MainoRegistro}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.facebook.Profile.getId ()' on a null object reference