如何修复logcat中的错误?

时间:2015-09-24 18:00:57

标签: java android eclipse

每个人都好!

我是android编程新手,我在logcat中遇到错误,控制台没有错误。我试着一遍又一遍地搜索,但似乎我是唯一一个面临这些错误的人。

BTW这个代码不是我的,我在教程中发现它特别是" Sinch Group Chat"如果你在google上搜索一下这个很受欢迎。除了它是谷歌我在Eclipse上适应它,我相信他们为Android Studio制作了这个教程。

09-24 13:47:52.195: E/AndroidRuntime(1467): FATAL EXCEPTION: main
09-24 13:47:52.195: E/AndroidRuntime(1467): Process: com.groupchat, PID: 1467
09-24 13:47:52.195: E/AndroidRuntime(1467): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.groupchat/com.groupchat.LogIn}: java.lang.NullPointerException
09-24 13:47:52.195: E/AndroidRuntime(1467):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
09-24 13:47:52.195: E/AndroidRuntime(1467):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
09-24 13:47:52.195: E/AndroidRuntime(1467):     at android.app.ActivityThread.access$800(ActivityThread.java:135)
09-24 13:47:52.195: E/AndroidRuntime(1467):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
09-24 13:47:52.195: E/AndroidRuntime(1467):     at android.os.Handler.dispatchMessage(Handler.java:102)
09-24 13:47:52.195: E/AndroidRuntime(1467):     at android.os.Looper.loop(Looper.java:136)
09-24 13:47:52.195: E/AndroidRuntime(1467):     at android.app.ActivityThread.main(ActivityThread.java:5001)
09-24 13:47:52.195: E/AndroidRuntime(1467):     at java.lang.reflect.Method.invokeNative(Native Method)
09-24 13:47:52.195: E/AndroidRuntime(1467):     at java.lang.reflect.Method.invoke(Method.java:515)
09-24 13:47:52.195: E/AndroidRuntime(1467):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
09-24 13:47:52.195: E/AndroidRuntime(1467):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
09-24 13:47:52.195: E/AndroidRuntime(1467):     at dalvik.system.NativeStart.main(Native Method)
09-24 13:47:52.195: E/AndroidRuntime(1467): Caused by: java.lang.NullPointerException
09-24 13:47:52.195: E/AndroidRuntime(1467):     at com.parse.Parse.getParseDir(Parse.java:313)
09-24 13:47:52.195: E/AndroidRuntime(1467):     at com.parse.ParseCorePlugins.getCurrentUserController(ParseCorePlugins.java:124)
09-24 13:47:52.195: E/AndroidRuntime(1467):     at com.parse.ParseUser.getCurrentUserController(ParseUser.java:56)
09-24 13:47:52.195: E/AndroidRuntime(1467):     at com.parse.ParseUser.getCurrentUser(ParseUser.java:892)
09-24 13:47:52.195: E/AndroidRuntime(1467):     at com.parse.ParseUser.getCurrentUser(ParseUser.java:879)
09-24 13:47:52.195: E/AndroidRuntime(1467):     at com.groupchat.LogIn.onCreate(LogIn.java:35)
09-24 13:47:52.195: E/AndroidRuntime(1467):     at android.app.Activity.performCreate(Activity.java:5231)
09-24 13:47:52.195: E/AndroidRuntime(1467):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
09-24 13:47:52.195: E/AndroidRuntime(1467):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
09-24 13:47:52.195: E/AndroidRuntime(1467):     ... 11 more

这是我的Login.java

package com.groupchat;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import com.parse.LogInCallback;
import com.parse.ParseException;
import com.parse.ParseUser;
import com.parse.SignUpCallback;

import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class LogIn extends Activity {

private Button signUpButton;
private Button loginButton;
private EditText usernameField;
private EditText passwordField;
private String username;
private String password;
private Intent intent;
private Intent serviceIntent;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    intent = new Intent(getApplicationContext(), ListUsersActivity.class);
    serviceIntent = new Intent(getApplicationContext(), MessageService.class);

    ParseUser currentUser = ParseUser.getCurrentUser();
    if (currentUser != null) {
        startActivity(intent);
        startService(serviceIntent);
    }

    setContentView(R.layout.activity_log_in);

    loginButton = (Button) findViewById(R.id.loginButton);
    signUpButton = (Button) findViewById(R.id.signupButton);
    usernameField = (EditText) findViewById(R.id.loginUsername);
    passwordField = (EditText) findViewById(R.id.loginPassword);

    loginButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            username = usernameField.getText().toString();
            password = passwordField.getText().toString();

            ParseUser.logInInBackground(username, password, new LogInCallback() {
                public void done(ParseUser user, com.parse.ParseException e) {
                    if (user != null) {
                        startActivity(intent);
                        startService(serviceIntent);
                    } else {
                        Toast.makeText(getApplicationContext(),
                            "Wrong username/password combo",
                                Toast.LENGTH_LONG).show();
                    }
                }
            });
        }
    });

    signUpButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            username = usernameField.getText().toString();
            password = passwordField.getText().toString();

            ParseUser user = new ParseUser();
            user.setUsername(username);
            user.setPassword(password);

            user.signUpInBackground(new SignUpCallback() {
                public void done(com.parse.ParseException e) {
                    if (e == null) {
                        startActivity(intent);
                        startService(serviceIntent);
                    } else {
                        Toast.makeText(getApplicationContext(),
                            "There was an error signing up."
                                , Toast.LENGTH_LONG).show();
                    }
                }
            });
        }
    });
}

@Override
public void onDestroy() {
    stopService(new Intent(this, MessageService.class));
    super.onDestroy();
}
}

控制台上没有错误。

谢谢!

1 个答案:

答案 0 :(得分:0)

你的例外被抛出:

ParseUser currentUser = ParseUser.getCurrentUser();

getCurrentUser()类的方法ParseUser正在尝试完成所有这些(从下到上阅读):

at com.parse.Parse.getParseDir(Parse.java:313) <---- THIS THROWS NPE
at com.parse.ParseCorePlugins.getCurrentUserController(ParseCorePlugins.java:124)
at com.parse.ParseUser.getCurrentUserController(ParseUser.java:56)
at com.parse.ParseUser.getCurrentUser(ParseUser.java:892)
at com.parse.ParseUser.getCurrentUser(ParseUser.java:879)

这似乎表明您的ParseUser类在之前需要其他信息它可以解析用户,或者它需要一个它没有的权限。

在任何情况下,如果无法访问ParseUser类'源代码,就无法分辨。