我的登录问题。单击登录按钮时,其强制停止。
这是我的代码:
//Initializing views
editTextEmail = (EditText) findViewById(R.id.edEmail);
editTextPassword = (EditText) findViewById(R.id.edPassword);
btlogin = (Button) findViewById(R.id.btlogin);
btlogin.setOnClickListener(this);
((TextView) findViewById(R.id.btDaftar))
.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
LoginActivity.this.startActivity(new Intent(LoginActivity.this,SignupActivity.class));
}
});
}
@Override
protected void onResume() {
super.onResume();
//In onresume fetching value from sharedpreference
SharedPreferences sharedPreferences = getSharedPreferences(Config.SHARED_PREF_NAME,Context.MODE_PRIVATE);
//Fetching the boolean value form sharedpreferences
loggedIn = sharedPreferences.getBoolean(Config.LOGGEDIN_SHARED_PREF, false);
//If we will get true
if(loggedIn){
//We will start the Profile Activity
Intent intent = new Intent(LoginActivity.this, MainActivity.class);
startActivity(intent);
}
}
private void login(){
final String email = editTextEmail.getText().toString().trim();
final String password = editTextPassword.getText().toString().trim();
StringRequest stringRequest = new StringRequest(Request.Method.POST, Config.LOGIN_URL,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
if(response.trim().equalsIgnoreCase(Config.LOGIN_SUCCESS)){
SharedPreferences sharedPreferences = LoginActivity.this.getSharedPreferences(Config.SHARED_PREF_NAME, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putBoolean(Config.LOGGEDIN_SHARED_PREF, true);
editor.putString(Config.EMAIL_SHARED_PREF, email);
editor.commit();
Intent intent = new Intent(LoginActivity.this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("Exit me", true);
startActivity(intent);
finish();
}else{
Toast.makeText(LoginActivity.this, "Invalid username or password", Toast.LENGTH_LONG).show();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
}){
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String,String> params = new HashMap<>();
//Adding parameters to request
params.put(Config.KEY_EMAIL, email);
params.put(Config.KEY_PASSWORD, password);
//returning parameter
return params;
}
};
//Adding the string request to the queue
RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(stringRequest);
}
@Override
public void onClick(View v) {
login();
}
日志猫是:
11-13 06:05:07.990:E / AndroidRuntime(13864):致命异常:主要 11-13 06:05:07.990:E / AndroidRuntime(13864):进程:com.example.mdesigntemp,PID:13864 11-13 06:05:07.990:E / AndroidRuntime(13864):java.lang.NoClassDefFoundError:com.example.mdesigntemp.LoginActivity $ 4 11-13 06:05:07.990:E / AndroidRuntime(13864):at com.example.mdesigntemp.LoginActivity.login(LoginActivity.java:84) 11-13 06:05:07.990:E / AndroidRuntime(13864):at com.example.mdesigntemp.LoginActivity.onClick(LoginActivity.java:134) 11-13 06:05:07.990:E / AndroidRuntime(13864):在android.view.View.performClick(View.java:4783) 11-13 06:05:07.990:E / AndroidRuntime(13864):在android.view.View $ PerformClick.run(View.java:19887) 11-13 06:05:07.990:E / AndroidRuntime(13864):在android.os.Handler.handleCallback(Handler.java:739) 11-13 06:05:07.990:E / AndroidRuntime(13864):在android.os.Handler.dispatchMessage(Handler.java:95) 11-13 06:05:07.990:E / AndroidRuntime(13864):在android.os.Looper.loop(Looper.java:135) 11-13 06:05:07.990:E / AndroidRuntime(13864):在android.app.ActivityThread.main(ActivityThread.java:5290) 11-13 06:05:07.990:E / AndroidRuntime(13864):at java.lang.reflect.Method.invoke(Native Method) 11-13 06:05:07.990:E / AndroidRuntime(13864):at java.lang.reflect.Method.invoke(Method.java:372) 11-13 06:05:07.990:E / AndroidRuntime(13864):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:911) 11-13 06:05:07.990:E / AndroidRuntime(13864):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:706)
它说我的错误
StringRequest stringRequest = new StringRequest(Request.Method.POST, Config.LOGIN_URL, new Response.Listener<String>() {
我不知道故障在哪里。我做错了吗?每个答案对我都有帮助。提前致谢
答案 0 :(得分:0)
在此处更新代码:
(TextView)findViewById(R.id.btDaftar)
喜欢:
TextView tx = (TextView)findViewById(R.id.btDaftar);
tx.setOnClickListener(this);
并覆盖onClick()方法。