SQLite数据未存储在Android数据库中

时间:2016-02-09 17:32:26

标签: java android sqlite

我正在尝试将数据存储在SQLite数据库中,但我不知道为什么数据没有存储在表中我检查了100次我的数据库名称,列名,通过网络搜索我无法找到原因。请发布有人帮忙 码 Wishes.java

String url = "http://programmingly.com/bvn/test/ws/listQuotes.php";
ListView lv;
ImageView ivv;
AQuery aQuery;
ProgressDialog progressDialog;
JSONObject jsonObject;
ArrayList<String> al;
List<String> items;
String path;
SQLiteDatabase db;
Cursor c;
ArrayList<String> arryli = new ArrayList<String>();

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.d("vips", "onCreate()Log..");
    setContentView(R.layout.activity_wishes);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    aQuery = new AQuery(this);
    progressDialog = new ProgressDialog(this);
    progressDialog.setMessage("loading...");
    getMyQuotes();
    //My SQLiteHelper Class
    MyHelper helper = new MyHelper(getApplicationContext());
    db = helper.getWritableDatabase();

    lv = (ListView) findViewById(R.id.listView);
    lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (!isNetworkConnected()) {
                Intent data = new Intent(Wishes.this, MyWish.class);
                data.putExtra("str", items.get(position));
                startActivity(data);
            } else {
                Intent mydata = new Intent(Wishes.this, MyWish.class);
                mydata.putExtra("str", arryli.get(position));
                startActivity(mydata);
            }


        }
    });
}
private boolean isNetworkConnected() {
    ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    return cm.getActiveNetworkInfo() != null;
}

    public void getMyQuotes() {
    aQuery.progress(progressDialog).ajax(url, JSONObject.class, new AjaxCallback<JSONObject>() {
        @Override
        public void callback(String url, JSONObject object, AjaxStatus status) {

            if (object != null) {
                String quotos = object.optString("quote_data");
                String msg = object.optString("msg");
             try {
                    JSONArray jsonArray = new JSONArray(quotos);
                    al = new ArrayList<String>();
                    for (int i = 0; i < jsonArray.length(); i++) {
                        jsonObject = jsonArray.getJSONObject(i);
                        String str = jsonObject.getString("quote");
                        arryli.add(str);
                        //DataStore
                        ContentValues cv = new ContentValues();
                        cv.put("WishName",str);
                        db.insert("Wish",null,cv);
                        Log.d("DATA", "Data Stored" + cv);
                    }


                  CustomeAdapter mycustomeAdapter = new CustomeAdapter(arryli,Wishes.this);
                      mycustomeAdapter.notifyDataSetChanged();
                    lv.setAdapter(mycustomeAdapter);



                } catch (JSONException e) {
                    Toast.makeText(getApplicationContext(), "Server is busy Reciving data..", Toast.LENGTH_LONG).show();
                }
               // saveMyData();


            } else {

                //SimpleCursorAdapter sd = new SimpleCursorAdapter(getApplicationContext(), R.layout.single_row,c, new String[]{"msg"}, new int[]{R.id.tv_wishdata});
                //lv.setAdapter(sd);
               //String query = "Select"+myHelper.MESSAGE+"from"+myHelper.TABLE_NAME;
                // db.execSQL(query);
                //String query = "select * from wishes ";
                //Toast.makeText(getApplicationContext(),""+query,Toast.LENGTH_LONG).show();
               // String query = "Select"+myHelper.MESSAGE+"from"+myHelper.TABLE_NAME;
                //SQLiteDatabase database;
              //  MyHelper myHelper1=new MyHelper(Wishes.this);
                //db = myHelper1.getReadableDatabase();
                //Cursor cursor = db.rawQuery(query, null);
                //Cursor cursor = db.rawQuery("select rowid _id,* from"+myHelper1.TABLE_NAME+"", null);

                //Toast.makeText(getApplicationContext(),""+cursor,Toast.LENGTH_LONG).show();
                /*if(cursor!=null)
                {
                    cursor.moveToFirst();
                    Toast.makeText(Wishes.this, ""+cursor.getString(1), Toast.LENGTH_SHORT).show();
                }*/

这是MyHelper.java

    package com.tdi.wish.wishes;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class MyHelper extends SQLiteOpenHelper {

    public MyHelper(Context context) {
        super(context,"Mydatabase",null,2);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("create table Wish(WishName string)");
        Log.d("Table Created", "YES");
    }
}

这是我的日志

2-09 16:59:48.424 701-1306/? I/Icing: doRemovePackageData com.tdi.wish.wishes
02-09 17:02:26.716 18007-18007/? D/DATA: Data Storedkmaiv aaauaanc akaj
02-09 17:02:26.720 18007-18007/? D/DATA: Data Storedabc de jfia a aiuan
02-09 17:08:34.552 21492-21492/? D/DATA: Data Storedname=kmaiv aaauaanc akaj
02-09 17:08:34.556 21492-21492/? D/DATA: Data Storedname=abc de jfia a aiuan
02-09 17:10:35.420 22664-22664/? D/DATA: Data Storedname=kmaiv aaauaanc akaj
02-09 17:10:35.424 22664-22664/? D/DATA: Data Storedname=abc de jfia a aiuan
02-09 17:16:04.348 25914-25914/? D/DATA: Data StoredWishName=kmaiv aaauaanc akaj
02-09 17:16:04.356 25914-25914/? D/DATA: Data StoredWishName=abc de jfia a aiuan

我在该代码中找不到任何错误。我不知道为什么没有存储数据。

这是我的数据库截图

enter image description here

second image from Android Moniter

请有人帮忙

0 个答案:

没有答案