I am currently working on an Android app with Android Studio. I followed a Tuto to add the facebook login functions with picture and username . Then I created a new Activity once the Login is successful. But when I start the app, the app crash within 5 seconds with the message Attempt to invoke virtual method 'java.lang.String android.os.Bundle.getString(java.lang.String)' on a null object reference
Main activity :
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Bundle inBundle = getIntent().getExtras();
String name = inBundle.get("name").toString();
String surname = inBundle.get("surname").toString();
String imageUrl = inBundle.get("imageUrl").toString();
if (AccessToken.getCurrentAccessToken() == null) {
TextView nameView = (TextView)findViewById(R.id.nameAndSurname);
nameView.setText("" + name + " " + surname);
new DownloadImage((ImageView)findViewById(R.id.profileImage)).execute(imageUrl);
goLoginScreen();
}
}
private void goLoginScreen() {
Intent intent = new Intent(this, LoginActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
public void logout(View view) {
LoginManager.getInstance().logOut();
goLoginScreen();
}
Activity_main.xml :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="tech.alvarez.androidfacebooklogin.MainActivity">
<TextView
android:id="@+id/nameAndSurname"
android:layout_width="77dp"
android:layout_height="wrap_content"
android:layout_above="@+id/profileImage"
android:layout_centerHorizontal="true"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="-143dp"
android:textSize="22dp"
android:textStyle="bold" />
<ImageView
android:id="@+id/profileImage"
android:layout_width="87dp"
android:layout_height="101dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="190dp" />
<Button
style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:onClick="logout"
android:text="@string/logout" />