0

GOOD DAY Everyone!

i am new in android programming and i am facing an error in logcat and there is no error in console. i tried searching it over and over but it seems i am the only one facing these errors.

BTW this codes are not mine, i found it on a tutorial to be particular it is the "Sinch Group Chat" if you will search on google this one is kind of popular. aside from it is from google i adapt it on Eclipse, i believe they made this tutorial for 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

and this is my 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();
}
}

there are no errors on Console.

THANK YOU!

  • "there are no errors on Console." well... you have one here: Caused by: java.lang.NullPointerException 09-24 13:47:52.195: E/AndroidRuntime(1467): at com.parse.Parse.getParseDir(Parse.java:313) – Mariano Zorrilla Sep 24 '15 at 18:02
  • 1
    possible duplicate of [What is a Null Pointer Exception, and how do I fix it?](http://stackoverflow.com/questions/218384/what-is-a-null-pointer-exception-and-how-do-i-fix-it) – Tom Sep 24 '15 at 18:04

1 Answers1

0

Your exception is thrown here:

ParseUser currentUser = ParseUser.getCurrentUser();

The method getCurrentUser() of the ParseUser class is attempting to do all this (read from bottom to top):

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)

Which seems to indicate that either your ParseUser class needs additional information before it can parse the user or that it requires a permission that it doesn't have.

In any case, without access to ParseUser class' source code, it's impossible to tell.

Tom
  • 16,842
  • 17
  • 45
  • 54
Martin Marconcini
  • 26,875
  • 19
  • 106
  • 144
  • *"In any case, without access to `ParseUser` class' source code, it's impossible to tell."* ... well, then look at the source: https://github.com/ParsePlatform/Parse-SDK-Android/blob/master/Parse/src/main/java/com/parse/ParseUser.java :). (Since the line numbers differ a bit, OP might not use the newest version) – Tom Sep 24 '15 at 18:16
  • @Martin Marconcini ill try to review on my class and read the tutorial from top to bottom again, maybe you're right and i am missing something. – kim caboteja Sep 24 '15 at 18:19