有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

尝试向SQLite数据库创建/添加数据时发生java错误

当我试图创建/添加数据到我的SQLite数据库时,我得到了很多错误,但不知道为什么,因为它看起来应该对我有用。代码如下,我将在下面发布错误。提前感谢你的帮助

enter code here
public class MyActivity extends Activity
{
   @Override
   public void onCreate(Bundle savedInstanceState)
   {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);

      //create an instance of the PlayerDatabase class and pass this context through parameters;
      PlayerDatabase playerProfile = new PlayerDatabase(this);

      try
      {
         //open the database;
         playerProfile.open();
      }//try;
      catch (SQLException e)
      {
         //print description of the error;
         e.printStackTrace();
      }//catch;

      //insert data into the table;
      playerProfile.createInsert("Player", "Connor", "5", "1234");
      //close the database;
      playerProfile.close();
   }//onCreate;
}//class;



public class PlayerDatabase
{
   public static final String KEY_PLAYER = "Player";
   public static final String KEY_NAME = "Name";
   public static final String KEY_GUESSES = "NumberOfGuesses";
   public static final String KEY_NUMBER= "NumberToGuess";

   private static final String DATABASE_NAME = "PlayerData.db";
   private static final String DATABASE_MARKSTABLE = "PlayerData";
   private static final int DATABASE_VERSION = 1;

   //create instance of DbHelper class called ourHelper;
   private DbHelper ourHelper;
   //create a context called ourContext;
   private final Context ourContext;
   //create an instance of SQLiteDatabase called ourDatabase to be the database;
   private SQLiteDatabase ourDatabase;


   //constructor to pass through context;
   public PlayerDatabase(Context c)
   {
      ourContext = c;
   }//constructor;


   //open the database;
   public PlayerDatabase open()throws SQLException
   {
      //finish creating the instance of the DbHelper class;
      ourHelper = new DbHelper(ourContext);
      //create database;
      ourDatabase = ourHelper.getWritableDatabase();
      return this;
   }//open;

   //close the database;
   public void close()
   {
      ourHelper.close();
   }//close;


   //insert data into the database;
   public long createInsert(String player, String name, String guesses,
                        String number)
   {
      // TODO Auto-generated method stub
      ContentValues cv = new ContentValues();
      cv.put(KEY_PLAYER, player);
      cv.put(KEY_NAME, name);
      cv.put(KEY_GUESSES, guesses);
      cv.put(KEY_NUMBER, number);
      return ourDatabase.insert(DATABASE_MARKSTABLE, null, cv);
   } //createInsert;




   //DbHelper class within PlayerDatabase class;
   private static class DbHelper extends SQLiteOpenHelper
   {

      public DbHelper(Context context)
      {
         super(context, DATABASE_NAME, null, DATABASE_VERSION);
         // TODO Auto-generated constructor stub
      }//DbHelper constructor;


      //when DbHelper is first created it will create this table;
      @Override
      public void onCreate(SQLiteDatabase db)
      {
         // TODO Auto-generated method stub
         db.execSQL(" CREATE TABLE " + DATABASE_MARKSTABLE + " (" +
             KEY_PLAYER + " TEXT PRIMARY KEY, " +
             KEY_NAME + " TEXT NOT NULL, " +
             KEY_GUESSES + " TEXT NOT NULL, " +
             KEY_NUMBER + " TEXT NOT NULL);"
         );
      }//DbHelper onCreate;


      //only used when database is upgraded;
      @Override
      public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
      {
         // TODO Auto-generated method stub

         db.execSQL("DROP TABLE IF EXISTS " + DATABASE_MARKSTABLE);
         onCreate(db);
      }//DbHelper onUpgrade;
    } //class DbHelper;
}//class;

这是错误报告

12-27 13:15:43.549: ERROR/ActivityThread(6572): Service com.安卓.exchange.ExchangeService has leaked ServiceConnection com.安卓.emailcommon.service.ServiceProxy$ProxyConnection@40cea8d8 that was originally bound here
        安卓.app.ServiceConnectionLeaked: Service com.安卓.exchange.ExchangeService has leaked ServiceConnection com.安卓.emailcommon.service.ServiceProxy$ProxyConnection@40cea8d8 that was originally bound here
        at 安卓.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
        at 安卓.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
        at 安卓.app.ContextImpl.bindService(ContextImpl.java:1418)
        at 安卓.app.ContextImpl.bindService(ContextImpl.java:1407)
        at 安卓.content.ContextWrapper.bindService(ContextWrapper.java:473)
        at com.安卓.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
        at com.安卓.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
        at com.安卓.emailcommon.service.ServiceProxy.test(ServiceProxy.java:191)
        at com.安卓.exchange.ExchangeService$7.run(ExchangeService.java:1850)
        at com.安卓.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
        at com.安卓.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
        at 安卓.os.AsyncTask$2.call(AsyncTask.java:287)
        at java.util.concurrent.FutureTask.run(FutureTask.java:234)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
        at java.lang.Thread.run(Thread.java:856)
12-27 13:15:43.549: ERROR/StrictMode(6572): null
        安卓.app.ServiceConnectionLeaked: Service com.安卓.exchange.ExchangeService has leaked ServiceConnection com.安卓.emailcommon.service.ServiceProxy$ProxyConnection@40cea8d8 that was originally bound here
        at 安卓.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
        at 安卓.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
        at 安卓.app.ContextImpl.bindService(ContextImpl.java:1418)
        at 安卓.app.ContextImpl.bindService(ContextImpl.java:1407)
        at 安卓.content.ContextWrapper.bindService(ContextWrapper.java:473)
        at com.安卓.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
        at com.安卓.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
        at com.安卓.emailcommon.service.ServiceProxy.test(ServiceProxy.java:191)
        at com.安卓.exchange.ExchangeService$7.run(ExchangeService.java:1850)
        at com.安卓.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
        at com.安卓.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
        at 安卓.os.AsyncTask$2.call(AsyncTask.java:287)
        at java.util.concurrent.FutureTask.run(FutureTask.java:234)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
        at java.lang.Thread.run(Thread.java:856)
12-27 13:15:43.739: ERROR/ActivityThread(6572): Service com.安卓.exchange.ExchangeService has leaked ServiceConnection com.安卓.emailcommon.service.ServiceProxy$ProxyConnection@40cd08b0 that was originally bound here
        安卓.app.ServiceConnectionLeaked: Service com.安卓.exchange.ExchangeService has leaked ServiceConnection com.安卓.emailcommon.service.ServiceProxy$ProxyConnection@40cd08b0 that was originally bound here
        at 安卓.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
        at 安卓.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
        at 安卓.app.ContextImpl.bindService(ContextImpl.java:1418)
        at 安卓.app.ContextImpl.bindService(ContextImpl.java:1407)
        at 安卓.content.ContextWrapper.bindService(ContextWrapper.java:473)
        at com.安卓.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
        at com.安卓.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
        at com.安卓.emailcommon.service.AccountServiceProxy.getDeviceId12-27 13:24:07.950: ERROR/StrictMode(6572): null
12-27 13:24:10.041: ERROR/ThrottleService(6245): problem during onPollAlarm: java.lang.IllegalStateException: problem parsing stats: java.io.FileNotFoundException: /proc/net/xt_qtaguid/iface_stat_all: open failed: ENOENT (No such file or directory)

共 (0) 个答案