我只是想用microsoft创建一个登录活动。这是我的代码......
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;
}
}
但它显示.....不幸的是App停止了。而Logcat显示.........
09-13 00:35:50.128:D / AndroidRuntime(2488):关闭VM 09-13 00:35:50.168:W / dalvikvm(2488):threadid = 1:线程退出,未捕获异常(组= 0x41465700) 09-13 00:35:50.200:E / AndroidRuntime(2488):致命异常:主要 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:输入参数&#39;活动&#39;是无效的。 &#39;活动&#39;不能为空。 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.access $ 600(ActivityThread.java:141) 09-13 00:35:50.200:E / AndroidRuntime(2488):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1256) 09-13 00:35:50.200:E / AndroidRuntime(2488):在android.os.Handler.dispatchMessage(Handler.java:99) 09-13 00:35:50.200:E / AndroidRuntime(2488):在android.os.Looper.loop(Looper.java:137) 09-13 00:35:50.200:E / AndroidRuntime(2488):在android.app.ActivityThread.main(ActivityThread.java:5103) 09-13 00:35:50.200:E / AndroidRuntime(2488):at java.lang.reflect.Method.invokeNative(Native Method) 09-13 00:35:50.200:E / AndroidRuntime(2488):at java.lang.reflect.Method.invoke(Method.java:525) 09-13 00:35:50.200:E / AndroidRuntime(2488):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:737) 09-13 00:35:50.200:E / AndroidRuntime(2488):at com.android.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:输入参数&#39; activity&#39;是无效的。 &#39;活动&#39;不能为空。 09-13 00:35:50.200:E / AndroidRuntime(2488):at com.microsoft.live.LiveConnectUtils.assertNotNull(LiveConnectUtils.java:31) 09-13 00:35:50.200:E / AndroidRuntime(2488):at com.microsoft.live.LiveAuthClient.login(LiveAuthClient.java:409) 09-13 00:35:50.200:E / AndroidRuntime(2488):at com.microsoft.live.LiveAuthClient.login(LiveAuthClient.java:384) 09-13 00:35:50.200:E / AndroidRuntime(2488):at com.example.microsoft_login.MainActivity.onStart(MainActivity.java:32) 09-13 00:35:50.200:E / AndroidRuntime(2488):在android.app.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):关闭虚拟机 09-13 01:10:22.488:W / dalvikvm(2699):threadid = 1:线程退出时未捕获异常(组= 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:输入参数&#39;活动&#39;是无效的。 &#39;活动&#39;不能为空。 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):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:737) 09-13 01:10:22.598:E / AndroidRuntime(2699):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 09-13 01:10:22.598:E / AndroidRuntime(2699):at dalvik.system.NativeStart.main(Native Method) 09-13 01:10:22.598:E / AndroidRuntime(2699):引起:java.lang.NullPointerException:输入参数&#39; activity&#39;是无效的。 &#39;活动&#39;不能为空。 09-13 01:10:22.598:E / AndroidRuntime(2699):at com.microsoft.live.LiveConnectUtils.assertNotNull(LiveConnectUtils.java:31) 09-13 01:10:22.598:E / AndroidRuntime(2699):at com.microsoft.live.LiveAuthClient.login(LiveAuthClient.java:409) 09-13 01:10:22.598:E / AndroidRuntime(2699):at 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):致命异常:主要 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:输入参数&#39;活动&#39;是无效的。 &#39;活动&#39;不能为空。 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.access $ 600(ActivityThread.java:141) 09-13 01:25:16.088:E / AndroidRuntime(2850):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1256) 09-13 01:25:16.088:E / AndroidRuntime(2850):在android.os.Handler.dispatchMessage(Handler.java:99) 09-13 01:25:16.088:E / AndroidRuntime(2850):在android.os.Looper.loop(Looper.java:137) 09-13 01:25:16.088:E / AndroidRuntime(2850):在android.app.ActivityThread.main(ActivityThread.java:5103) 09-13 01:25:16.088:E / AndroidRuntime(2850):at java.lang.reflect.Method.invokeNative(Native Method) 09-13 01:25:16.088:E / AndroidRuntime(2850):at java.lang.reflect.Method.invoke(Method.java:525) 09-13 01:25:16.088:E / AndroidRuntime(2850):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:737) 09-13 01:25:16.088:E / AndroidRuntime(2850):at com.android.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:输入参数&#39; activity&#39;是无效的。 &#39;活动&#39;不能为空。 09-13 01:25:16.088:E / AndroidRuntime(2850):at com.microsoft.live.LiveConnectUtils.assertNotNull(LiveConnectUtils.java:31) 09-13 01:25:16.088:E / AndroidRuntime(2850):at com.microsoft.live.LiveAuthClient.login(LiveAuthClient.java:409) 09-13 01:25:16.088:E / AndroidRuntime(2850):at com.microsoft.live.LiveAuthClient.login(LiveAuthClient.java:384) 09-13 01:25:16.088:E / AndroidRuntime(2850):at com.example.microsoft_login.MainActivity.onStart(MainActivity.java:32) 09-13 01:25:16.088:E / AndroidRuntime(2850):在android.app.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
答案 0 :(得分:0)
自从您发布此内容已经有一段时间了,所以我不确定您是否还需要帮助,但似乎您的错误就在这一行(在您的onStart()中):
this.auth.login(null,scopes,this);
如果用“this”替换null,那应该可以解决问题。
auth.login(this, scopes, this);
microsoft的登录方法如下:
public void login(活动活动,Iterable范围,LiveAuthListener侦听器){ this.login(activity,scopes,listener,null);
并且需要一个活动(它将自己绘制)。在你的代码片段中,你提供了null。