我只是想用微软创建一个登录活动。这是我的代码....
package com.example.microsoft_login;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import java.util.Arrays;
import com.microsoft.live.LiveAuthException;
import com.microsoft.live.LiveAuthListener;
import com.microsoft.live.LiveAuthClient;
import com.microsoft.live.LiveConnectSession;
import com.microsoft.live.LiveConnectClient;
import com.microsoft.live.LiveStatus;
public class MainActivity extends Activity implements LiveAuthListener {
private LiveAuthClient auth;
private LiveConnectClient client;
private TextView resultTextView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.resultTextView = (TextView)findViewById(R.id.resultTextView);
this.auth = new LiveAuthClient(this, MyConstants.APP_CLIENT_ID);
}
@Override
protected void onStart() {
super.onStart();
Iterable<String> scopes = Arrays.asList("wl.signin", "wl.basic");
this.auth.login(null, scopes, this);
}
public void onAuthComplete(LiveStatus status, LiveConnectSession session, Object userState) {
if(status == LiveStatus.CONNECTED) {
this.resultTextView.setText("Signed in.");
client = new LiveConnectClient(session);
}
else {
this.resultTextView.setText("Not signed in.");
client = null;
}
}
public void onAuthError(LiveAuthException exception, Object userState) {
this.resultTextView.setText("Error signing in: " + exception.getMessage());
client = null;
}
}
但它显示......不幸的是应用程序已停止。并且 Logcat 显示............
09-13 00:35:50.128: D/AndroidRuntime(2488): 关闭 VM 09-13 00:35:50.168: W/dalvikvm(2488): threadid=1: 线程退出未捕获异常 (group=0x41465700) 09 -13 00:35:50.200: E/AndroidRuntime(2488): 致命异常: main 09-13 00:35:50.200: E/AndroidRuntime(2488): java.lang.RuntimeException: 无法启动活动 ComponentInfo{com.example .microsoft_login/com.example.microsoft_login.MainActivity}:java.lang.NullPointerException:输入参数“活动”无效。“活动”不能为空。09-13 00:35:50.200: E/AndroidRuntime(2488): 在 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211) 09-13 00:35:50.200: E/AndroidRuntime(2488): 在 android. app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261) 09-13 00:35:50.200: E/AndroidRuntime(2488): 在 android.app.ActivityThread。internal.os.ZygoteInit.main(ZygoteInit.java:553) 09-13 00:35:50.200: E/AndroidRuntime(2488): at dalvik.system.NativeStart.main(Native Method) 09-13 00:35:50.200 :E / AndroidRuntime(2488):引起:java.lang.NullPointerException:输入参数“活动”无效。“活动”不能为空。09-13 00:35:50.200: E/AndroidRuntime(2488): 在 com.microsoft.live.LiveConnectUtils.assertNotNull(LiveConnectUtils.java:31) 09-13 00:35:50.200: E/AndroidRuntime(2488): 在com.microsoft.live.LiveAuthClient.login(LiveAuthClient.java:409) 09-13 00:35:50.200: E/AndroidRuntime(2488): 在 com.microsoft.live.LiveAuthClient.login(LiveAuthClient.java:384) 09 -13 00:35:50.200: E/AndroidRuntime(2488): 在 com.example.microsoft_login.MainActivity.onStart(MainActivity.java:32) 09-13 00:35:50.200: E/AndroidRuntime(2488): 在 android 。应用程序。Instrumentation.callActivityOnStart(Instrumentation.java:1171) 09-13 00:35:50.200: E/AndroidRuntime(2488): 在 android.app.Activity.performStart(Activity.java:5143) 09-13 00:35:50.200: E/AndroidRuntime(2488): 在 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184) 09-13 00:35:50.200: E/AndroidRuntime(2488): ... 11 更多 09-13 01:10: 22.488: D/AndroidRuntime(2699): 关闭 VM 09-13 01:10:22.488: W/dalvikvm(2699): threadid=1: 线程退出未捕获异常 (group=0x41465700) 09-13 01:10:22.598 :E/AndroidRuntime(2699):致命异常:主 09-13 01:10:22.598:E/AndroidRuntime(2699):java.lang.RuntimeException:无法启动活动 ComponentInfo{com.example.microsoft_login/com.example。 microsoft_login.MainActivity}:java.lang.NullPointerException:输入参数“活动”无效。' 活动'不能为空。09-13 01:10:22.598: E/AndroidRuntime(2699): 在 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211) 09-13 01:10:22.598: E/AndroidRuntime(2699): 在 android. app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261) 09-13 01:10:22.598: E/AndroidRuntime(2699): 在 android.app.ActivityThread.access$600(ActivityThread.java:141) 09-13 01:10 :22.598: E/AndroidRuntime(2699): 在 android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256) 09-13 01:10:22.598: E/AndroidRuntime(2699): 在 android.os.Handler。 dispatchMessage(Handler.java:99) 09-13 01:10:22.598: E/AndroidRuntime(2699): 在 android.os.Looper.loop(Looper.java:137) 09-13 01:10:22.598: E/ AndroidRuntime(2699): 在 android.app.ActivityThread.main(ActivityThread.java:5103) 09-13 01:10:22.598: E/AndroidRuntime(2699): at java.lang.reflect.Method.invokeNative(Native Method) 09-13 01:10:22.598: E/AndroidRuntime(2699): at java.lang.reflect.Method.invoke(Method. java:525) 09-13 01:10:22.598: E/AndroidRuntime(2699): 在 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737) 09-13 01:10:22.598: E/AndroidRuntime(2699): 在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 09-13 01:10:22.598: E/AndroidRuntime(2699): 在 dalvik.system.NativeStart.main (本机方法)09-13 01:10:22.598:E/AndroidRuntime(2699):原因:java.lang.NullPointerException:输入参数“活动”无效。“活动”不能为空。09-13 01:10:22.598: E/AndroidRuntime(2699): 在 com.microsoft.live.LiveConnectUtils.assertNotNull(LiveConnectUtils.java:31) 09-13 01:10:22.598: E/AndroidRuntime(2699): 在 com.microsoft.live.LiveAuthClient.login(LiveAuthClient.java:409) 09-13 01:10:22.598: E/AndroidRuntime(2699): 在 com.microsoft.live.LiveAuthClient.login (LiveAuthClient.java:384) 09-13 01:10:22.598: E/AndroidRuntime(2699): at com.example.microsoft_login.MainActivity.onStart(MainActivity.java:32) 09-13 01:10:22.598: E /AndroidRuntime(2699): 在 android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1171) 09-13 01:10:22.598: E/AndroidRuntime(2699): 在 android.app.Activity.performStart(Activity.java: 5143) 09-13 01:10:22.598: E/AndroidRuntime(2699): 在 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184) 09-13 01:10:22.598: E/AndroidRuntime(2699):. .. 11 更多 09-13 01:10:30.678: I/Process(2699): 发送信号。PID: 2699 SIG: 9 09-13 01:25:16.060: D / AndroidRuntime(2850):关闭VM 09-13 01:25:16.060:W / dalvikvm(2850):threadid = 1:线程退出未捕获的异常(组= 0x41465700)09-13 01:25:16.088:E /AndroidRuntime(2850): 致命异常: main 09-13 01:25:16.088: E/AndroidRuntime(2850): java.lang.RuntimeException: 无法启动活动 ComponentInfo{com.example.microsoft_login/com.example.microsoft_login. MainActivity}:java.lang.NullPointerException:输入参数“活动”无效。“活动”不能为空。09-13 01:25:16.088: E/AndroidRuntime(2850): 在 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211) 09-13 01:25:16.088: E/AndroidRuntime(2850): 在 android. app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261) 09-13 01:25:16.088: E/AndroidRuntime(2850): 在 android.app.ActivityThread。internal.os.ZygoteInit.main(ZygoteInit.java:553) 09-13 01:25:16.088: E/AndroidRuntime(2850): at dalvik.system.NativeStart.main(Native Method) 09-13 01:25:16.088 :E/AndroidRuntime(2850):引起:java.lang.NullPointerException:输入参数“活动”无效。“活动”不能为空。09-13 01:25:16.088: E/AndroidRuntime(2850): 在 com.microsoft.live.LiveConnectUtils.assertNotNull(LiveConnectUtils.java:31) 09-13 01:25:16.088: E/AndroidRuntime(2850): 在com.microsoft.live.LiveAuthClient.login(LiveAuthClient.java:409) 09-13 01:25:16.088: E/AndroidRuntime(2850): 在 com.microsoft.live.LiveAuthClient.login(LiveAuthClient.java:384) 09 -13 01:25:16.088: E/AndroidRuntime(2850): 在 com.example.microsoft_login.MainActivity.onStart(MainActivity.java:32) 09-13 01:25:16.088: E/AndroidRuntime(2850): 在 android 。应用程序。Instrumentation.callActivityOnStart(Instrumentation.java:1171) 09-13 01:25:16.088: E/AndroidRuntime(2850): 在 android.app.Activity.performStart(Activity.java:5143) 09-13 01:25:16.088: E/AndroidRuntime(2850): 在 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184) 09-13 01:25:16.088: E/AndroidRuntime(2850): ... 11 更多 09-13 01:30: 16.614:I/Process(2850):发送信号。PID:2850 SIG:9