Ошибка входа в залп: Null

Привет, я пытаюсь создать страницу входа, используя библиотеку залпов. Когда я запускаю приложение, введите необходимые учетные данные и, наконец, нажмите кнопку входа в систему, мой logcat отображает эту ошибку:

ошибка logcat

я не знаю, что, кажется, вызывает эту ошибку, вот моя активность входа в систему:

public class LoginActivity extends Activity {
private static final String TAG = LoginActivity.class.getSimpleName();
private Button btnLogin;
private EditText inputUsername;
private EditText inputPassword;
private ProgressDialog pDialog;
private SessionManager session;

@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();
}}

Пожалуйста, помогите мне. Или помогите мне найти более простой способ входа в систему с использованием JSON и базы данных MYSQL. Спасибо

Вот мой класс AppController:

public class AppController extends Application {
public static final String TAG = AppController.class.getSimpleName();

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);
}
}}

0

Решение

В моем случае просто я меняю свой локальный URL на онлайн

URL_REGISTER = "http://192.168.1.1/Register.php";

в

URL_REGISTER = "http://Webserver/Register.php"

не знаю, почему это работает для меня, лол

0

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

метод getInstance () из этого кода

AppController.getInstance().addToRequestQueue(strReq, tag_string_req);

может дать вам ноль.

вы можете опубликовать код класса AppCnotroller

0

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