Android 未添加Ormlite DatabaseConfigUtil.java生成原始空文件和数据库字段

Android 未添加Ormlite DatabaseConfigUtil.java生成原始空文件和数据库字段,android,android-sqlite,ormlite,sqlite,Android,Android Sqlite,Ormlite,Sqlite,我正在Win7平台上使用EclipseHelios。 我有这个刀课 package com.example.hello; import com.j256.ormlite.field.DatabaseField; import com.j256.ormlite.table.DatabaseTable; @DatabaseTable(tableName = "accounts") public class Account { // for QueryBuilder to be

我正在Win7平台上使用EclipseHelios。 我有这个刀课

package com.example.hello;

import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;

@DatabaseTable(tableName = "accounts")
public class Account {

        // for QueryBuilder to be able to find the fields
        public static final String NAME_FIELD_NAME = "name";
        public static final String PASSWORD_FIELD_NAME = "passwd";

        @DatabaseField(generatedId = true)
        private int id;

        @DatabaseField(columnName = NAME_FIELD_NAME, canBeNull = false)
        private String name;

        @DatabaseField(columnName = PASSWORD_FIELD_NAME)
        private String password;

        Account() {
                // all persisted classes must define a no-arg constructor with at least package visibility
        }

        public Account(String name) {
                this.name = name;
        }

        public Account(String name, String password) {
                this.name = name;
                this.password = password;
        }

        public int getId() {
                return id;
        }

        public String getName() {
                return name;
        }

        public void setName(String name) {
                this.name = name;
        }

        public String getPassword() {
                return password;
        }

        public void setPassword(String password) {
                this.password = password;
        }

        @Override
        public int hashCode() {
                return name.hashCode();
        }

        @Override
        public boolean equals(Object other) {
                if (other == null || other.getClass() != getClass()) {
                        return false;
                }
                return name.equals(((Account) other).name);
        }
}
我的数据库configutil如下所示

package com.example.hello;

import java.io.IOException;
import java.sql.SQLException;

import com.j256.ormlite.android.apptools.OrmLiteConfigUtil;

/**
 * Database helper class used to manage the creation and upgrading of your database. This class also usually provides
 * the DAOs used by the other classes.
 */
public class DatabaseConfigUtil extends OrmLiteConfigUtil {

    public static void main(String[] args) throws SQLException, IOException {
        writeConfigFile("ormlite_config.txt");
    }
}
我的问题是,如果我试图生成它在res/raw文件夹中成功生成的原始数据库配置文件,但除了

#
# generated on 2013/06/26 05:18:40
#

为什么我的数据库字段不是在此自动生成的?

根据以下文档:

在当前目录或其下查找带注释的类,然后 将配置文件写入原始文件夹中的文件名

假设您的类和
DatabaseConfigUtil
位于同一目录/包中,它应该可以工作。正如你所说的,事实并非如此

我不知道为什么你的
res/raw/ormlite_config.txt
是空的,但我有一个建议,可以用另一个解决方案来修复。我是这样做的(版本4.45):

公共类数据库ConfigUtil扩展了OrmLiteConfigUtil{
//我们不能使用Android的Log类,因为这是一个独立的命令行应用程序。
私有静态最终记录器Logger=Logger.getLogger(DatabaseConfigUtil.class.getName());
/**
*生成的ORMLite配置文件的名称。
*/
公共静态最终字符串配置文件\u NAME=“ormlite\u CONFIG.txt”;
/**
*将存储在本地数据库中的类es数组。
*/
公共静态最终类[]类=新类[]{
警报类,
助手类
};
/**
*创建新模型类时需要执行的主方法
*介绍了代码库。
*
*@param args命令行参数(已忽略)。
*
*@在配置文件无法写入'res/raw/'时引发IOException。
*@在“CLASSES”中的某个类包含无效内容时引发SQLException
*SQL注释。
*/
公共静态void main(字符串[]args)引发IOException、SQLException{
File rawFolder=新文件(“res/raw”);
//检查“res/raw”是否存在。。。
如果(!rawFolder.exists()){
//…如果不是,就创建它。
布尔值rawCreated=rawFolder.mkdirs();
如果(!已创建){
logger.warning(“无法在'res/'内创建'raw'文件夹)”+
“来自DatabaseConfigUtil:未创建数据库配置文件!”);
系统出口(1);
}
否则{
info(“创建的文件夹`res/raw/`”);
}
}
writeConfigFile(配置文件名、类);
}
}

根据以下文件:

在当前目录或其下查找带注释的类,然后 将配置文件写入原始文件夹中的文件名

假设您的类和
DatabaseConfigUtil
位于同一目录/包中,它应该可以工作。正如你所说的,事实并非如此

我不知道为什么你的
res/raw/ormlite_config.txt
是空的,但我有一个建议,可以用另一个解决方案来修复。我是这样做的(版本4.45):

公共类数据库ConfigUtil扩展了OrmLiteConfigUtil{
//我们不能使用Android的Log类,因为这是一个独立的命令行应用程序。
私有静态最终记录器Logger=Logger.getLogger(DatabaseConfigUtil.class.getName());
/**
*生成的ORMLite配置文件的名称。
*/
公共静态最终字符串配置文件\u NAME=“ormlite\u CONFIG.txt”;
/**
*将存储在本地数据库中的类es数组。
*/
公共静态最终类[]类=新类[]{
警报类,
助手类
};
/**
*创建新模型类时需要执行的主方法
*介绍了代码库。
*
*@param args命令行参数(已忽略)。
*
*@在配置文件无法写入'res/raw/'时引发IOException。
*@在“CLASSES”中的某个类包含无效内容时引发SQLException
*SQL注释。
*/
公共静态void main(字符串[]args)引发IOException、SQLException{
File rawFolder=新文件(“res/raw”);
//检查“res/raw”是否存在。。。
如果(!rawFolder.exists()){
//…如果不是,就创建它。
布尔值rawCreated=rawFolder.mkdirs();
如果(!已创建){
logger.warning(“无法在'res/'内创建'raw'文件夹)”+
“来自DatabaseConfigUtil:未创建数据库配置文件!”);
系统出口(1);
}
否则{
info(“创建的文件夹`res/raw/`”);
}
}
writeConfigFile(配置文件名、类);
}
}
public class DatabaseConfigUtil extends OrmLiteConfigUtil {

    // The logger. We cannot use Android's Log class since this is a standalone command line app.
    private static final Logger logger = Logger.getLogger(DatabaseConfigUtil.class.getName());

    /**
     * The name of the generated ORMLite config file.
     */
    public static final String CONFIG_FILE_NAME = "ormlite_config.txt";

    /**
     * An array of Class-es which will be stored in the local DB.
     */
    public static final Class<?>[] CLASSES = new Class[]{
            Alarm.class,
            Helper.class
    };

    /**
     * A main method that needs to be executed when a new model class is
     * introduced to the code base.
     *
     * @param args command line parameters (which are ignored).
     *
     * @throws IOException  when the config file cannot be written to `res/raw/`.
     * @throws SQLException when one of the Class-es in `CLASSES` contains invalid
     *                      SQL annotations.
     */
    public static void main(String[] args) throws IOException, SQLException {

        File rawFolder = new File("res/raw");

        // Check is `res/raw` exists ...
        if(!rawFolder.exists()) {

            // ... if not create it.
            boolean rawCreated = rawFolder.mkdirs();

            if(!rawCreated) {
                logger.warning("could not create a 'raw' folder inside 'res/'" +
                        " from DatabaseConfigUtil: no DB-config file created!");
                System.exit(1);
            }
            else {
                logger.info("created folder `res/raw/`");
            }
        }

        writeConfigFile(CONFIG_FILE_NAME, CLASSES);
    }
}