Thursday, May 2, 2013

[android help] android login while connecting web server DB


im asking about my code.. im doing the android login details that connect to web server DB.. but while i run the apps.. when the button login i click i doesnt view the next page... but its detect the the application failure... need and advise for this code.. maybe expert can help me... this the code for login to send the data from page login...



package com.androidnew;

import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends Activity
{
JSONParser jsonparser = new JSONParser();

EditText id;
EditText password;

static final String TAG_SUCCESS = "success";

@Override public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addListenerOnButton();

}

public void addListenerOnButton()
{
id = (EditText) findViewById(R.id.user_id);
password = (EditText) findViewById(R.id.user_password);

Button btnlogin = (Button) findViewById(R.id.login);

btnlogin.setOnClickListener(new View.OnClickListener() {

public void onClick(View view)
{
String text1 = id.getText().toString();
String text2 = password.getText().toString();

Intent intent = new Intent(getApplicationContext(), Subject_Register.class);
intent.putExtra("ID", text1);
intent.putExtra("PASS", text2);
startActivity(intent);
finish();

}
});

}


}


and this for retrieve the data from page login to DB and view in my apps....

package com.androidnew;


import java.util.ArrayList;
import java.util.List;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.app.ProgressDialog;

import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;


public class Subject_Register extends Activity{

Button next;
EditText user_id;
EditText user_password;

TextView matrix_no;
TextView name;
TextView faculty;
TextView session;
TextView section_group;
TextView year_semester;
TextView course_code;
TextView course_name;

private ProgressDialog pDialog;

JSONParser jParser = new JSONParser();

private static final String url_user = "http://10.131.75.125/android_baru/login.php";


private static final String TAG_SUCCESS = "success";
private static final String TAG_user_details = "user_details";
private static final String TAG_user = "user";
private static final String TAG_ID = "username";
private static final String TAG_PASS = "password";

private static final String TAG_matrix_no = "matrix_no";
private static final String TAG_name = "name";
private static final String TAG_faculty = "faculty";
private static final String TAG_session = "session";
private static final String TAG_section_group = "section_group";
private static final String TAG_year_semester = "year_semester";
private static final String TAG_course_name = "course_name";
private static final String TAG_course_code = "course_code";


String ID;
String PASS;
TextView txtView1;
TextView txtView2;
TextView txtView3;
TextView txtView4;
TextView txtView5;
TextView txtView6;
TextView txtView7;
TextView txtView8;

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.subject_register);
addListenerOnNext();

Intent i = getIntent();

ID = i.getStringExtra(TAG_ID);
PASS = i.getStringExtra(TAG_PASS);

new user_details().execute(); //class

}





class user_details extends AsyncTask {
String id,pin;
@Override
protected void onPreExecute() {

super.onPreExecute();

pDialog = new ProgressDialog(Subject_Register.this);
pDialog.setMessage("Retrive data..Please wait...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();


}

protected String doInBackground (String...params) {

runOnUiThread(new Runnable() {
public void run() {

int success = 0;
try {

List params = new ArrayList();
params.add(new BasicNameValuePair("ID",ID));
params.add(new BasicNameValuePair("PASS",PASS));

JSONObject json = jParser.makeHttpRequest(url_user, "GET", params);

Log.d("User Details", json.toString());

success = json.getInt(TAG_SUCCESS);

if(success == 1) {

JSONArray user_details = json.getJSONArray(TAG_user);

JSONObject user = user_details.getJSONObject(0);

//user with this pid found
matrix_no = (TextView) findViewById(R.id.matrix_no);
name = (TextView) findViewById(R.id.name);
faculty = (TextView) findViewById(R.id.faculty);
session = (TextView) findViewById(R.id.session);
section_group = (TextView) findViewById(R.id.section_group);
course_code = (TextView) findViewById(R.id.course_code);
course_name = (TextView) findViewById(R.id.course_name);
year_semester = (TextView) findViewById(R.id.year_semester);

//display user data in edittext

matrix_no.setText(user.getString(TAG_matrix_no));
name.setText(user.getString(TAG_name));
faculty.setText(user.getString(TAG_faculty));
session.setText(user.getString(TAG_session));
section_group.setText(user.getString(TAG_section_group));
course_code.setText(user.getString(TAG_course_code));
course_name.setText(user.getString(TAG_course_name));
year_semester.setText(user.getString(TAG_year_semester));

}else{

}
}
catch (JSONException e) {
e.printStackTrace();

}
}
});

return null;
}

protected void onPostExecute(String file_url) {
pDialog.dismiss();
}
}

private void addListenerOnNext() {
// TODO Auto-generated method stub
final Context context = this;

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

next.setOnClickListener(new OnClickListener(){
public void onClick(View arg0){
Intent intent = new Intent (context, Subject.class);
startActivity(intent);
finish();
}
});
}}

thanks for concern... :)


.

stackoverflow.comm

No comments:

Post a Comment

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...