尝试使用解析登录时出错

时间:2017-07-13 20:08:06

标签: android

我是android的初学者,我一直在关注udemy的课程。我试图使用解析,但每次我尝试运行代码时都会给我一个错误。下面是解析类的代码:

import android.app.Application;

import com.parse.Parse;
import com.parse.ParseACL;


public class StarterApplication extends Application {

  @Override
  public void onCreate() {
    super.onCreate();

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

// Add your initialization code here
Parse.initialize(new Parse.Configuration.Builder(getApplicationContext())
        .applicationId("4e188aaea9fd210545126d11e6dc4b2463265310")
        .clientKey("00f12c54779ba75af4d6deb7c599c5de77ddd47a")
        .server("http://ec2-13-59-193-44.us-east-2.compute.amazonaws.com:80/parse/")
        .build()
);


//ParseUser.enableAutomaticUser();

ParseACL defaultACL = new ParseACL();
defaultACL.setPublicReadAccess(true);
defaultACL.setPublicWriteAccess(true);
ParseACL.setDefaultACL(defaultACL, true);

  }
}

这是主类:

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.parse.FindCallback;
import com.parse.GetCallback;
import com.parse.LogInCallback;
import com.parse.Parse;
import com.parse.ParseAnalytics;
import com.parse.ParseException;
import com.parse.ParseObject;
import com.parse.ParseQuery;
import com.parse.ParseUser;
import com.parse.SaveCallback;
import com.parse.SignUpCallback;

import java.util.List;


public class MainActivity extends AppCompatActivity implements View.OnClickListener {

Boolean signUpModeActive = true;

TextView changeSignupModeTextView;

@Override
public void onClick(View view) {

    if (view.getId() == R.id.changeSignupModeTextView) {

        Button signupButton = (Button) findViewById(R.id.signupButton);

        if (signUpModeActive) {

            signUpModeActive = false;
            signupButton.setText("Login");
            changeSignupModeTextView.setText("Or, Signup");

        } else {

            signUpModeActive = true;
            signupButton.setText("Signup");
            changeSignupModeTextView.setText("Or, Login");

        }

    }

}

public void signUp(View view) {

    EditText usernameEditText = (EditText) findViewById(R.id.usernameEditText);

    EditText passwordEditText = (EditText) findViewById(R.id.passwordEditText);

    if (usernameEditText.getText().toString().matches("") || passwordEditText.getText().toString().matches("")) {

        Toast.makeText(this, "A username and password are required.", Toast.LENGTH_SHORT).show();

    } else {

        if (signUpModeActive) {

            ParseUser user = new ParseUser();

            user.setUsername(usernameEditText.getText().toString());
            user.setPassword(passwordEditText.getText().toString());

            user.signUpInBackground(new SignUpCallback() {
                @Override
                public void done(ParseException e) {
                    if (e == null) {

                        Log.i("Signup", "Successful");

                    } else {

                        Toast.makeText(MainActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();

                    }
                }
            });

        } else {

            ParseUser.logInInBackground(usernameEditText.getText().toString(), passwordEditText.getText().toString(), new LogInCallback() {
                @Override
                public void done(ParseUser user, ParseException e) {

                    if (user != null) {

                        Log.i("Signup", "Login successful");

                    } else {

                        Toast.makeText(MainActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();

                    }


                }
            });


        }
    }


}

  @Override
  protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

  changeSignupModeTextView = (TextView)                     findViewById(R.id.changeSignupModeTextView);

  changeSignupModeTextView.setOnClickListener(this);


ParseAnalytics.trackAppOpenedInBackground(getIntent());
  }

}

PS:继承错误:

07-13 23:55:44.169 2603-2603/com.parse.starter E/AndroidRuntime: FATAL EXCEPTION: main
                                                             Process: com.parse.starter, PID: 2603
                                                             java.lang.RuntimeException: Unable to instantiate application com.parse.starter.StarterApplication: java.lang.ClassNotFoundException: Didn't find class "com.parse.starter.StarterApplication" on path: DexPathList[[zip file "/data/app/com.parse.starter-1/base.apk"],nativeLibraryDirectories=[/data/app/com.parse.starter-1/lib/x86, /system/lib, /vendor/lib]]
                                                                 at android.app.LoadedApk.makeApplication(LoadedApk.java:802)
                                                                 at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5377)
                                                                 at android.app.ActivityThread.-wrap2(ActivityThread.java)
                                                                 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1545)
                                                                 at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                 at android.os.Looper.loop(Looper.java:154)
                                                                 at android.app.ActivityThread.main(ActivityThread.java:6119)
                                                                 at java.lang.reflect.Method.invoke(Native Method)
                                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
                                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
                                                              Caused by: java.lang.ClassNotFoundException: Didn't find class "com.parse.starter.StarterApplication" on path: DexPathList[[zip file "/data/app/com.parse.starter-1/base.apk"],nativeLibraryDirectories=[/data/app/com.parse.starter-1/lib/x86, /system/lib, /vendor/lib]]
                                                                 at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
                                                                 at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
                                                                 at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
                                                                 at android.app.Instrumentation.newApplication(Instrumentation.java:992)
                                                                 at android.app.LoadedApk.makeApplication(LoadedApk.java:796)
                                                                 at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5377) 
                                                                 at android.app.ActivityThread.-wrap2(ActivityThread.java) 
                                                                 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1545) 
                                                                 at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                 at android.os.Looper.loop(Looper.java:154) 
                                                                 at android.app.ActivityThread.main(ActivityThread.java:6119) 
                                                                 at java.lang.reflect.Method.invoke(Native Method) 
                                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) 
                                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)

1 个答案:

答案 0 :(得分:0)

以下是您正在关注link

的解析启动项目
  1. 创建扩展android.app.Application StarterApplication 类,如图所示 以下

    public class StarterApplication extends Application {
    }
    
  2. AndroidManifest.xml 文件中设置您的应用程序名称如下:

    <application
        android:name=".StarterApplication">
    
  3. 那你现在应该好好去。