连接web服务器数据库时android登录

连接web服务器数据库时android登录,android,sql,android-intent,Android,Sql,Android Intent,我在问我的密码。。我正在做连接到web服务器数据库的android登录详细信息。。但是当我运行应用程序时。。当我点击“登录”按钮时,我不会查看下一页。。。但它可以检测应用程序故障。。。需要并建议此代码。。也许专家能帮我。。。这是用于登录的代码,用于从页面登录发送数据 package com.androidnew; import android.app.Activity; import android.app.Dialog; import android.content.Intent; impo

我在问我的密码。。我正在做连接到web服务器数据库的android登录详细信息。。但是当我运行应用程序时。。当我点击“登录”按钮时,我不会查看下一页。。。但它可以检测应用程序故障。。。需要并建议此代码。。也许专家能帮我。。。这是用于登录的代码,用于从页面登录发送数据

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, String, String> {
        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<NameValuePair> params = new ArrayList<NameValuePair>();
                        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... :)
package com.androidnew;
导入android.app.Activity;
导入android.app.Dialog;
导入android.content.Intent;
导入android.os.Bundle;
导入android.view.view;
导入android.widget.Button;
导入android.widget.EditText;
导入android.widget.Toast;
公共类MainActivity扩展了活动
{
JSONParser JSONParser=新的JSONParser();
编辑文本id;
编辑文本密码;
静态最终字符串标记_SUCCESS=“SUCCESS”;
@在创建时覆盖公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addListenerOnButton();
}
public void addListenerOnButton()
{
id=(EditText)findViewById(R.id.user\u id);
密码=(EditText)findViewById(R.id.user\u密码);
按钮btnlogin=(按钮)findViewById(R.id.login);
btnlogin.setOnClickListener(新视图.OnClickListener(){
公共void onClick(视图)
{
字符串text1=id.getText().toString();
String text2=password.getText().toString();
Intent Intent=newintent(getApplicationContext(),Subject\u Register.class);
意图。putExtra(“ID”,text1);
意向。额外(“通过”,文本2);
星触觉(意向);
完成();
}
});
}
}
这用于从页面登录到数据库检索数据,并在我的应用程序中查看。。。。
包com.androidnew;
导入java.util.ArrayList;
导入java.util.List;
导入org.apache.http.NameValuePair;
导入org.apache.http.message.BasicNameValuePair;
导入org.json.JSONArray;
导入org.json.JSONException;
导入org.json.JSONObject;
导入android.app.Activity;
导入android.app.ProgressDialog;
导入android.content.Context;
导入android.content.Intent;
导入android.os.AsyncTask;
导入android.os.Bundle;
导入android.util.Log;
导入android.view.view;
导入android.view.view.OnClickListener;
导入android.widget.Button;
导入android.widget.EditText;
导入android.widget.TextView;
公开课科目注册扩展活动{
按钮下一步;
编辑文本用户标识;
编辑文本用户密码;
文本视图矩阵_编号;
文本视图名称;
文本视图学院;
文本视图会话;
文本视图分区组;
TextView学年/学期;
TextView课程代码;
TextView课程名称;
私人对话;
JSONParser jParser=新的JSONParser();
私有静态最终字符串url_user=”http://10.131.75.125/android_baru/login.php";
私有静态最终字符串标记_SUCCESS=“SUCCESS”;
私有静态最终字符串标记\u user\u details=“user\u details”;
私有静态最终字符串标记_user=“user”;
私有静态最终字符串标记\u ID=“username”;
私有静态最终字符串标记\u PASS=“password”;
私有静态最终字符串标记\u matrix\u no=“matrix\u no”;
私有静态最终字符串标记_name=“name”;
私有静态最终字符串标记_faculty=“faculty”;
私有静态最终字符串标记\u session=“session”;
私有静态最终字符串标记\u section\u group=“section\u group”;
私有静态最终字符串标记“年\学期=“年\学期”;
私有静态最终字符串TAG\u course\u name=“course\u name”;
私有静态最终字符串TAG\u course\u code=“course\u code”;
字符串ID;
串通;
TextView txtView1;
TextView-txtView2;
TextView-txtView3;
TextView txtView4;
TextView txtView5;
TextView txtView6;
TextView txtView7;
TextView txtView8;
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.subject_寄存器);
addListenerOnNext();
Intent i=getIntent();
ID=i.getStringExtra(标签ID);
通过=i.getStringExtra(标记通过);
新用户_details().execute();//类
}
类用户\u详细信息扩展异步任务{
字符串id,pin;
@凌驾
受保护的void onPreExecute(){
super.onPreExecute();
pDialog=新建进度对话框(主题\寄存器。此);
setMessage(“检索数据..请稍候…”);
pDialog.setUndeterminate(假);
pDialog.setCancelable(真);
pDialog.show();
}
受保护的字符串doInBackground(字符串…参数){
runOnUiThread(新的Runnable(){
公开募捐{
int成功=0;
试一试{
List params=new ArrayList();
参数add(新的BasicNameValuePair(“ID”,ID));
参数添加(新的BasicNameValuePair(“通过”,通过));
JSONObject json=jParser.makeHttpRequest(url_用户,“GET”,参数);
Log.d(“用户详细信息”,json.toString());
success=json.getInt(TAG_success);
如果(成功==1){
JSONArray user_details=json.getJSONArray(TAG_user);
JSONObject user=user_details.getJSONObject(0);
//找到具有此pid的用户
矩阵号=(TextView)findViewById(R.id.matrix号);
name=(TextView)findViewById(R.id.name);
教员=(TextView)findViewById(R.id.faculty);
session=(TextView)findViewById(R.id.session);
section_group=(TextView)findViewById(R.id.section_group);
private static final String TAG_ID = "username";
private static final String TAG_PASS = "password";
private static final String TAG_ID = "ID";
private static final String TAG_PASS = "PASS";
ID = i.getStringExtra("ID");
PASS  = i.getStringExtra("PASS");
Intent intent = new Intent (youractivity.this, Subject.class);
Intent intent = new Intent (context, Subject.class);