我在我的应用中尝试使用google plus添加注册时遇到问题,但是我收到此错误:
10-15 16:30:04.697: E/AndroidRuntime(24508): FATAL EXCEPTION: main
10-15 16:30:04.697: E/AndroidRuntime(24508): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=9000, result=0, data=null} to activity {com.mycompany.myapp/com.mycompany.myapp.activities.SignUp}: java.lang.NullPointerException
10-15 16:30:04.697: E/AndroidRuntime(24508): at android.app.ActivityThread.deliverResults(ActivityThread.java:3000)
10-15 16:30:04.697: E/AndroidRuntime(24508): at android.app.ActivityThread.handleSendResult(ActivityThread.java:3043)
10-15 16:30:04.697: E/AndroidRuntime(24508): at android.app.ActivityThread.access$1100(ActivityThread.java:127)
10-15 16:30:04.697: E/AndroidRuntime(24508): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1188)
10-15 16:30:04.697: E/AndroidRuntime(24508): at android.os.Handler.dispatchMessage(Handler.java:99)
10-15 16:30:04.697: E/AndroidRuntime(24508): at android.os.Looper.loop(Looper.java:137)
10-15 16:30:04.697: E/AndroidRuntime(24508): at android.app.ActivityThread.main(ActivityThread.java:4441)
10-15 16:30:04.697: E/AndroidRuntime(24508): at java.lang.reflect.Method.invokeNative(Native Method)
10-15 16:30:04.697: E/AndroidRuntime(24508): at java.lang.reflect.Method.invoke(Method.java:511)
10-15 16:30:04.697: E/AndroidRuntime(24508): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
10-15 16:30:04.697: E/AndroidRuntime(24508): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
10-15 16:30:04.697: E/AndroidRuntime(24508): at dalvik.system.NativeStart.main(Native Method)
10-15 16:30:04.697: E/AndroidRuntime(24508): Caused by: java.lang.NullPointerException
10-15 16:30:04.697: E/AndroidRuntime(24508): at com.mycompany.myapp.activities.SignUp.onActivityResult(SignUp.java:313)
10-15 16:30:04.697: E/AndroidRuntime(24508): at android.app.Activity.dispatchActivityResult(Activity.java:4649)
10-15 16:30:04.697: E/AndroidRuntime(24508): at android.app.ActivityThread.deliverResults(ActivityThread.java:2996)
10-15 16:30:04.697: E/AndroidRuntime(24508): ... 11 more
以下是我所拥有的代码:
private static final int REQUEST_CODE_RESOLVE_ERR = 9000;
private ProgressDialog mConnectionProgressDialog;
private PlusClient mPlusClient;
private ConnectionResult mConnectionResult;
private SignInButton signupButtonPlus;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.signup);
mPlusClient = new PlusClient.Builder(this, this, this)
.setVisibleActivities("http://schemas.google.com/AddActivity",
"http://schemas.google.com/BuyActivity")
.setScopes("PLUS_LOGIN") // Space separated list of scopes
.build();
initWidgets();
}
我在initwidgets()
中的:
mConnectionProgressDialog = new ProgressDialog(this);
mConnectionProgressDialog.setMessage("Signing in...");
signupButtonPlus = (SignInButton) findViewById(R.id.sign_in_button_plus);
signupButtonPlus.setOnClickListener(this);
其余的google plus东西:
@Override
public void onClick(View v) {
if (v.getId() == R.id.sign_in_button_plus) {
Log.v("--", "gplus");
if (!mPlusClient.isConnected()) {
mPlusClient.connect();
}
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode,
android.content.Intent data) {
Log.v("--", resultCode+" fb");
if (requestCode == REQUEST_CODE_RESOLVE_ERR && resultCode == RESULT_OK) {
mConnectionResult = null;
mPlusClient.connect();
} else
fbLoginManager.loginSuccess(data);
}
@Override
public void onDisconnected() {
Log.e("gPlus", "disconnected");
}
@Override
public void onConnected(Bundle b) {
String accountName = mPlusClient.getAccountName();
Toast.makeText(this, accountName + " is connected.", Toast.LENGTH_LONG)
.show();
}