解析XML时出错 - 格式不正确(无效令牌)

时间:2015-01-06 00:27:39

标签: java android xml sqlite

我已经检查了其他XML文件是否有错误,但是这是错误消息说错误所在的文件。每当我尝试运行应用程序时,都会弹出一条消息,说“文件”生成的文件夹下,不应编辑“。

package com.example.drive.drivercorder;

import android.content.ContentValues; 

import android.content.Context;

import android.database.Cursor;

import android.database.sqlite.SQLiteDatabase;

import android.database.sqlite.SQLiteOpenHelper;

import android.util.Log;



public class DBAdapter {

    private static final String TAG = "DBAdapter";

    public static final String KEY_ROWID = "_id";
    public static final int COL_ROWID = 0;

    public static final String KEY_DRIVETIME = "Drive Time";
    public static final String KEY_NIGHTORDAY = "Time of Day";



    public static final int COL_DRIVETIME = 1;
    public static final int COL_NIGHTORDAY = 2;



    public static final String[] ALL_KEYS = new String[] {KEY_ROWID, KEY_DRIVETIME, KEY_NIGHTORDAY, };


    public static final String DATABASE_NAME = "MyDb";
    public static final String DATABASE_TABLE = "mainTable";

    public static final int DATABASE_VERSION = 2;   

    private static final String DATABASE_CREATE_SQL = 
            "create table " + DATABASE_TABLE 
            + " (" + KEY_ROWID + " integer primary key autoincrement, "

            + KEY_DRIVETIME + " integer not null, "
            + KEY_NIGHTORDAY + " text not null "



            + ");";


    private final Context context;

    private DatabaseHelper myDBHelper;
    private SQLiteDatabase db;



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


    public DBAdapter open() {
        db = myDBHelper.getWritableDatabase();
        return this;
    }


    public void close() {
        myDBHelper.close();
    }


    public long insertRow(int drivetime, String nightorday) {

        ContentValues initialValues = new ContentValues();
        initialValues.put(KEY_DRIVETIME, Drive Time);
        initialValues.put(KEY_NIGHTORDAY, Time of Day);



        return db.insert(DATABASE_TABLE, null, initialValues);
    }

    public boolean deleteRow(long rowId) {
        String where = KEY_ROWID + "=" + rowId;
        return db.delete(DATABASE_TABLE, where, null) != 0;
    }

    public void deleteAll() {
        Cursor c = getAllRows();
        long rowId = c.getColumnIndexOrThrow(KEY_ROWID);
        if (c.moveToFirst()) {
            do {
                deleteRow(c.getLong((int) rowId));              
            } while (c.moveToNext());
        }
        c.close();
    }


    public Cursor getAllRows() {
        String where = null;
        Cursor c =  db.query(true, DATABASE_TABLE, ALL_KEYS, 
                            where, null, null, null, null, null);
        if (c != null) {
            c.moveToFirst();
        }
        return c;
    }


    public Cursor getRow(long rowId) {
        String where = KEY_ROWID + "=" + rowId;
        Cursor c =  db.query(true, DATABASE_TABLE, ALL_KEYS, 
                        where, null, null, null, null, null);
        if (c != null) {
            c.moveToFirst();
        }
        return c;
    }


    public boolean updateRow(long rowId, String drivetime, String nightorday) {
        String where = KEY_ROWID + "=" + rowId;

        ContentValues newValues = new ContentValues();
        newValues.put(KEY_DRIVETIME, Drive Time);
        newValues.put(KEY_NIGHTORDAY, Time of Day);

        return db.update(DATABASE_TABLE, newValues, where, null) != 0;
    }


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

        @Override
        public void onCreate(SQLiteDatabase _db) {
            _db.execSQL(DATABASE_CREATE_SQL);           
        }

        @Override
        public void onUpgrade(SQLiteDatabase _db, int oldVersion, int newVersion) {
            Log.w(TAG, "Upgrading application's database from version " + oldVersion
                    + " to " + newVersion + ", which will destroy all old data!");

            _db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE);


            onCreate(_db);
        }
    }
}

1 个答案:

答案 0 :(得分:0)

  

每当我尝试运行应用程序时,都会弹出一条消息,说“生成并且不应编辑构建文件夹下的文件”。

我认为您正在调试/ DDMS模式中更改.class文件或类似的东西。请检查并确保编辑.java文件。

发布相关的logcat消息以及相关的XML文件可能有助于理解问题。