Java Android Studio NullPointerException,正在尝试使用parse.com

Java Android Studio NullPointerException,正在尝试使用parse.com,java,android,parse-platform,nullpointerexception,Java,Android,Parse Platform,Nullpointerexception,我正在尝试使用Parse.com为我的应用程序进行用户登录/注册活动,我正在学习如何使用本教程。但在我输入所有内容后,我的应用程序不断崩溃,并给出NullPointerException 这是我的主要活动 package com.example.ed.parselogintutorial; import android.app.Activity; import android.content.Intent; import android.support.v7.app.ActionBarActi

我正在尝试使用Parse.com为我的应用程序进行用户登录/注册活动,我正在学习如何使用本教程。但在我输入所有内容后,我的应用程序不断崩溃,并给出NullPointerException

这是我的主要活动

package com.example.ed.parselogintutorial;

import android.app.Activity;
import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

import com.parse.Parse;
import com.parse.ParseAnonymousUtils;
import com.parse.ParseUser;


public class MainActivity extends Activity {

    public void onCreate(Bundle savedInstanceState) {

        // Enable Local Datastore.
        Parse.enableLocalDatastore(this);

        Parse.initialize(this, "T9so2huSfs1xMHwEjx9vSeUuKeyBZsXVyG4QHi7K", "yiQz0RMs9TCkWu8EsdsoVxcPWGlTyAmO20JuEh0X");

        super.onCreate(savedInstanceState);

        //Determine whether the current user is an anonymous user
        if (ParseAnonymousUtils.isLinked(ParseUser.getCurrentUser())) {
            //If user is anonymous, send the user to LoginSignupActivity.class
            Intent intent = new Intent(MainActivity.this,
                    LoginSignupActivity.class);
            startActivity(intent);
            finish();
        } else {
            //If current user is no anonymous user
            //Get current user data from Parse.com
            ParseUser currentUser = ParseUser.getCurrentUser();
            if (currentUser != null) {
                //Send logged in users to Welcome.class
                Intent intent = new Intent(MainActivity.this, Welcome.class);
                startActivity(intent);
                finish();
            } else {
                //Send User to LoginSignupActivity.class
                Intent intent = new Intent(MainActivity.this,
                        LoginSignupActivity.class);
                startActivity(intent);
                finish();
            }
        }
    }


}
这是书堆

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.ed.parselogintutorial/com.example.ed.parselogintutorial.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean com.parse.ParseUser.isLinked(java.lang.String)' on a null object reference
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
        at android.app.ActivityThread.access$800(ActivityThread.java:151)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5257)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
asdsa


我很抱歉,如果这里有一个非常明显的错误,因为我是android开发新手,请之前使用Parse.com的任何人,或者有任何关于此错误的知识,请教我如何解决它。提前感谢。

阅读教程中的以下注释,给定代码存在问题。以下是其中一条评论的建议:

时间还早,所以我不太确定他们来这里干什么。。。收到 去掉ParseApplication.java并将其放入 mainactivity.java


本质上,问题在于您没有调用setContentViewR.layout.activity_main;在您尝试调用解析函数之前。

我不确定这是否是问题所在,因为我不熟悉解析,但您是从活动类调用解析方法,而教程是从应用程序类调用它们。哦,是的,我错过了ParseApplication类,感谢您注意到这一点。我现在将尝试创建ParseApplication。谢谢在我添加了ParseApplication类之后,出现了以下错误:无法启动activity ComponentInfo{com.example.ed.parselogintutorial/com.example.ed.parselogintutorial.MainActivity}:java.lang.RuntimeException:在使用解析库之前,必须调用Parse.initializecontext、oauthKey、oauthSecret。如何在MainActivity中调用ParseApplication类?很抱歉提出了愚蠢的问题,需要帮助,谢谢。实际上我解决了它,问题是我没有在应用程序的AndroidManifest中写这行:android:name=ParseApplication。非常感谢你的帮助。非常感谢。
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean com.parse.ParseUser.isLinked(java.lang.String)' on a null object reference
        at com.parse.ParseAnonymousUtils.isLinked(ParseAnonymousUtils.java:51)
        at com.example.ed.parselogintutorial.MainActivity.onCreate(MainActivity.java:28)
        at android.app.Activity.performCreate(Activity.java:5990)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)  
        android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390) 
        at android.app.ActivityThread.access$800(ActivityThread.java:151)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5257)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main); <<----UNDER THIS (left in for location purpose)

// Add your initialization code here

Parse.initialize(this, "YOUR_APPLICATION_ID", "YOUR_CLIENT_KEY");

ParseUser.enableAutomaticUser();

ParseACL defaultACL = new ParseACL();

// If you would like all objects to be private by default, remove this

// line.

defaultACL.setPublicReadAccess(true);

ParseACL.setDefaultACL(defaultACL, true);

// Determine whether the current user is an anonymous user

if (ParseAnonymousUtils.isLinked(ParseUser.getCurrentUser())) { <<----(left in for location purpose)