SQL Lite issues


Last Updated:

  1. jdizzle1988

    jdizzle1988 Member This Topic's Starter

    Joined:
    Jul 1, 2010
    Messages:
    12
    Likes Received:
    1
    I am working on a program that writes files to a database that is copied from the assets of the application. The copy works fine. However when I try to write to the DB It doesn't error out, logcat shows nothing, but the DB will not change. I pull the DB out of the emulater using the DDMS window then open it with SQLLite browser. The database is default as if nothing was inserted. Not sure what is going on. Can anyone help? (code below).

    This is in a class I created called DBAdapter.java. This is what is called in the class of the application.
    Code (Text):
    1.  
    2.  //---insert a game into the database---
    3.         public long insertGame(Integer id, Integer user_id, String title, String esrb, String genre, Integer rating, String review, Integer pic_id)
    4.         {
    5.             ContentValues initialValues = new ContentValues();
    6.             initialValues.put(KEY_ID, id);
    7.             initialValues.put(KEY_USER_ID, user_id);
    8.             initialValues.put(KEY_TITLE, title);
    9.             initialValues.put(KEY_ESRB, esrb);
    10.             initialValues.put(KEY_GENRE, genre);
    11.             initialValues.put(KEY_RATING, rating);
    12.             initialValues.put(KEY_REVIEW, review);
    13.             initialValues.put(KEY_PICID, pic_id);
    14.             return db.insert(DATABASE_TABLE1, null, initialValues);
    15.         }
    16.  
    This is in a class called InputGame.java.
    Code (Text):
    1.  
    2. DBAdapter db = new DBAdapter(this);
    3.  
    4.     @Override
    5.     public void onCreate(Bundle savedInstanceState) {
    6.         super.onCreate(savedInstanceState);
    7.         setContentView(R.layout.inputgame);
    8.        
    9.        
    10.         Spinner s = (Spinner) findViewById(R.id.spnRatings);
    11.         ArrayAdapter adapter = ArrayAdapter.createFromResource(this, R.array.ratings, android.R.layout.simple_spinner_item);
    12.         adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    13.         s.setAdapter(adapter);
    14.        
    15.         Spinner s1 = (Spinner) findViewById(R.id.spnGenre);
    16.         ArrayAdapter adapter1 = ArrayAdapter.createFromResource(this, R.array.genre, android.R.layout.simple_spinner_item);
    17.         adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    18.         s1.setAdapter(adapter1);
    19.        
    20.        
    21.         RatingBar ratingbar = (RatingBar) findViewById(R.id.rbRating);
    22.         ratingbar.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {
    23.             public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
    24.                 Toast.makeText(InputGame.this, "New Rating: " + rating, Toast.LENGTH_SHORT).show();
    25.  
    26.                 }
    27.             });
    28.  
    29. Button btnAddGame = (Button) findViewById(R.id.btnGSubmit);
    30.         btnAddGame.setOnClickListener(new View.OnClickListener() {
    31.             public void onClick(View v) {
    32.                
    33.                 EditText txtTitle = (EditText) findViewById(R.id.edtTitle);
    34.                 EditText txtReview = (EditText) findViewById(R.id.Review);
    35.                 Spinner s = (Spinner) findViewById(R.id.spnRatings);
    36.                 Spinner s1 = (Spinner) findViewById(R.id.spnGenre);
    37.                 RatingBar ratingbar = (RatingBar) findViewById(R.id.rbRating);
    38.                
    39.                 String Title = txtTitle.getText().toString();
    40.                 String Genre = s1.getSelectedItem().toString();
    41.                 String ESRB = s.getSelectedItem().toString();
    42.                 Integer Stars = ratingbar.getNumStars();
    43.                 String Review = txtReview.getText().toString();
    44.                
    45.                 db.open();        
    46.                 long id;
    47.                 id = db.insertGame(
    48.                         00001, 00001, Title, ESRB, Genre, Stars, Review, 00001);        
    49.                 db.close();
    50.                
    51.                 Toast.makeText(InputGame.this, "Save Successful!", Toast.LENGTH_SHORT).show();
    52.    
    53.                
    54.             }
    55.         });
    56.  
     

    Advertisement

Share This Page

Loading...