2016-03-03 3 views
-4
03-03 17:36:46.791 31818-31818/com.example.ricardo.tcc2 E/AndroidRuntime:  FATAL EXCEPTION: main 
03-03 17:36:46.791 31818-31818/com.example.ricardo.tcc2 E/AndroidRuntime:  Process: com.example.ricardo.tcc2, PID: 31818 
03-03 17:36:46.791 31818-31818/com.example.ricardo.tcc2 E/AndroidRuntime:  java.lang.RuntimeException: Unable to resume activity  {com.example.ricardo.tcc2/com.example.ricardo.tcc2.Facebook}:  java.lang.NullPointerException: Attempt to invoke virtual method  'java.lang.String com.facebook.Profile.getId()' on a null object reference 
03-03 17:36:46.791 31818-31818/com.example.ricardo.tcc2 E/AndroidRuntime:  at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4008) 
03-03 17:36:46.791 31818-31818/com.example.ricardo.tcc2 E/AndroidRuntime:  at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4039) 
03-03 17:36:46.791 31818-31818/com.example.ricardo.tcc2 E/AndroidRuntime:  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3235) 
03-03 17:36:46.791 31818-31818/com.example.ricardo.tcc2 E/AndroidRuntime:  at android.app.ActivityThread.access$1000(ActivityThread.java:198) 
03-03 17:36:46.791 31818-31818/com.example.ricardo.tcc2 E/AndroidRuntime:  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1682) 
03-03 17:36:46.791 31818-31818/com.example.ricardo.tcc2 E/AndroidRuntime:  at android.os.Handler.dispatchMessage(Handler.java:102) 
03-03 17:36:46.791 31818-31818/com.example.ricardo.tcc2 E/AndroidRuntime:  at android.os.Looper.loop(Looper.java:145) 
03-03 17:36:46.791 31818-31818/com.example.ricardo.tcc2 E/AndroidRuntime:  at android.app.ActivityThread.main(ActivityThread.java:6843) 
03-03 17:36:46.791 31818-31818/com.example.ricardo.tcc2 E/AndroidRuntime:  at java.lang.reflect.Method.invoke(Native Method) 
03-03 17:36:46.791 31818-31818/com.example.ricardo.tcc2 E/AndroidRuntime:  at java.lang.reflect.Method.invoke(Method.java:372) 
03-03 17:36:46.791 31818-31818/com.example.ricardo.tcc2 E/AndroidRuntime:  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404) 
03-03 17:36:46.791 31818-31818/com.example.ricardo.tcc2 E/AndroidRuntime:  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199) 
03-03 17:36:46.791 31818-31818/com.example.ricardo.tcc2 E/AndroidRuntime: Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.facebook.Profile.getId()' on a null object reference 
03-03 17:36:46.791 31818-31818/com.example.ricardo.tcc2 E/AndroidRuntime:  at com.example.ricardo.tcc2.BlankFragment.onResume(BlankFragment.java:168) 
03-03 17:36:46.791 31818-31818/com.example.ricardo.tcc2 E/AndroidRuntime:  at android.support.v4.app.Fragment.performResume(Fragment.java:2005) 
03-03 17:36:46.791 31818-31818/com.example.ricardo.tcc2 E/AndroidRuntime:  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1108) 
03-03 17:36:46.791 31818-31818/com.example.ricardo.tcc2 E/AndroidRuntime:  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1248) 
03-03 17:36:46.791 31818-31818/com.example.ricardo.tcc2 E/AndroidRuntime:  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1230) 
03-03 17:36:46.791 31818-31818/com.example.ricardo.tcc2 E/AndroidRuntime:  at android.support.v4.app.FragmentManagerImpl.dispatchResume(FragmentManager.java:2052) 
03-03 17:36:46.791 31818-31818/com.example.ricardo.tcc2 E/AndroidRuntime:  at android.support.v4.app.FragmentController.dispatchResume(FragmentController.java:187) 
03-03 17:36:46.791 31818-31818/com.example.ricardo.tcc2 E/AndroidRuntime:  at android.support.v4.app.FragmentActivity.onResumeFragments(FragmentActivity.java:462) 
03-03 17:36:46.791 31818-31818/com.example.ricardo.tcc2 E/AndroidRuntime:  at android.support.v4.app.FragmentActivity.onPostResume(FragmentActivity.java:451) 
03-03 17:36:46.791 31818-31818/com.example.ricardo.tcc2 E/AndroidRuntime:  at android.app.Activity.performResume(Activity.java:6639) 
03-03 17:36:46.791 31818-31818/com.example.ricardo.tcc2 E/AndroidRuntime:  at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3997) 
03-03 17:36:46.791 31818-31818/com.example.ricardo.tcc2 E/AndroidRuntime:  at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4039)  
03-03 17:36:46.791 31818-31818/com.example.ricardo.tcc2 E/AndroidRuntime:  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3235)  
03-03 17:36:46.791 31818-31818/com.example.ricardo.tcc2 E/AndroidRuntime:  at android.app.ActivityThread.access$1000(ActivityThread.java:198)  
03-03 17:36:46.791 31818-31818/com.example.ricardo.tcc2 E/AndroidRuntime:  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1682)  
03-03 17:36:46.791 31818-31818/com.example.ricardo.tcc2 E/AndroidRuntime:  at android.os.Handler.dispatchMessage(Handler.java:102)  
03-03 17:36:46.791 31818-31818/com.example.ricardo.tcc2 E/AndroidRuntime:  at android.os.Looper.loop(Looper.java:145)  
03-03 17:36:46.791 31818-31818/com.example.ricardo.tcc2 E/AndroidRuntime:  at android.app.ActivityThread.main(ActivityThread.java:6843)  
03-03 17:36:46.791 31818-31818/com.example.ricardo.tcc2 E/AndroidRuntime:  at java.lang.reflect.Method.invoke(Native Method)  
03-03 17:36:46.791 31818-31818/com.example.ricardo.tcc2 E/AndroidRuntime:  at java.lang.reflect.Method.invoke(Method.java:372)  
03-03 17:36:46.791 31818-31818/com.example.ricardo.tcc2 E/AndroidRuntime:  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)  
03-03 17:36:46.791 31818-31818/com.example.ricardo.tcc2 E/AndroidRuntime:  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)  

Это мой класс Facebook.Facebook, возвращающийся

public class Facebook extends FragmentActivity { 

private BlankFragment mainFragment; 
private LoginButton loginButton; 
private CallbackManager callbackManager; 


public String name; 
public String id; 
public String imageUrl; 



@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_facebook); 



    FacebookSdk.sdkInitialize(getApplicationContext()); 
    callbackManager = CallbackManager.Factory.create(); 


    loginButton = (LoginButton) findViewById(R.id.login_button); 

    printHashkey(); 

    if (savedInstanceState == null) { 
     // Add the fragment on initial activity setup 
     mainFragment = new BlankFragment(); 
     getSupportFragmentManager().beginTransaction() 
       .add(android.R.id.content, mainFragment).commit(); 
    } else { 
     // Or set the fragment from restored state info 
     mainFragment = (BlankFragment) getSupportFragmentManager() 
       .findFragmentById(android.R.id.content); 
    } 



} 


public void printHashkey(){ 
    try { 
     PackageInfo info = getPackageManager().getPackageInfo(
       "name", 
       PackageManager.GET_SIGNATURES); 
     for (Signature signature : info.signatures) { 
      MessageDigest md = MessageDigest.getInstance("SHA"); 
      md.update(signature.toByteArray()); 
      Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT)); 
     } 
    } catch (PackageManager.NameNotFoundException e) { 

    } catch (NoSuchAlgorithmException e) { 

    } 
} 




@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 
    callbackManager.onActivityResult(requestCode, resultCode, data); 
} 



public void goToAttract(View v) 
{ 
    Profile profile = Profile.getCurrentProfile(); 
    getProfile(profile); 

    Intent intent = new Intent(this, MainActivity.class); 
    Bundle b = new Bundle(); 
    b.putString("Nome", name); 
    b.putString("ID", id); 
    intent.putExtras(b); 

    setResult(1, intent); 
    finish(); 
} 



public void getProfile(Profile profile){ 
    if(profile != null){ 
     id = profile.getId().toString(); 
     name = profile.getName().toString(); 

    } 
} 


} 

Это мой фрагмент

public class BlankFragment extends Fragment { 



private CallbackManager callbackManager; 
private TextView textView; 
private ImageView imv; 

private AccessTokenTracker accessTokenTracker; 
private ProfileTracker profileTracker; 
private Button btnVoltar; 

private FacebookCallback<LoginResult> callback = new FacebookCallback<LoginResult>() { 
    @Override 
    public void onSuccess(LoginResult loginResult) { 
     AccessToken accessToken = loginResult.getAccessToken(); 
     Profile profile = Profile.getCurrentProfile(); 

     displayMessage(profile); 

    } 

    @Override 
    public void onCancel() { 

    } 

    @Override 
    public void onError(FacebookException e) { 

    } 
}; 

public BlankFragment() { 

} 


@Override 
public void onCreate(Bundle savedInstanceState){ 
    super.onCreate(savedInstanceState); 



    FacebookSdk.sdkInitialize(getActivity().getApplicationContext()); 

    callbackManager = CallbackManager.Factory.create(); 

    accessTokenTracker= new AccessTokenTracker() { 
     @Override 
     protected void onCurrentAccessTokenChanged(AccessToken oldToken, AccessToken newToken) { 

     } 
    }; 

    profileTracker = new ProfileTracker() { 
     @Override 
     protected void onCurrentProfileChanged(Profile oldProfile, Profile newProfile) { 
      displayMessage(newProfile); 
     } 
    }; 

    accessTokenTracker.startTracking(); 
    profileTracker.startTracking(); 
} 

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
         Bundle savedInstanceState) { 



    return inflater.inflate(R.layout.fragment_blank, container, false); 
} 

@Override 
public void onViewCreated(View view, Bundle savedInstanceState) { 
    super.onViewCreated(view, savedInstanceState); 
    LoginButton loginButton = (LoginButton) view.findViewById(R.id.login_button); 
    textView = (TextView) view.findViewById(R.id.textView); 
    btnVoltar = (Button) view.findViewById(R.id.btnVoltar); 


    loginButton.setReadPermissions("public_profile"); 
    loginButton.setFragment(this); 
    loginButton.registerCallback(callbackManager, callback); 



} 

@Override 
public void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 

    callbackManager.onActivityResult(requestCode, resultCode, data); 


} 

private void displayMessage(Profile profile){ 

    TextView textView = (TextView) getActivity().findViewById(R.id.textView); 
    ProfilePictureView profileImage = (ProfilePictureView) getActivity().findViewById(R.id.profilePicture); 
    profileImage.setProfileId(profile.getId()); 

    if(profile != null){ 
     textView.setText(profile.getName()); 
     profileImage.setProfileId(profile.getId()); 

    } 

} 



@Override 
public void onStop() { 
    super.onStop(); 
    accessTokenTracker.stopTracking(); 
    profileTracker.stopTracking(); 
} 

@Override 
public void onResume() { 
    super.onResume(); 
    Profile profile = Profile.getCurrentProfile(); 
    ProfilePictureView profileImage = (ProfilePictureView) getActivity().findViewById(R.id.profilePicture); 
    profileImage.setProfileId(profile.getId()); 
    displayMessage(profile); 


} 







} 

На моем MainActivity У меня есть боковое меню, ссылки на класс facebook. Он работал нормально. Теперь он начал показывать эту ошибку. Я не понимаю почему.

Любая помощь PLS?

+0

[галочка]: https://uploaddeimagens.com.br/imagens/faceerro-png--2 Всегда получайте эту ошибку. Был поиск ответа здесь часами, но все же не мог понять, почему это происходит. –

ответ

2

Вы должны попробовать читать ваши ошибки:

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.facebook.Profile.getId()' on a null object reference 

Это означает, что объект профиля вы пытаетесь использовать нуль. Выясните, почему он равен нулю. Не предполагайте, потому что он работал до этого, это не проблема. Возможно, это проблема, с которой вы действительно не столкнулись из-за определенных условий.

+0

спасибо, что не помогли –

0

Видимо это работает. Все еще тестирование. Если профиль пуст, он показывает кнопку входа.

@Override 
public void onResume() { 
    super.onResume(); 

    Profile profile = Profile.getCurrentProfile(); 
    if (profile != null) { 
     ProfilePictureView profileImage = (ProfilePictureView) getActivity().findViewById(R.id.profilePicture); 
     profileImage.setProfileId(profile.getId()); 
     displayMessage(profile); 
    } 
} 
Смежные вопросы