我在eclipse上使用Parse.com上的服务在后端创建了一个Android应用程序,
在'登录密码'屏幕,它工作finr,闪烁没有用户存在的吐司,请注册。
在注册活动中,表单会被提交,但是toast会显示“错误”字样。部分,数据不会保存到解析后端。 请帮忙。 这是代码
ParseStarterProjectActivity.java
package com.parse.starter;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.parse.LogInCallback;
import com.parse.ParseAnalytics;
import com.parse.ParseException;
import com.parse.ParseUser;
public class ParseStarterProjectActivity extends Activity {
EditText Username,Password;
Button Login,Signup;
String usernametxt,passwordtxt;
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Username = (EditText) findViewById(R.id.editText1);
Password = (EditText) findViewById(R.id.editText2);
Login = (Button) findViewById(R.id.button1);
Signup = (Button) findViewById(R.id.button2);
Login.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
usernametxt = Username.getText().toString();
passwordtxt = Password.getText().toString();
ParseUser.logInInBackground(usernametxt, passwordtxt,
new LogInCallback() {
@Override
public void done(ParseUser user, ParseException e) {
// TODO Auto-generated method stub
if (user != null) {
// If user exist and authenticated, send user to Welcome.class
Intent intent = new Intent(ParseStarterProjectActivity.this,
WelcomeActivity.class);
startActivity(intent);
Toast.makeText(getApplicationContext(),"Successfully Logged in",
Toast.LENGTH_LONG).show();
finish();
}
else
{
Toast.makeText(getApplicationContext(),"No such user exist, please signup",
Toast.LENGTH_LONG).show();
}
}
});
}
});
Signup.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent i = new Intent(ParseStarterProjectActivity.this,SignupActivity.class);
startActivity(i);
}
});
}
}
SignupActivity.java
package com.parse.starter;
import com.parse.ParseException;
import com.parse.ParseUser;
import com.parse.SignUpCallback;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class SignupActivity extends Activity {
EditText name,password,confirmpass,email;
Button signup;
String usertxt,passwordtxt,emailtxt,confirmpasstxt;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.signin);
name = (EditText) findViewById(R.id.editText1);
password = (EditText) findViewById(R.id.editText2);
email = (EditText) findViewById(R.id.editText4);
signup = (Button) findViewById(R.id.button1);
signup.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
usertxt = name.getText().toString();
passwordtxt = password.getText().toString();
emailtxt = email.getText().toString();
if (usertxt.equals("") && passwordtxt.equals("") && emailtxt.equals(""))
{
Toast.makeText(getApplicationContext(),"Please complete the sign up form",
Toast.LENGTH_LONG).show();
}
else
{
ParseUser user = new ParseUser();
user.setUsername("username");
user.setPassword("password");
user.setEmail("email");
user.signUpInBackground(new SignUpCallback() {
@Override
public void done(ParseException e) {
// TODO Auto-generated method stub
if (e == null) {
Toast.makeText(getApplicationContext(),"Successfully Signed up, please log in.",
Toast.LENGTH_LONG).show();
finish();
} else {
Toast.makeText(getApplicationContext(),"Sign up Error",
Toast.LENGTH_LONG).show();
}
}
});
}
}
});
}
}
可能出了什么问题?
提前致谢
答案 0 :(得分:0)
实际上你的代码是有效的,但你唯一错误的做法就是你在解析用户中设置了你输入的数据而不是用户给出的输入""标记只是使用像这样的变量来引用它
*.setUsername(name)
答案 1 :(得分:0)
使用
在您的类文件中写入密钥的值parse.initialize(this,"app_id","client_id");