我有一个启动活动,之后会打开一个包含facebook登录信息的活动。一旦启动活动完成,应用程序就会崩溃。这是堆栈跟踪
06-17 19:56:02.550 28595-28595/com.android.dride.dride E/AndroidRuntime: Process: com.android.dride.dride, PID: 28595
06-17 19:56:02.550 28595-28595/com.android.dride.dride E/AndroidRuntime: java.lang.NullPointerException: Argument 'context' cannot be null
06-17 19:56:02.550 28595-28595/com.android.dride.dride E/AndroidRuntime: at com.facebook.internal.Validate.notNull(Validate.java:76)
06-17 19:56:02.550 28595-28595/com.android.dride.dride E/AndroidRuntime: at com.facebook.internal.Utility.getMetadataApplicationId(Utility.java:594)
06-17 19:56:02.550 28595-28595/com.android.dride.dride E/AndroidRuntime: at com.facebook.appevents.AppEventsLogger.<init>(AppEventsLogger.java:757)
06-17 19:56:02.550 28595-28595/com.android.dride.dride E/AndroidRuntime: at com.facebook.appevents.AppEventsLogger.<init>(AppEventsLogger.java:732)
06-17 19:56:02.550 28595-28595/com.android.dride.dride E/AndroidRuntime: at com.facebook.appevents.AppEventsLogger.newLogger(AppEventsLogger.java:400)
06-17 19:56:02.550 28595-28595/com.android.dride.dride E/AndroidRuntime: at com.facebook.FacebookButtonBase.logButtonCreated(FacebookButtonBase.java:225)
06-17 19:56:02.550 28595-28595/com.android.dride.dride E/AndroidRuntime: at com.facebook.FacebookButtonBase.onAttachedToWindow(FacebookButtonBase.java:136)
06-17 19:56:02.550 28595-28595/com.android.dride.dride E/AndroidRuntime: at com.facebook.login.widget.LoginButton.onAttachedToWindow(LoginButton.java:452)
06-17 19:56:02.550 28595-28595/com.android.dride.dride E/AndroidRuntime: at android.view.View.dispatchAttachedToWindow(View.java:13795)
06-17 19:56:02.550 28595-28595/com.android.dride.dride E/AndroidRuntime: at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2828)
06-17 19:56:02.550 28595-28595/com.android.dride.dride E/AndroidRuntime: at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2828)
06-17 19:56:02.550 28595-28595/com.android.dride.dride E/AndroidRuntime: at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2828)
06-17 19:56:02.550 28595-28595/com.android.dride.dride E/AndroidRuntime: at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2828)
06-17 19:56:02.550 28595-28595/com.android.dride.dride E/AndroidRuntime: at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2828)
06-17 19:56:02.550 28595-28595/com.android.dride.dride E/AndroidRuntime: at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2828)
06-17 19:56:02.550 28595-28595/com.android.dride.dride E/AndroidRuntime: at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1602)
06-17 19:56:02.550 28595-28595/com.android.dride.dride E/AndroidRuntime: at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1343)
06-17 19:56:02.550 28595-28595/com.android.dride.dride E/AndroidRuntime: at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6853)
06-17 19:56:02.550 28595-28595/com.android.dride.dride E/AndroidRuntime: at android.view.Choreographer$CallbackRecord.run(Choreographer.java:825)
06-17 19:56:02.550 28595-28595/com.android.dride.dride E/AndroidRuntime: at android.view.Choreographer.doCallbacks(Choreographer.java:619)
06-17 19:56:02.550 28595-28595/com.android.dride.dride E/AndroidRuntime: at android.view.Choreographer.doFrame(Choreographer.java:579)
06-17 19:56:02.550 28595-28595/com.android.dride.dride E/AndroidRuntime: at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:811)
06-17 19:56:02.550 28595-28595/com.android.dride.dride E/AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:815)
06-17 19:56:02.550 28595-28595/com.android.dride.dride E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:104)
06-17 19:56:02.550 28595-28595/com.android.dride.dride E/AndroidRuntime: at android.os.Looper.loop(Looper.java:214)
06-17 19:56:02.550 28595-28595/com.android.dride.dride E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:6102)
06-17 19:56:02.550 28595-28595/com.android.dride.dride E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
06-17 19:56:02.550 28595-28595/com.android.dride.dride E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:372)
06-17 19:56:02.550 28595-28595/com.android.dride.dride E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1028)
06-17 19:56:02.550 28595-28595/com.android.dride.dride E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
即使我没有对登录活动代码进行任何更改,但这个问题已经开始出现了令人困惑的问题。请帮忙。
我理解什么是nullPointerException。它在过去1个月一直运作良好。现在我已经开始无处可去解决这个问题,这很奇怪。
public class LoginActivity extends AppCompatActivity{
private CallbackManager callbackManager;
private LoginButton loginButton;
private ImageView b_fb_login;
//loader related
private CustomProgress progressDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//initialize facebook sdk
FacebookSdk.sdkInitialize(LoginActivity.this);
setContentView(R.layout.activity_login);
//logout previously logged in accounts
//for fb
Log.i("check","here");
LoginManager.getInstance().logOut();
Log.i("check","there");
//loader related
progressDialog = new CustomProgress(this);
}
@Override
protected void onResume() {
super.onResume();
//checking if user is logged in
Log.i("check","resume");
if (PrefUtils.getCurrentUser(LoginActivity.this) != null) {
Intent intent = new Intent(LoginActivity.this, XYZActivity.class);
startActivity(intent);
overridePendingTransition(R.anim.enter, R.anim.exit);
finish();
}
callbackManager = CallbackManager.Factory.create();
loginButton = (LoginButton) findViewById(R.id.login_button);
loginButton.setReadPermissions("public_profile", "email", "basic_info");
b_fb_login = (ImageView) findViewById(R.id.b_fb_login);
Log.i("check", "1");
b_fb_login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (isInternetAvailable()) {
loginButton.performClick();
loginButton.setPressed(true);
loginButton.invalidate();
loginButton.registerCallback(callbackManager, mCallBack);
// loginButton.setPressed(false);
loginButton.invalidate();
} else {
Toast.makeText(getApplicationContext(), getStringFromId(R.string.no_internet), Toast.LENGTH_LONG).show();
}
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
progressDialog.show();
callbackManager.onActivityResult(requestCode, resultCode, data);
}
}
private FacebookCallback<LoginResult> mCallBack = new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
// App code
GraphRequest request = GraphRequest.newMeRequest(
loginResult.getAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(
JSONObject object,
GraphResponse response) {
Log.e("response: ", response + "");
try {
String email = object.getString("email");
String name = object.getString("name");
String gender = object.getString("gender");
String id = object.getString("id");
// Toast.makeText(getApplicationContext(),object.getString("gender")+object.getString("id"),Toast.LENGTH_LONG).show();
nextScreen(email, getStringFromId(R.string.login_type_facebook), name,id);
} catch (Exception e) {
e.printStackTrace();
}
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "name,email,gender,id");
request.setParameters(parameters);
request.executeAsync();
}
@Override
public void onCancel() {
progressDialog.cancel1();
Toast.makeText(getApplicationContext(), getStringFromId(R.string.unable_login), Toast.LENGTH_LONG).show();
}
@Override
public void onError(FacebookException e) { //when no internet connection
progressDialog.cancel1();
Toast.makeText(getApplicationContext(), getStringFromId(R.string.unable_login), Toast.LENGTH_LONG).show();
}};
public void nextScreen(String email, String login_type, String name,String login_id) {
progressDialog.cancel1();
Intent intent = new Intent(LoginActivity.this, GetMobileActivity.class);
intent.putExtra("login_type", login_type);
intent.putExtra("email", email);
intent.putExtra("name", name);
intent.putExtra("login_id",login_id);
startActivity(intent);
overridePendingTransition(R.anim.enter, R.anim.exit);
}
}
答案 0 :(得分:1)
继续使用gradle并执行此操作:
from: compile 'com.facebook.android:facebook-android-sdk:4.+
to: compile 'com.facebook.android:facebook-android-sdk:4.12.1'