本文介绍了与Microsoft帐户Android应用程序认证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是试图建立与微软登录活动。这是我的code ....

I am just trying to create an login activity with microsoft. This is my code....

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;
    }
}

但它显示了.....不幸的是应用具有stopped.And的logcat的显示.........

But it shows.....Unfortunately App has stopped.And the Logcat shows.........

09-13 00:35:50.128:D / AndroidRuntime(2488):关闭VM
09-13 00:35:50.168:W / dalvikvm(2488):主题ID = 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:输入参数'活动'是无效的。 活动不能为空。
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):在java.lang.reflect.Method.invokeNative(本机方法)
09-13 00:35:50.200:E / AndroidRuntime(2488):在java.lang.reflect.Method.invoke(Method.java:525)
09-13 00:35:50.200:E / AndroidRuntime(2488):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:737)
09-13 00:35:50.200:E / AndroidRuntime(2488):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-13 00:35:50.200:E / AndroidRuntime(2488):在dalvik.system.NativeStart.main(本机方法)
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.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 ...更多
1月9日至一十三日:10:22.488:D / AndroidRuntime(2699):关闭VM
1月9日至一十三日:10:22.488:W / dalvikvm(2699):主题ID = 1:螺纹未捕获的异常(组= 0x41465700)退出
1月9日至一十三日:10:22.598:E / AndroidRuntime(2699):致命异常:主要
1月9日至一十三日:10:22.598:E / AndroidRuntime(2699):了java.lang.RuntimeException:无法启动活动ComponentInfo {com.example.microsoft_login / com.example.microsoft_login.MainActivity}:显示java.lang.NullPointerException:输入参数'活动'是无效的。 活动不能为空。
1月9日至一十三日:10:22.598:E / AndroidRuntime(2699):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
1月9日至一十三日:10:22.598:E / AndroidRuntime(2699):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
1月9日至一十三日:10:22.598:E / AndroidRuntime(2699):在android.app.ActivityThread.access $ 600(ActivityThread.java:141)
1月9日至一十三日:10:22.598:E / AndroidRuntime(2699):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1256)
1月9日至一十三日:10:22.598:E / AndroidRuntime(2699):在android.os.Handler.dispatchMessage(Handler.java:99)
1月9日至一十三日:10:22.598:E / AndroidRuntime(2699):在android.os.Looper.loop(Looper.java:137)
1月9日至一十三日:10:22.598:E / AndroidRuntime(2699):在android.app.ActivityThread.main(ActivityThread.java:5103)
1月9日至一十三日:10:22.598:E / AndroidRuntime(2699):在java.lang.reflect.Method.invokeNative(本机方法)
1月9日至一十三日:10:22.598:E / AndroidRuntime(2699):在java.lang.reflect.Method.invoke(Method.java:525)
1月9日至一十三日:10:22.598:E / AndroidRuntime(2699):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:737)
1月9日至一十三日:10:22.598:E / AndroidRuntime(2699):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
1月9日至一十三日:10:22.598:E / AndroidRuntime(2699):在dalvik.system.NativeStart.main(本机方法)
1月9日至一十三日:10:22.598:E / AndroidRuntime(2699):显示java.lang.NullPointerException:由造成输入参数'活动'无效。 活动不能为空。
1月9日至一十三日:10:22.598:E / AndroidRuntime(2699):在com.microsoft.live.LiveConnectUtils.assertNotNull(LiveConnectUtils.java:31)
1月9日至一十三日:10:22.598:E / AndroidRuntime(2699):在com.microsoft.live.LiveAuthClient.login(LiveAuthClient.java:409)
1月9日至一十三日:10:22.598:E / AndroidRuntime(2699):在com.microsoft.live.LiveAuthClient.login(LiveAuthClient.java:384)
1月9日至一十三日:10:22.598:E / AndroidRuntime(2699):在com.example.microsoft_login.MainActivity.onStart(MainActivity.java:32)
1月9日至一十三日:10:22.598:E / AndroidRuntime(2699):在android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1171)
1月9日至一十三日:10:22.598:E / AndroidRuntime(2699):在android.app.Activity.performStart(Activity.java:5143)
1月9日至一十三日:10:22.598:E / AndroidRuntime(2699):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
1月9日至一十三日:10:22.598:E / AndroidRuntime(2699):11 ...更多
1月9日至一十三日:10:3​​0.678:I /流程(2699):发送信号。 PID:2699 SIG:9
1月9日至一十三日:25:16.060:D / AndroidRuntime(2850):关闭VM
1月9日至一十三日:25:16.060:W / dalvikvm(2850):主题ID = 1:螺纹未捕获的异常(组= 0x41465700)退出
1月9日至一十三日:25:16.088:E / AndroidRuntime(2850):致命异常:主要
1月9日至一十三日:25:16.088:E / AndroidRuntime(2850):了java.lang.RuntimeException:无法启动活动ComponentInfo {com.example.microsoft_login / com.example.microsoft_login.MainActivity}:显示java.lang.NullPointerException:输入参数'活动'是无效的。 活动不能为空。
1月9日至一十三日:25:16.088:E / AndroidRuntime(2850):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
1月9日至一十三日:25:16.088:E / AndroidRuntime(2850):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
1月9日至一十三日:25:16.088:E / AndroidRuntime(2850):在android.app.ActivityThread.access $ 600(ActivityThread.java:141)
1月9日至一十三日:25:16.088:E / AndroidRuntime(2850):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1256)
1月9日至一十三日:25:16.088:E / AndroidRuntime(2850):在android.os.Handler.dispatchMessage(Handler.java:99)
1月9日至一十三日:25:16.088:E / AndroidRuntime(2850):在android.os.Looper.loop(Looper.java:137)
1月9日至一十三日:25:16.088:E / AndroidRuntime(2850):在android.app.ActivityThread.main(ActivityThread.java:5103)
1月9日至一十三日:25:16.088:E / AndroidRuntime(2850):在java.lang.reflect.Method.invokeNative(本机方法)
1月9日至一十三日:25:16.088:E / AndroidRuntime(2850):在java.lang.reflect.Method.invoke(Method.java:525)
1月9日至一十三日:25:16.088:E / AndroidRuntime(2850):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:737)
1月9日至一十三日:25:16.088:E / AndroidRuntime(2850):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
1月9日至一十三日:25:16.088:E / AndroidRuntime(2850):在dalvik.system.NativeStart.main(本机方法)
1月9日至一十三日:25:16.088:E / AndroidRuntime(2850):显示java.lang.NullPointerException:由造成输入参数'活动'无效。 活动不能为空。
1月9日至一十三日:25:16.088:E / AndroidRuntime(2850):在com.microsoft.live.LiveConnectUtils.assertNotNull(LiveConnectUtils.java:31)
1月9日至一十三日:25:16.088:E / AndroidRuntime(2850):在com.microsoft.live.LiveAuthClient.login(LiveAuthClient.java:409)
1月9日至一十三日:25:16.088:E / AndroidRuntime(2850):在com.microsoft.live.LiveAuthClient.login(LiveAuthClient.java:384)
1月9日至一十三日:25:16.088:E / AndroidRuntime(2850):在com.example.microsoft_login.MainActivity.onStart(MainActivity.java:32)
1月9日至一十三日:25:16.088:E / AndroidRuntime(2850):在android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1171)
1月9日至一十三日:25:16.088:E / AndroidRuntime(2850):在android.app.Activity.performStart(Activity.java:5143)
1月9日至一十三日:25:16.088:E / AndroidRuntime(2850):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
1月9日至一十三日:25:16.088:E / AndroidRuntime(2850):11 ...更多
1月9日至一十三日:30:16.614:I /流程(2850):发送信号。 PID:2850 SIG:9

09-13 00:35:50.128: D/AndroidRuntime(2488): Shutting down VM09-13 00:35:50.168: W/dalvikvm(2488): threadid=1: thread exiting with uncaught exception (group=0x41465700)09-13 00:35:50.200: E/AndroidRuntime(2488): FATAL EXCEPTION: main09-13 00:35:50.200: E/AndroidRuntime(2488): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.microsoft_login/com.example.microsoft_login.MainActivity}: java.lang.NullPointerException: Input parameter 'activity' is invalid. 'activity' cannot be null.09-13 00:35:50.200: E/AndroidRuntime(2488): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)09-13 00:35:50.200: E/AndroidRuntime(2488): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)09-13 00:35:50.200: E/AndroidRuntime(2488): at android.app.ActivityThread.access$600(ActivityThread.java:141)09-13 00:35:50.200: E/AndroidRuntime(2488): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)09-13 00:35:50.200: E/AndroidRuntime(2488): at android.os.Handler.dispatchMessage(Handler.java:99)09-13 00:35:50.200: E/AndroidRuntime(2488): at android.os.Looper.loop(Looper.java:137)09-13 00:35:50.200: E/AndroidRuntime(2488): at 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): Caused by: java.lang.NullPointerException: Input parameter 'activity' is invalid. 'activity' cannot be null.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): at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1171)09-13 00:35:50.200: E/AndroidRuntime(2488): at android.app.Activity.performStart(Activity.java:5143)09-13 00:35:50.200: E/AndroidRuntime(2488): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)09-13 00:35:50.200: E/AndroidRuntime(2488): ... 11 more09-13 01:10:22.488: D/AndroidRuntime(2699): Shutting down VM09-13 01:10:22.488: W/dalvikvm(2699): threadid=1: thread exiting with uncaught exception (group=0x41465700)09-13 01:10:22.598: E/AndroidRuntime(2699): FATAL EXCEPTION: main09-13 01:10:22.598: E/AndroidRuntime(2699): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.microsoft_login/com.example.microsoft_login.MainActivity}: java.lang.NullPointerException: Input parameter 'activity' is invalid. 'activity' cannot be null.09-13 01:10:22.598: E/AndroidRuntime(2699): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)09-13 01:10:22.598: E/AndroidRuntime(2699): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)09-13 01:10:22.598: E/AndroidRuntime(2699): at android.app.ActivityThread.access$600(ActivityThread.java:141)09-13 01:10:22.598: E/AndroidRuntime(2699): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)09-13 01:10:22.598: E/AndroidRuntime(2699): at android.os.Handler.dispatchMessage(Handler.java:99)09-13 01:10:22.598: E/AndroidRuntime(2699): at android.os.Looper.loop(Looper.java:137)09-13 01:10:22.598: E/AndroidRuntime(2699): at 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): Caused by: java.lang.NullPointerException: Input parameter 'activity' is invalid. 'activity' cannot be null.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): at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1171)09-13 01:10:22.598: E/AndroidRuntime(2699): at android.app.Activity.performStart(Activity.java:5143)09-13 01:10:22.598: E/AndroidRuntime(2699): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)09-13 01:10:22.598: E/AndroidRuntime(2699): ... 11 more09-13 01:10:30.678: I/Process(2699): Sending signal. PID: 2699 SIG: 909-13 01:25:16.060: D/AndroidRuntime(2850): Shutting down VM09-13 01:25:16.060: W/dalvikvm(2850): threadid=1: thread exiting with uncaught exception (group=0x41465700)09-13 01:25:16.088: E/AndroidRuntime(2850): FATAL EXCEPTION: main09-13 01:25:16.088: E/AndroidRuntime(2850): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.microsoft_login/com.example.microsoft_login.MainActivity}: java.lang.NullPointerException: Input parameter 'activity' is invalid. 'activity' cannot be null.09-13 01:25:16.088: E/AndroidRuntime(2850): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)09-13 01:25:16.088: E/AndroidRuntime(2850): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)09-13 01:25:16.088: E/AndroidRuntime(2850): at android.app.ActivityThread.access$600(ActivityThread.java:141)09-13 01:25:16.088: E/AndroidRuntime(2850): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)09-13 01:25:16.088: E/AndroidRuntime(2850): at android.os.Handler.dispatchMessage(Handler.java:99)09-13 01:25:16.088: E/AndroidRuntime(2850): at android.os.Looper.loop(Looper.java:137)09-13 01:25:16.088: E/AndroidRuntime(2850): at 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): Caused by: java.lang.NullPointerException: Input parameter 'activity' is invalid. 'activity' cannot be null.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): at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1171)09-13 01:25:16.088: E/AndroidRuntime(2850): at android.app.Activity.performStart(Activity.java:5143)09-13 01:25:16.088: E/AndroidRuntime(2850): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)09-13 01:25:16.088: E/AndroidRuntime(2850): ... 11 more09-13 01:30:16.614: I/Process(2850): Sending signal. PID: 2850 SIG: 9

推荐答案

它已经有一段时间,因为你张贴了这个,所以我不知道你是否还需要帮助,但似乎你的错误是在这条线(在你的在onStart()):

it's been a while since you posted this, so i'm not sure if you still need help, but it seems your error is on this line (in your onStart()):

this.auth.login(NULL,范围,这一点);

this.auth.login(null, scopes, this);

如果你用这个替换为空,这应该解决这个问题。

if you replace the null with "this", that should fix the problem.

auth.login(this, scopes, this);

从微软的登录方法如下:

the login method from microsoft is as below:

公共无效登录(活动活动,可迭代范围,LiveAuthListener听众){
    this.login(活动范围,监听器,NULL);

public void login(Activity activity, Iterable scopes, LiveAuthListener listener) { this.login(activity, scopes, listener, null);

和需要的活动(在那里将绘制自身)。在code片断,你给它提供空。

and requires an activity (where it will draw itself). in your code snippet, you provided null to it.

这篇关于与Microsoft帐户Android应用程序认证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-08 04:36