当我运行应用程序时,它显示错误消息“错误” 这是我的mainclass.i已经采取了3个文件用户名,传递,imeinum。 url也包括。但它不起作用。解决方案是什么.plz帮助我。
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();
}
}
答案 0 :(得分:0)
参考我的代码 -
HashMap latestValues(keys, values);