Страница входа Android с библиотекой залпа

Я пытаюсь настроить страницу входа в Android с помощью PHP и MySQL. Я натолкнулся на эту библиотеку Google ‘Volley.jar’, и я пытаюсь ее реализовать, но моя LoginActivity имеет ошибки при получении деталей и использовании AppController для выполнения запроса. Я приложил код LoginACtivity и AppController.
Активность входа

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);

inputUsername = (EditText) findViewById(R.id.username);
inputPassword = (EditText) findViewById(R.id.password);
btnLogin = (Button) findViewById(R.id.btnLogin);

// Progress dialog
pDialog = new ProgressDialog(this);
pDialog.setCancelable(false);

// Session manager
session = new SessionManager(getApplicationContext());

// Check if user is already logged in or not
if (session.isLoggedIn()) {
// User is already logged in. Take him to main activity
Intent intent = new Intent(LoginActivity.this, MainActivity.class);
startActivity(intent);
finish();
}

// Login button Click Event
btnLogin.setOnClickListener(new View.OnClickListener() {

public void onClick(View view) {
String username = inputUsername.getText().toString();
String password = inputPassword.getText().toString();

// Check for empty data in the form
if (username.trim().length() > 0 && password.trim().length() > 0) {
// login user
checkLogin(username, password);
} else {
// Prompt user to enter credentials
Toast.makeText(getApplicationContext(),
"Please enter the credentials!", Toast.LENGTH_LONG)
.show();
}
}

});
}
private void checkLogin(final String username, final String password) {
// Tag used to cancel the request
String tag_string_req = "req_login";

pDialog.setMessage("Logging in ...");
showDialog();

StringRequest strReq = new StringRequest(Method.POST,
AppConfig.URL_REGISTER, new Response.Listener<String>() {

@Override
public void onResponse(String response) {
Log.d(TAG, "Login Response: " + response.toString());
hideDialog();

try {
JSONObject jObj = new JSONObject(response);
boolean error = jObj.getBoolean("error");

// Check for error node in json
if (!error) {
// user successfully logged in
// Create login session
session.setLogin(true);

// Launch main activity
Intent intent = new Intent(LoginActivity.this,
MainActivity.class);
startActivity(intent);
finish();
} else {
// Error in login. Get the error message
String errorMsg = jObj.getString("error_msg");
Toast.makeText(getApplicationContext(),
errorMsg, Toast.LENGTH_LONG).show();
}
} catch (JSONException e) {
// JSON error
e.printStackTrace();
}

}
}, new Response.ErrorListener() {

@Override
public void onErrorResponse(VolleyError error) {
Log.e(TAG, "Login Error: " + error.getMessage());
Toast.makeText(getApplicationContext(),
error.getMessage(), Toast.LENGTH_LONG).show();
hideDialog();
}
}) {

@Override
protected Map<String, String> getParams() {
// Posting parameters to login url
Map<String, String> params = new HashMap<String, String>();
params.put("tag", "login");
params.put("username", username);
params.put("password", password);

return params;
}

};

// Adding request to request queue
AppController.getInstance().addToRequestQueue(strReq, tag_string_req);
}

private void showDialog() {
if (!pDialog.isShowing())
pDialog.show();
}

private void hideDialog() {
if (pDialog.isShowing())
pDialog.dismiss();
}

AppController

private RequestQueue mRequestQueue;

private static AppController mInstance;

@Override
public void onCreate() {
super.onCreate();
mInstance = this;
}

public static synchronized AppController getInstance() {
return mInstance;
}

public RequestQueue getRequestQueue() {
if (mRequestQueue == null) {
mRequestQueue = Volley.newRequestQueue(getApplicationContext());
}

return mRequestQueue;
}

public <T> void addToRequestQueue(Request<T> req, String tag) {
req.setTag(TextUtils.isEmpty(tag) ? TAG : tag);
getRequestQueue().add(req);
}

public <T> void addToRequestQueue(Request<T> req) {
req.setTag(TAG);
getRequestQueue().add(req);
}

public void cancelPendingRequests(Object tag) {
if (mRequestQueue != null) {
mRequestQueue.cancelAll(tag);
}
}

И вот мой logcat:
04-03 04: 16: 40.190: E / AndroidRuntime (1099): ИСКЛЮЧИТЕЛЬНОЕ ИСКЛЮЧЕНИЕ: основное
04-03 04: 16: 40.190: E / AndroidRuntime (1099): процесс: com.example.zcasm_learningplatform, PID: 1099
04-03 04: 16: 40.190: E / AndroidRuntime (1099): java.lang.NullPointerException
04-03 04: 16: 40.190: E / AndroidRuntime (1099): на com.example.zcasm_learningplatform.LoginActivity.checkLogin (LoginActivity.java:154)
04-03 04: 16: 40.190: E / AndroidRuntime (1099): на com.example.zcasm_learningplatform.LoginActivity.access $ 2 (LoginActivity.java:87)
04-03 04: 16: 40.190: E / AndroidRuntime (1099): на com.example.zcasm_learningplatform.LoginActivity $ 1.onClick (LoginActivity.java:76)
04-03 04: 16: 40.190: E / AndroidRuntime (1099): на android.view.View.performClick (View.java:4424)
04-03 04: 16: 40.190: E / AndroidRuntime (1099): на android.view.View $ PerformClick.run (View.java:18383)
04-03 04: 16: 40.190: E / AndroidRuntime (1099): на android.os.Handler.handleCallback (Handler.java:733)
04-03 04: 16: 40.190: E / AndroidRuntime (1099): на android.os.Handler.dispatchMessage (Handler.java:95)
04-03 04: 16: 40.190: E / AndroidRuntime (1099): на android.os.Looper.loop (Looper.java:137)
04-03 04: 16: 40.190: E / AndroidRuntime (1099): на android.app.ActivityThread.main (ActivityThread.java:4998)
04-03 04: 16: 40.190: E / AndroidRuntime (1099): на java.lang.reflect.Method.invokeNative (собственный метод)
04-03 04: 16: 40.190: E / AndroidRuntime (1099): в java.lang.reflect.Method.invoke (Method.java:515)
04-03 04: 16: 40.190: E / AndroidRuntime (1099): на com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:777)
04-03 04: 16: 40.190: E / AndroidRuntime (1099): на com.android.internal.os.ZygoteInit.main (ZygoteInit.java:593)
04-03 04: 16: 40.190: E / AndroidRuntime (1099): at dalvik.system.NativeStart.main (собственный метод)

1

Решение

Та же ошибка произошла и в моем случае, я исправил ошибку, добавив класс AppControler в манифест. но могут быть другие объекты, которые вызывают эту ошибку. Я не могу видеть линию 154.

В AndroidManifest.xml

 <application
android:name="xxx.xxx.xxx.xxx.AppController"....
>

здесь ххх ссылается на имя вашего пакета и … ссылается на ваш существующий код

0

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector