Bir uygulamanın içinde 3 fragman var ve bunlardan birinde SQLite veritabanından kullanıcı adı gösteriyorum. Ne olursa olsun, yeni bir kullanıcı kaydettiğimde ve kullanıcılarla ilk kez giriş yaptığımda, kullanıcıların adının görüneceğini düşündüğü metin görünümünde, NULL değeri görüntülendiğimde, aynı kullanıcıyla oturum açıp tekrar oturum açtığımda, adı gerektiği gibi görünür.İlk kullanıcılar oturum açtıktan sonra boş değerlerin gösterilmesi android içinde oturum açıyor
Kullanıcıyı kaydettikten sonra, tüm veriler bir veritabanına eklenir, kontrol ettim.
Herhangi bir fikir bu soruna neden olabilir? Hiçbir fikrim kod parçası var gibi istek üzerine bazı kod katacak, fragmanları veya java dosyaları bu neden olabilir ..
bu sorunun çözümüne yardımcı olmak için bazı kod eklemiş
DÜZENLENMİŞ. ana ekranda içeride
Girişi fonksiyonu (bir kez uygulama başlattı):
@Override
public void onViewCreated(View view, Bundle savedInstanceState){
profileName = (TextView) getActivity().findViewById(R.id.profileName);
// SqLite database handler
db = new SQLiteHandler(getActivity().getApplicationContext());
// session manager
session = new SessionManager(getActivity().getApplicationContext());
if (!session.isLoggedIn()) {
logoutUser();
}
// Fetching user details from SQLite
HashMap<String, String> user = db.getUserDetails();
String name = user.get("name");
// Displaying the user details on the screen
profileName.setText(name);
}
Kayıt fonksiyonu kısmı::
public void onResponse(String response) {
Log.d(TAG, "Register Response: " + response.toString());
hideDialog();
try {
JSONObject jObj = new JSONObject(response);
boolean error = jObj.getBoolean("error");
if (!error) {
// User successfully stored in MySQL
// Now store the user in sqlite
String uid = jObj.getString("uid");
JSONObject user = jObj.getJSONObject("user");
String name = user.getString("name");
String email = user.getString("email");
String created_at = user.getString("created_at");
// Inserting row in users table
db.addUser(name, email, uid, created_at);
// Launch login activity
Intent intent = new Intent(
Register.this,
Main.class);
startActivity(intent);
finish();
} else {
// Error occurred in registration. Get the error
// message
error_msg.setVisibility(View.VISIBLE);
String msg = jObj.getString("error_msg");
error_msg.setText(msg);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e(TAG, "Registration Error: " + error.getMessage());
Toast.makeText(getApplicationContext(),
error.getMessage(), Toast.LENGTH_LONG).show();
hideDialog();
}
}) {
kullanıcıların isim diplayed edilmelidir fragmanı içindeki
private void checkLogin(final String email, final String password) {
// Tag used to cancel the request
String tag_string_req = "req_login";
pDialog.setMessage("Logging in ...");
showDialog();
StringRequest strReq = new StringRequest(Request.Method.POST,
AppConfig.URL_LOGIN, 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);
// Now store the user in SQLite
String uid = jObj.getString("uid");
JSONObject user = jObj.getJSONObject("user");
String name = user.getString("name");
String email = user.getString("email");
String created_at = user.getString("created_at");
// Inserting row in users table
db.addUser(name, email, uid, created_at);
// Launch main activity
Intent intent = new Intent(Main.this,
Logged.class);
startActivity(intent);
finish();
} else {
error_msg.setVisibility(View.VISIBLE);
String msg = jObj.getString("error_msg");
error_msg.setText(msg);
}
} catch (JSONException e) {
// JSON error
e.printStackTrace();
Toast.makeText(getApplicationContext(), "Json error: " + e.getMessage(), Toast.LENGTH_LONG).show();
}
}
}, 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("email", email);
params.put("password", password);
return params;
}
};
// Adding request to request queue
AppController.getInstance().addToRequestQueue(strReq, tag_string_req);
}
onViewCreated fonk
sen değişkenin boş olmadığından emin değil misiniz? Atadı ve görüntüledin mi? Muhtemelen, bazı kodların çıkmasına yardımcı olur. – 3kings
Sorun herhangi bir noktada olabilir - veritabanı kullanıcı adını döndürmüyor, denetleyici/DAO katmanı doğru isimde geri dönmüyorsa istemci veya istemci kodunun doğru işlenmemesi ve görüntülenmemesi .. Bu nedenle, ideal tüm 3 katmandan ilgili bölümler koymalıdır. – hagrawal
kullanıcı kaydedildikten sonra, onun ayrıntıları mysql ve sqlite veritabanları içinde eklenir .. Verilerin tamamı eklenir, ancak neşredilecek hiçbir şey yoktur. İkinci bir – AlwaysConfused