Android解析开放帐户错误

时间:2013-02-28 18:44:33

标签: java android

我想通过parse.com开设一个新帐户:

https://www.parse.com/docs/android_guide

然而,当我到达这条线时:

user.setUsername( “A”);

然后它会显示一个弹出窗口:“应用程序必须停止...”并退出

这是logcat:

02-28 18:35:42.849: E/AndroidRuntime(1862): FATAL EXCEPTION: main
02-28 18:35:42.849: E/AndroidRuntime(1862): java.lang.ExceptionInInitializerError
02-28 18:35:42.849: E/AndroidRuntime(1862):     at com.parse.ParseUser.stripAnonymity(ParseUser.java:327)
02-28 18:35:42.849: E/AndroidRuntime(1862):     at com.parse.ParseUser.put(ParseUser.java:319)
02-28 18:35:42.849: E/AndroidRuntime(1862):     at com.parse.ParseUser.setUsername(ParseUser.java:274)
02-28 18:35:42.849: E/AndroidRuntime(1862):     at com.example.salebook.RegisterActivity$1.onClick(RegisterActivity.java:34)
02-28 18:35:42.849: E/AndroidRuntime(1862):     at android.view.View.performClick(View.java:4204)
02-28 18:35:42.849: E/AndroidRuntime(1862):     at android.view.View$PerformClick.run(View.java:17355)
02-28 18:35:42.849: E/AndroidRuntime(1862):     at android.os.Handler.handleCallback(Handler.java:725)
02-28 18:35:42.849: E/AndroidRuntime(1862):     at android.os.Handler.dispatchMessage(Handler.java:92)
02-28 18:35:42.849: E/AndroidRuntime(1862):     at android.os.Looper.loop(Looper.java:137)
02-28 18:35:42.849: E/AndroidRuntime(1862):     at android.app.ActivityThread.main(ActivityThread.java:5041)
02-28 18:35:42.849: E/AndroidRuntime(1862):     at java.lang.reflect.Method.invokeNative(Native Method)
02-28 18:35:42.849: E/AndroidRuntime(1862):     at java.lang.reflect.Method.invoke(Method.java:511)
02-28 18:35:42.849: E/AndroidRuntime(1862):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
02-28 18:35:42.849: E/AndroidRuntime(1862):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
02-28 18:35:42.849: E/AndroidRuntime(1862):     at dalvik.system.NativeStart.main(Native Method)
02-28 18:35:42.849: E/AndroidRuntime(1862): Caused by: java.lang.RuntimeException: You must call Parse.initialize(context, oauthKey, oauthSecret) before using the Parse library.
02-28 18:35:42.849: E/AndroidRuntime(1862):     at com.parse.ParseUser.checkApplicationContext(ParseUser.java:858)
02-28 18:35:42.849: E/AndroidRuntime(1862):     at com.parse.ParseUser.getCurrentUser(ParseUser.java:731)
02-28 18:35:42.849: E/AndroidRuntime(1862):     at com.parse.ParseUser.registerAuthenticationProvider(ParseUser.java:929)
02-28 18:35:42.849: E/AndroidRuntime(1862):     at com.parse.ParseAnonymousUtils.initialize(ParseAnonymousUtils.java:42)
02-28 18:35:42.849: E/AndroidRuntime(1862):     at com.parse.ParseAnonymousUtils.<clinit>(ParseAnonymousUtils.java:36)
02-28 18:35:42.849: E/AndroidRuntime(1862):     ... 15 more

这是我的代码(我必须说服务器中不存在“a”用户名)

regbutton.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v) {
                ParseUser user = new ParseUser();
                user.setUsername("a");
                user.setPassword("a");
                user.setEmail("email@example.com");
                try {
                    user.signUp();
                } catch (ParseException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        });

感谢

1 个答案:

答案 0 :(得分:1)

在使用Parse库之前,必须调用Parse.initialize(context,oauthKey,oauthSecret)。