java.lang.Runtimeexception: Unable to start Activity Componentinfo {...}: java.lang.Nullpointerexception

Asked

Viewed 1,024 times

-1

I’m trying to rewind facebook data and I’m getting this error.

Logcat  10-24 00:46:41.230 7526-7526/sptour.hotmail.com E/AndroidRuntime: FATAL EXCEPTION: main
Process: sptour.hotmail.com, PID: 7526
java.lang.RuntimeException: Unable to start activity ComponentInfo{sptour.hotmail.com/sptour.hotmail.com.Main6Activity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.app.Activity.findViewById(int)' on a null object reference
  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2426)
  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490)
  at android.app.ActivityThread.-wrap11(ActivityThread.java)
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354)
  at android.os.Handler.dispatchMessage(Handler.java:102)
  at android.os.Looper.loop(Looper.java:148)
  at android.app.ActivityThread.main(ActivityThread.java:5443)
  at java.lang.reflect.Method.invoke(Native Method)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.app.Activity.findViewById(int)' on a null object reference
  at sptour.hotmail.com.Main6Activity.onCreate(Main6Activity.java:69)
  at android.app.Activity.performCreate(Activity.java:6245)
  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1130)
  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379)
  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490) 
  at android.app.ActivityThread.-wrap11(ActivityThread.java) 
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354) 
  at android.os.Handler.dispatchMessage(Handler.java:102) 
  at android.os.Looper.loop(Looper.java:148) 
  at android.app.ActivityThread.main(ActivityThread.java:5443) 
  at java.lang.reflect.Method.invoke(Native Method) 
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728) 
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)

 

activity loggin `FacebookSdk.sdkInitialize(getApplicationContext());
setContentView(R.layout.activity_loggin);

mCallbackManager = CallbackManager.Factory.create();
LoginButton mLoginButton = (LoginButton)findViewById(R.id.login_button);

mLoginButton.registerCallback(mCallbackManager, new FacebookCallback<LoginResult>() {
    @Override
    public void onSuccess(LoginResult loginResult) {
        String userLoginId = loginResult.getAccessToken().getUserId();
        Intent facebookIntent = new Intent(Loggin.this, Main6Activity.class);
        Profile mProfile = Profile.getCurrentProfile();
        String firstName = mProfile.getFirstName();
        String lastName = mProfile.getLastName();
        String userId = mProfile.getId().toString();
        String profileImageUrl = mProfile.getProfilePictureUri(96, 96).toString();

        facebookIntent.putExtra(PROFILE_USER_ID, userId);
        facebookIntent.putExtra(PROFILE_FIRST_NAME, firstName);
        facebookIntent.putExtra(PROFILE_LAST_NAME, lastName);
        facebookIntent.putExtra(PROFILE_IMAGE_URL, profileImageUrl);
        startActivity(facebookIntent);

    activity main ImageView profileView = (ImageView)headerLayout.findViewById(R.id.profile_image);
        TextView profileName = (TextView)headerLayout.findViewById(R.id.profile_name);
        TextView profileUserId = (TextView)headerLayout.findViewById(R.id.user_id);
        String profileUserID = returnValueFromBundles(Loggin.PROFILE_USER_ID);
        String profileFirstName = returnValueFromBundles(Loggin.PROFILE_FIRST_NAME);
        String profileLastName = returnValueFromBundles(Loggin.PROFILE_LAST_NAME);
        String profileImageLink = returnValueFromBundles(Loggin.PROFILE_IMAGE_URL);
        profileName.setText(profileFirstName + " " + profileLastName);
        profileUserId.setText("User ID : " + profileUserID);

        Picasso.with(Main6Activity.this).load(profileImageLink).into(profileView);


    private String returnValueFromBundles(String key){

        Bundle inBundle = getIntent().getExtras();
        String returnedValue = inBundle.get(key).toString();
        return returnedValue;

1 answer

1


I’ve been looking at your code and not whether the error was at the time of writing the question or really this coded like this

` activity main ImageView profileView = (ImageView)headerLayout.findViewById(R.id.profile_image);`

The error message that appears on the console is about calling the findViewById method.

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.app.Activity.findViewById(int)' on a null object reference  at sptour.hotmail.com.Main6Activity.onCreate(Main6Activity.java:69)

Take a look at that something says there.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.