简体   繁体   English

登录代码在我的代码中不起作用我已经使用了volly。当我运行应用程序时,它显示错误消息“ Error”

[英]login code is not working in my code i have used volly .when i run application it shows the error message “Error”

When i run application it shows the error message "Error" and this is my mainclass.i have taken 3 fileds username,pass,imeinum. 当我运行应用程序时,它显示错误消息“ Error”,这是我的mainclass.i已经使用了3个用户名,密码,imeinum。 url is also includes.but it not working.what will be the solution.plz help me. url也包括在内。但它不起作用。解决方案将是什么。请帮助我。

public class MainActivity extends AppCompatActivity implements View.OnClickListener{

public static final String LOGIN_URL = "http://www.infinitethought.in/mobapp.php";

public static final String KEY_USERNAME="username1";
public static final String KEY_PASSWORD="password";
public static final String KEY_IMEINUM="imeinum";


private EditText editTextUsername;
private EditText editTextPassword;
private EditText editText;
private Button buttonLogin;

private String username1;
private String password;
private String imeinum;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    editTextUsername = (EditText) findViewById(R.id.editTextUsername);
    editTextPassword = (EditText) findViewById(R.id.editTextPassword);
    editText = (EditText) findViewById(R.id.editText);

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

    buttonLogin.setOnClickListener(this);
}


private void userLogin() {
    username1 = editTextUsername.getText().toString().trim();
    password = editTextPassword.getText().toString().trim();
    imeinum = editText.getText().toString().trim();

    StringRequest stringRequest = new StringRequest(Request.Method.POST, LOGIN_URL,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    if(response.trim().equals("success")){
                        openProfile();
                    }else{
                        Toast.makeText(MainActivity.this,"Error",Toast.LENGTH_LONG).show();
                    }
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    Toast.makeText(MainActivity.this,error.toString(),Toast.LENGTH_LONG ).show();
                }
            }){
        @Override
        protected Map<String, String> getParams() throws AuthFailureError {
            Map<String,String> map = new HashMap<String,String>();
            map.put(KEY_USERNAME,username1);
            map.put(KEY_PASSWORD,password);
            map.put(KEY_IMEINUM,imeinum);
            return map;
        }
    };

    RequestQueue requestQueue = Volley.newRequestQueue(this);
    requestQueue.add(stringRequest);
}

private void openProfile(){
    Intent intent = new Intent(this, userprofile.class);
    intent.putExtra(KEY_USERNAME, username1);
    startActivity(intent);
}

@Override
public void onClick(View v) {
    userLogin();
}
}

Refer My Code -- 请参阅我的代码-

public void login(View view) {
    switch (view.getId()) {

        case R.id.signin:
            String employCod = editTextUserCode.getText().toString();
            String branchCod = editTextBranchCode.getText().toString();
            String password = editTextPassword.getText().toString();
            onlogin(employCod, branchCod, password);

            break;

    }
}

private void onlogin(final String employCod, final String branchCod, final String password) {

    class LoginAsync extends AsyncTask<String, String, String> {
        /**
         * Before starting background thread Show Progress Dialog
         */
        boolean failure = false;

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            pDialog = new ProgressDialog(LoginActivity.this);
            pDialog.setMessage("Attempting login...");
            pDialog.setIndeterminate(false);
            pDialog.setCancelable(true);
            pDialog.show();
        }

        @Override
        protected String doInBackground(String... args) {

            // TODO Auto-generated method stub
            // Check for success tag


            String companyCode = "VO";
            String loginBranch = "VO02";

            try {
                // Building Parameters
                List<NameValuePair> params = new ArrayList<>();
                params.add(new BasicNameValuePair("companyCode", companyCode));
                params.add(new BasicNameValuePair("employeeCode", employCod));
                params.add(new BasicNameValuePair("empBranch", branchCod));
                params.add(new BasicNameValuePair("passWord", password));
                params.add(new BasicNameValuePair("loginBranch", loginBranch));
                Log.d("request!", "starting");
                // getting product details by making HTTP request
                JSONObject json = jsonParser.makeHttpRequest(
                        LOGIN_URL, "POST", params);


                // check your log for json response
                Log.d("Login attempt", json.toString());

                // json success tag
                errflag = json.getString(TAG_SUCCESS);
                if (errflag.equalsIgnoreCase("S")) {
                    Log.d("Login Successful!", json.toString());
                    Intent i = new Intent(LoginActivity.this, MainActivity.class);
                    finish();
                    String employName = json.getString("empName");
                    i.putExtra("empName", employName);
                    startActivity(i);

                    return json.getString(TAG_MESSAGE);
                } else {
                    Log.d("Login Failure!", json.getString(TAG_MESSAGE));
                    return json.getString(TAG_MESSAGE);

                }

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

            return null;

        }


        /**
         * After completing background task Dismiss the progress dialog
         * **/

        protected void onPostExecute(String file_url) {
            // dismiss the dialog once product deleted
            pDialog.dismiss();
            if (file_url != null) {
                Toast.makeText(LoginActivity.this, file_url, Toast.LENGTH_LONG).show();


            }

        }

    }
    LoginAsync la = new LoginAsync();
    la.execute(employCod, branchCod, password);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当我运行我的Android UIAutomator代码时,它显示错误 - When i run my android UIAutomator code, it shows error 在Android上的Mysql Server上上传图像我的代码得到错误我正在使用Volly? - upload Image on Mysql Server In Android My code Get an Error i am use Volly? 我的代码有错误 - I have a error with my code 当我运行我的代码时,它会给出错误代码 400,但是当我进行热刷新时,它会在控制台中显示数据,同时从 flutter 中的 api 获取数据 - when i run my code it gives error code 400 but when i do hot refresh it shows data in console while getting data from api in flutter 我的代码显示了针对回收器视图的错误放大类片段。 这是我的代码,Adapter类以及我使用的所有xml文件 - My code shows error inflating class fragment, for recycler view. This is my code, Adapter class, and all the xml files I used 当我运行我的应用程序时出现未知错误 - unknown error when i run my application 当stacktrace仅在eclipse中显示本机方法时,如何查找导致错误的代码行 - How do I find the line of my code causing an error when the stacktrace only shows native methods in eclipse 当我尝试在手机上运行代码时,AndroidManifest.xml文件出现错误。 - I get error in the AndroidManifest.xml file when i try to run my code on my phone. 将Flutter代码编译为Android模拟器时收到错误消息 - I got an error message when I compile my Flutter code to an Android emulator 当我使用react-native-touch-id时,触摸ID不起作用是当我单击toggleTouchId()时重新编码错误isSupported未定义的代码 - Touch Id Not working when I used react-native-touch-id below is my code when i click toggleTouchId() it retun me error isSupported is not defined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM