Wrox Programmer Forums
|
BOOK: Professional Android Application Development ISBN: 978-0-470-34471-2
This is the forum to discuss the Wrox book Professional Android Application Development by Reto Meier; ISBN: 9780470344712
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional Android Application Development ISBN: 978-0-470-34471-2 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 18th, 2009, 09:02 AM
Registered User
 
Join Date: Apr 2009
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Default Chapter 6: Creating Table-example not working

So I followed the examples in chapter 6 for quickly creating a small database. But when I run this code the exception is thrown. How come? Im using SDK1.1


Code:
package simpleTest.database;

import android.app.Activity;
import android.content.ContentValues;
import android.content.Context;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.widget.Toast;

public class DBtest extends Activity {
    
    private static final String DATABASE_NAME = "myDatabase.db";
    private static final String DATABASE_TABLE = "mainTable";
    private static final String DATABASE_CREATE = "create table " + DATABASE_TABLE + " ( _id integer primary key autoincrement," +
    "column_one text not null);";
    
    SQLiteDatabase myDatabase;
    
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
            

        myDatabase = openOrCreateDatabase(DATABASE_NAME, Context.MODE_PRIVATE, null);
        try {
            myDatabase.execSQL(DATABASE_CREATE);
            } catch (SQLException ex){
                Toast.makeText(getBaseContext(), "error...", 
                        Toast.LENGTH_SHORT).show();
            }
    }
}
 
Old April 21st, 2009, 12:07 PM
Authorized User
 
Join Date: Mar 2009
Posts: 21
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Check for a Database error in the Log window, if you're using Eclipse. That will probably give you a good hint.
The Following User Says Thank You to sierawsk For This Useful Post:
sandstrp (April 27th, 2009)
 
Old April 27th, 2009, 06:45 PM
Registered User
 
Join Date: Apr 2009
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Default

why thank you, that helped. The table already existed, so the exception was thrown! ^__^





Similar Threads
Thread Thread Starter Forum Replies Last Post
creating table ph0neman Classic ASP Basics 3 January 22nd, 2008 05:06 PM
creating a junction table sarah lee SQL Server 2000 1 January 10th, 2007 05:18 PM
Creating table with existing table without value kumar_kumar Oracle 1 January 4th, 2005 07:12 AM
Creating a medal table awood2000 XSLT 12 November 15th, 2004 07:26 AM
padding not working in table tag [email protected] HTML Code Clinic 1 September 17th, 2003 08:41 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.