- Forum-Beiträge: 27
15.01.2016, 13:35:16 via Website
15.01.2016 13:35:16 via Website
Hallo
vorweg ermal die Info das ich eher ein noob auf dem Gebiet bin.
Seit einem Monat bin ich dran bei dem versuch eine app zu erstellen.
einige werden jetzt wahrscheinlich die Augen rollen was ich auch verstehen kann.
Die app die ich machen will ist vielleicht zum Anfang etwas wuchtig und brauch unbedingt eine Login Session.
welche ich jetzt versuche mit volley und JASON umzusetzen.
vom Server aus müsste eigentlich alles funktionieren.
nur Leider stoße ich jetzt beim ausführen der app die sich erstmal nur mit dem Login Register beschäftigt auf Fehler.
diese kann ich durch google und co leider nicht Identifizierenen.
Ich hoffe das hier wer vielleicht einen tip oder sogar eine Lösung hat.
Bearbeitet:
Gestartet bekomme ich sie.
wenn ich nix eingebe kommt die nachricht vom Server das nix eingetragen ist.
sobald ich aber etwas eintrage und auf login klicke stürzt sie wieder ab.
habe mal LoginActivity.class und den AppController.class und SQLiteHander.class mit hinzugefügt.
Vielen lieben dank
01-16 16:13:25.424 1577-1577/com.abc.smb.smb E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.abc.smb.smb, PID: 1577
java.lang.NullPointerException: println needs a message
at android.util.Log.println_native(Native Method)
at android.util.Log.e(Log.java:334)
at com.abc.smb.smb.LoginActivity$4.onErrorResponse(LoginActivity.java:128)
at com.android.volley.Request.deliverError(Request.java:524)
at com.android.volley.ExecutorDelivery$ResponseDeliveryRunnable.run(ExecutorDelivery.java:101)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5593)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
LoginActivity:
public class LoginActivity extends Activity {
private EditText emailTF, passwordTF;
private Button loginBtn, gotoRegBtn;
private ProgressDialog pDialog;
private SessionManager session;
private SQLiteHandler db;
private static final String TAG = LoginActivity.class.getSimpleName();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
emailTF = (EditText) findViewById(R.id.emailSF);
passwordTF = (EditText) findViewById(R.id.passwordSF);
loginBtn = (Button) findViewById(R.id.signin_btn);
gotoRegBtn = (Button) findViewById(R.id.notreg_btn);
pDialog = new ProgressDialog(this);
session = new SessionManager(getApplicationContext());
db = new SQLiteHandler(getApplicationContext());
if(session.isLoggedIn()){
Intent i = new Intent(this, MainActivity.class);
startActivity(i);
finish();
}
gotoRegBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(LoginActivity.this, RegisterActivity.class);
startActivity(i);
finish();
}
});
loginBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String email = emailTF.getText().toString();
String password = passwordTF.getText().toString();
if (!email.isEmpty() && !password.isEmpty()) {
<<75>> checkLogin(email, password);
} else {
Toast.makeText(LoginActivity.this, "Please enter details",
Toast.LENGTH_LONG).show();
}
}
});
}
public void checkLogin(final String email, final String password){
String tag_req = "login_request";
pDialog.setMessage("Logging In.....");
showDialog();
StringRequest strR = new StringRequest(
Request.Method.POST, AppConfig.LOGIN_URL,
new Response.Listener<String>() {
@Override
public void onResponse(String response){
hideDialog();
try{
JSONObject jsb = new JSONObject(response);
boolean error = jsb.getBoolean("error");
if(!error){
String uid = jsb.getString("uid");
JSONObject user = jsb.getJSONObject("user");
String name = user.getString("name");
String email = user.getString("email");
String created_at = user.getString("created_at");
db.addUser(name, email, uid, created_at);
session.setLogin(true);
Intent i = new Intent(LoginActivity.this, MainActivity.class);
startActivity(i);
finish();
}else{
String error_msg = jsb.getString("error_msg");
Toast.makeText(LoginActivity.this, error_msg, Toast.LENGTH_LONG).show();
}
}
catch (JSONException e){
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error){
Log.e(TAG, error.getMessage());
}
}
){
@Override
public Map<String, String> getParams(){
Map<String, String> p = new HashMap<String, String>();
p.put("tag", "login");
p.put("email", email);
p.put("password", password);
return p;
}
};
<<141>> AppController.getInstance().addToRequestQueue(strR, tag_req);
}
public void showDialog(){
if(!pDialog.isShowing()){
pDialog.show();
}
}
public void hideDialog(){
if(pDialog.isShowing()){
pDialog.dismiss();
}
}
}
AppControler:
public class AppController extends Application {
public static final String TAG = AppController.class.getSimpleName();
private RequestQueue myRequest;
private static AppController mInstance;
@Override
public void onCreate(){
super.onCreate();
mInstance = this;
}
public static synchronized AppController getInstance(){
return mInstance;
}
public RequestQueue getRequestQueue(){
if (myRequest == null){
myRequest = Volley.newRequestQueue(getApplicationContext());
}
return myRequest;
}
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(myRequest != null){
myRequest.cancelAll(tag);
}
}
}
SQLiteHandler:
public class SQLiteHandler extends SQLiteOpenHelper {
public static final String TAG = SQLiteHandler.class.getSimpleName();
private static final int DATABASE_VERSION = 1;
private static final String DATABASE_NAME = "login_db";
private static final String TABLE_NAME = "users";
private static final String KEY_ID = "id";
private static final String KEY_NAME = "name";
private static final String KEY_EMAIL = "email";
private static final String KEY_UID = "uid";
private static final String KEY_CREATED_AT = "created_at";
public SQLiteHandler (Context context){
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db){
String CREATE_TABLE = "CREATE TABLE " + TABLE_NAME + "("
+KEY_ID + " INTEGER PRIMARY KEY, " + KEY_NAME + " TEXT,"
+KEY_EMAIL + " TEXT UNIQUE," + KEY_UID + " TEXT,"
+KEY_CREATED_AT + " TEXT" + ")";
db.execSQL(CREATE_TABLE);
Log.d(TAG, "Database table created");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion){
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
onCreate(db);
}
public void addUser(String name, String email, String uid, String created_at){
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(KEY_NAME, name);
values.put(KEY_EMAIL, email);
values.put(KEY_UID, uid);
values.put(KEY_CREATED_AT, created_at);
long id = db.insert(TABLE_NAME, null, values);
db.close();
Log.d(TAG, "New user was added to sqlite " + id);
}
public HashMap<String, String> getUserDetails() {
HashMap<String, String> temp = new HashMap<String, String>();
String selectQuery = "SELECT * FROM "+ TABLE_NAME;
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
cursor.moveToFirst();
if(cursor.getCount() > 0){
temp.put("name", cursor.getString(1));
temp.put("email", cursor.getString(2));
temp.put("uid", cursor.getString(3));
temp.put("created_at", cursor.getString(4));
}
cursor.close();
db.close();
Log.d(TAG, "Fetching user info from sqlite");
return temp;
}
public int getRowCount(){
String countQuery = "SELECT * FROM "+ TABLE_NAME;
SQLiteDatabase db = this.getReadableDatabase();
Cursor c = db.rawQuery(countQuery, null);
int rowcount = c.getCount();
db.close();
c.close();
return rowcount;
}
public void deleteUser(){
SQLiteDatabase db = this.getWritableDatabase();
db.delete(TABLE_NAME, null, null);
db.close();
Log.d(TAG, "user has been deleted from sqlite");
}
}
— geändert am 16.01.2016, 16:14:59
Empfohlener redaktioneller Inhalt
Mit Deiner Zustimmung wird hier ein externer Inhalt geladen.
Mit Klick auf den oben stehenden Button erklärst Du Dich damit einverstanden, dass Dir externe Inhalte angezeigt werden dürfen. Dabei können personenbezogene Daten an Drittanbieter übermittelt werden. Mehr Infos dazu findest Du in unserer Datenschutzerklärung.