안드로이드 간단한 회원가입/ 로그인 소스를 만들었는데 작동되지않는 이유를 모르겠습니다.
회원가입 입니다------------------------------------------------------------------------
public class JoinActivity extends Activity {
ImageButton join_finish_imagebutton,join_cancel_imagebutton;
String myResult;
String edit1, edit2, edit3, edit4;
AsyncTaskJoin noticeUpload;
Boolean is;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.join);
is=false;
join_cancel_imagebutton = (ImageButton)findViewById(R.id.join_cancel_imagebutton);
join_cancel_imagebutton.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
Intent intent = new Intent(getBaseContext(), MainActivity.class);
startActivity(intent);
}
});
join_finish_imagebutton = (ImageButton) findViewById(R.id.join_finish_imagebutton);
join_finish_imagebutton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// manager aa;
// aa.setName()
if (getFormValue()) {
noticeUpload = new AsyncTaskJoin();
noticeUpload.execute();
}
}
});
}
private boolean getFormValue() {
if (TextUtils
.isEmpty(((EditText) (findViewById(R.id.join_name_edittext)))
.getText().toString())) {
Toast.makeText(JoinActivity.this, "이름을 입력하세요.", Toast.LENGTH_SHORT)
.show();
return false;
}
if (TextUtils
.isEmpty(((EditText) (findViewById(R.id.join_id_edittext)))
.getText().toString())) {
Toast.makeText(JoinActivity.this, "닉네임을 입력하세요.", Toast.LENGTH_SHORT)
.show();
return false;
}
if (TextUtils
.isEmpty(((EditText) (findViewById(R.id.join_pw_edittext)))
.getText().toString())) {
Toast.makeText(JoinActivity.this, "비밀번호를 입력하세요.",
Toast.LENGTH_SHORT).show();
return false;
}
if (TextUtils
.isEmpty(((EditText) (findViewById(R.id.join_phone_edittext)))
.getText().toString())) {
Toast.makeText(JoinActivity.this, "전화번호를 입력하세요.",
Toast.LENGTH_SHORT).show();
return false;
}
edit1 = ((EditText) (findViewById(R.id.join_name_edittext))).getText()
.toString();
edit2 = ((EditText) (findViewById(R.id.join_id_edittext))).getText()
.toString();
edit3 = ((EditText) (findViewById(R.id.join_pw_edittext))).getText()
.toString();
edit4 = ((EditText) (findViewById(R.id.join_phone_edittext))).getText()
.toString();
return true;
}
private class AsyncTaskJoin extends AsyncTask
@Override
protected Boolean doInBackground(Object... params) {
// TODO Auto-generated method stub
boolean result = false;
Vector vars = new Vector();
try {
// HTTP POST
vars.add(new BasicNameValuePair("name", edit1));
vars.add(new BasicNameValuePair("id", edit2));
vars.add(new BasicNameValuePair("passwd", edit3));
vars.add(new BasicNameValuePair("phone", edit4));
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(vars, HTTP.UTF_8);
String url = "http://127.0.0.1/join.php?useUnicode=true&characterEncoding=utf8";
HttpPost request = new HttpPost(url);
request.setEntity(entity);
try {
ResponseHandler responseHandler = new BasicResponseHandler();
HttpClient client = new DefaultHttpClient();
Log.i("kkkkk", url);
String responseBody = client.execute(request,responseHandler);
responseBody.trim();
//String[] res = responseBody.split("");
Log.i("kkkkk", responseBody);
if (responseBody.equals("ok")) {
result = true;
}
} catch (ClientProtocolException e) {
Log.i("kkkkk", "error");
result = false;
} catch (IOException e) {
Log.i("Failed to IOException: ", "" + e);
result = false;
}
} catch (Exception e) {
Log.i("kkkkk", "" + e);
result = false;
}
return result;
}
@Override
protected void onPostExecute(Boolean result) {
if (result) {
Toast.makeText(JoinActivity.this, "회원가입에 성공하였습니다.",
Toast.LENGTH_LONG).show();
is = true;
finish();
} else {
Toast.makeText(JoinActivity.this, "회원가입에 실패하였습니다.",
Toast.LENGTH_LONG).show();
is = false;
finish();
}
JoinActivity.this
.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
}
@Override
protected void onPreExecute() {
}
@Override
protected void onProgressUpdate(String... values) {
}
}
}
로그인 입니다-------------------------------------------------------------------------
public class MainActivity extends Activity {
ImageButton main_login_imagebutton, main_join_imagebutton;
private EditText idEV;
private EditText pwEV;
static final int DATE_DIALOG_ID = 0;
String id,pw;
AsyncTaskJoin noticeUpload;
boolean is;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
idEV =(EditText) findViewById(R.id.main_id_edittext);
pwEV = (EditText) findViewById(R.id.main_pw_edittext);
is=false;
Intent i=getIntent();
if(i.getStringExtra("id")!=null)
idEV.setText(i.getStringExtra("id"));
if(i.getStringExtra("pass")!=null)
pwEV.setText(i.getStringExtra("pass"));
main_login_imagebutton = (ImageButton) findViewById(R.id.main_login_imagebutton);
main_login_imagebutton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if(getFormValue()){
noticeUpload = new AsyncTaskJoin();
noticeUpload.execute();
}
}});
main_join_imagebutton = (ImageButton) findViewById(R.id.main_join_imagebutton);
main_join_imagebutton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent intent=new Intent(MainActivity.this,JoinActivity.class);
startActivity(intent);
}});
}
private boolean getFormValue() {
if (TextUtils.isEmpty(idEV.getText())) {
Toast.makeText(MainActivity.this, "ID입력해주세요.", Toast.LENGTH_SHORT)
.show();
return false;
}
if (TextUtils.isEmpty(pwEV.getText())) {
Toast.makeText(MainActivity.this, "PASSWORD입력해주세요.", Toast.LENGTH_SHORT)
.show();
return false;
}
id=idEV.getText().toString();
pw=pwEV.getText().toString();
return true;
}
@SuppressLint("NewApi")
private class AsyncTaskJoin extends AsyncTask
protected Boolean doInBackground(Object... params) {
// TODO Auto-generated method stub
boolean result = false;
Vector vars = new Vector();
try {
// HTTP POST
vars.add( new BasicNameValuePair("id", id));
vars.add( new BasicNameValuePair("passwd", pw));
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(vars,HTTP.UTF_8);
String url = "http://127.0.0.1/login.php";
HttpPost request = new HttpPost(url);
request.setEntity(entity);
try {
ResponseHandler responseHandler = new BasicResponseHandler();
HttpClient client = new DefaultHttpClient();
String responseBody = client.execute(request,responseHandler);
responseBody.trim();
Log.i("kkkkk", responseBody);
if (responseBody.equals("ok")) {
result = true;
is=true;
}
else if(responseBody.equals("no")){
result=false;
is=true;
}
} catch (ClientProtocolException e) {
Log.e("Failed to ClientProtocolException ", ""+e);
result = false;
} catch (IOException e) {
Log.e("Failed to IOException: ", ""+e);
result = false;
}
} catch (Exception e) {
result = false;
Log.e("other error :", ""+e);
}
return result;
}
protected void onPostExecute(Boolean result) {
if (result && is) {
Toast.makeText(MainActivity.this, "로그인 완료.", Toast.LENGTH_LONG).show();
Intent intent=new Intent(MainActivity.this,HomeActivity.class);
intent.putExtra("id", id);
startActivity(intent);
}else if(result || is) {
Toast.makeText(MainActivity.this, "로그인 실패.", Toast.LENGTH_LONG).show();
}else {
Toast.makeText(MainActivity.this,"서버접속 불량", Toast.LENGTH_LONG).show();
}
MainActivity.this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
}
protected void onPreExecute() {
}
protected void onProgressUpdate(String... values) {
}
}
}
--------------------------------------------------------------------------------------
1년전에 이렇게해서 회원가입 로그인 되었었는데..
1. 회원가입 후 DB에는 들어가는데 실패했다고 뜹니다.
2. 로그인은 되지않구요.
문제점이 뭔지 알고싶습니다 ㅠㅠ..... 9시간을 이것만 만들었어요ㅠㅠ
sdk 버전 달라서 그런거아닌가요?
sdk 버전 달라서 그런거아닌가요? 가끔 sdk 버전 달라서 mysql이랑 연동안될때가 있던데
sdk 버전을 6까지 내려보시고 한번 해보세요
댓글 달기