Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Problem developing app for Android

  1. #1
    Junior Member
    Join Date
    May 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Problem developing app for Android

    Hi All,

    I am a not experienced developer. All I want to do is make a small app to track information of football on TV. I want to do it through a small DB however I've been struggling a lot with an error I've been trying to discover in the last two weeks but I have not been able.

    I have teh following code in the class I create the DB

    public class DBAdapter {
    public static final String KEY_ROWID = "_id";
    public static final String KEY_GDATE = "gdate";
    public static final String KEY_GTIME = "gtime";
    public static final String KEY_GGAME = "ggame";
    public static final String KEY_GCOMPETITION = "gcompetition";
    public static final String KEY_GCHANNEL = "gchannel";

    private static final String TAG = "DBAdapter";

    private static final String DATABASE_NAME = "FonTV";
    private static final String DATABASE_TABLE = "games";
    private static final int DATABASE_VERSION = 2;

    private static final String DATABASE_CREATE =
    "create table games (_id integer primary key autoincrement, "
    + "gdate text not null, gtime text not null, ggame text not null" +
    "gcompetition text not null, gchannel text not null);";

    private final Context context;

    private DatabaseHelper DBHelper;
    private SQLiteDatabase db;

    public DBAdapter(Context ctx)
    {
    this.context = ctx;
    DBHelper = new DatabaseHelper(context);
    }

    private static class DatabaseHelper extends SQLiteOpenHelper
    {
    DatabaseHelper(Context context)
    {
    super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db)
    {
    try {
    db.execSQL(DATABASE_CREATE);
    } catch (SQLException e) {
    e.printStackTrace();
    }
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
    {
    Log.w(TAG, "Upgrading database from version " + oldVersion + " to "
    + newVersion + ", which will destroy all old data");
    db.execSQL("DROP TABLE IF EXISTS contacts");
    onCreate(db);
    }
    }

    //---opens the database---
    public DBAdapter open() throws SQLException
    {
    db = DBHelper.getWritableDatabase();
    return this;
    }

    //---closes the database---
    public void close()
    {
    DBHelper.close();
    }

    //---insert a contact into the database---
    public long insertContact(String gdate, String gtime, String ggame, String gcompetition, String gchannel )
    {
    ContentValues initialValues = new ContentValues();
    initialValues.put(KEY_GDATE, gdate);
    initialValues.put(KEY_GTIME, gtime);
    initialValues.put(KEY_GGAME, ggame);
    initialValues.put(KEY_GCOMPETITION, gcompetition);
    initialValues.put(KEY_GCHANNEL, gchannel);

    return db.insert(DATABASE_TABLE, null, initialValues);
    }
    }
    And the main class where I try to insert data has this:

    public class ResultsDBActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    DBAdapter db = new DBAdapter(this);

    db.open();
    long id = db.insertContact("12/may", "08:00", "Leeds vs York", "JUME Cup", "ITV, BBC");
    id = db.insertContact("13/may", "09:00", "London vs Bath", "JUME Cup", "ITV, BBC2");
    db.close();
    }
    }

    However when I try to run it, the debugger shows and error that says:

    E/Database(330): android.database.sqlite.SQLiteException: no such table: games: , while compiling: INSERT INTO games(gchannel, ggame, gtime, gdate, gcompetition) VALUES(?, ?, ?, ?, ?);

    I’ve trying to change parameters and many things but I haven’t found where the problem is. Can someone help me please?


  2. #2
    Member
    Join Date
    Feb 2011
    Posts
    33
    Thanks
    0
    Thanked 4 Times in 4 Posts

    Default Re: Problem developing app for Android

    Have you tried debugging to see if the table is actually being created?


    All intelligent thoughts have already been thought;
    what is necessary is only to try to think them again.



Similar Threads

  1. Best Tools for developing in Java/Android
    By Nesh108 in forum Android Development
    Replies: 11
    Last Post: October 24th, 2012, 07:34 AM
  2. Interested in developing an Android app eventually
    By madiaz3 in forum Member Introductions
    Replies: 1
    Last Post: May 17th, 2012, 07:02 AM
  3. problem developing a frame help me...
    By bluestar_me in forum AWT / Java Swing
    Replies: 3
    Last Post: February 18th, 2012, 05:18 AM
  4. beginner developing android app to stream radio station needs help!
    By infiniteoo in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 3rd, 2012, 03:31 PM
  5. Any alternative of Eclipse for developing android app?
    By vincentroberts in forum Java IDEs
    Replies: 6
    Last Post: January 5th, 2012, 01:48 AM