13

遵循上一个问题的注释:Android Studio run configuration for ORMLite config generation

我能够让我的配置运行这一类,但它仍然失败

Could not find raw directory

这是我的来源

package com.ilopez.android.machinesounds;

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

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

/**
 * Created by User on 7/25/13.
 */
public class DatabaseConfigUtil extends OrmLiteConfigUtil {
    private static final Class<?>[] classes = new Class[]{
            RecordedSound.class,
    };


    public static void main(String[] args) throws IOException, SQLException {
        writeConfigFile(new File("G:\\MachineSoundsProject\\MachineSounds\\src\\main\\res\\raw\\ormlite_config.txt"), classes );
    }
}

我的平台是windows,我真的不知道为什么它总是因为“找不到原始目录”而失败。

这是我的 android studio 运行的命令:

 "C:\Program Files\Java\jdk1.6.0_37\bin\java" -Didea.launcher.port=7544 "-Didea.launcher.bin.path=C:\Program Files (x86)\Android\android-studio\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files (x86)\Android\android-studio\sdk\platforms\android-17\android.jar;C:\Program Files (x86)\Android\android-studio\sdk\platforms\android-17\data\res;C:\Program Files (x86)\Android\android-studio\sdk\tools\support\annotations.jar;C:\local\Dropbox\git\MachineSoundsProject\MachineSounds\build\classes\debug;C:\Program Files (x86)\Android\android-studio\sdk\extras\android\m2repository\com\android\support\support-v4\13.0.0\support-v4-13.0.0.jar;C:\local\Dropbox\git\MachineSoundsProject\MachineSounds\libs\ormlite-android-4.45.jar;C:\local\Dropbox\git\MachineSoundsProject\MachineSounds\libs\ormlite-core-4.45.jar;C:\local\Dropbox\git\MachineSoundsProject\MachineSounds\libs\ormlite-jdbc-4.45.jar;C:\Program Files (x86)\Android\android-studio\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain com.ilopez.android.machinesounds.DatabaseConfigUtil

我正在使用 ORMLite 4.45 版

4

10 回答 10

25

您可以毫无问题地使用 Android Studio,但请确保在编辑配置中选择标准 JDK 并(重要!)通过选择您的 android 项目的“主”文件夹来修改“工作目录”

它应该类似于:/your_workspace/your_project/app/src/main

于 2015-02-21T18:03:50.200 回答
13

如果您尝试在 Android Studio 中创建它,它会尝试在最顶层的目录中找到该文件夹​​(例如 .idea 的位置)因此,如果您创建一个目录 res 并在该原始目录中,则该 util 将能够创建该文件。

于 2013-10-08T18:12:59.703 回答
7
  1. 右键单击 DBConfigUtil 文件并运行 DBConfigUtil.main();
    1. 转到编辑配置部分。
    2. 确保你的工作目录是这样的:/home/xyz/projects/xyz_project/app/src/main
    3. 将 JRE 更改为 JDK1.8
    4. 在启动前部分中删除 Make。
    5. 好的

并再次运行 DBConfigUtil 文件。

注意:确保你有 res/raw/ormlite_config.txt 文件

于 2014-11-08T06:15:12.810 回答
2

我得到了同样的错误。我忘了添加“新文件()”结构。在我添加之后,它仍然给出了相同的信息。但是当我重建项目时,它突然开始工作了。

总结一下我所做的(MAC OSX 用户): - 确保您已将 ormlite-android 和 ormlite-core jar 文件添加到 libs 目录 - 右键单击​​以将它们添加为项目库 - 从 ormlite 指令中复制 OrmLiteConfigUtil 指令- 确保使用完整路径并使用 File 类 - 在 res 树中添加原始目录 - 添加一个空的 ormlite_config.txt - 创建构建配置

显然,您需要在每次更改后进行重建以使它们生效。

于 2013-08-20T11:42:35.513 回答
1

另一个糟糕的选择是,如果您的数据库非常简单,则手动创建 txt 文件。在这里,我将程序创建的文件保留在我过去的项目中,用作模板,用于在当前项目中手动创建另一个文件:

#
# generated on 2013/08/15 05:07:12
#
# --table-start--
dataClass=com.alvarosantisteban.pathos.Event
tableName=events
# --table-fields-start--
# --field-start--
fieldName=id
generatedId=true
useGetSet=true
# --field-end--
# --field-start--
fieldName=sequence
useGetSet=true
# --field-end--
# --field-start--
fieldName=name
canBeNull=false
useGetSet=true
# --field-end--
# --field-start--
fieldName=day
canBeNull=false
useGetSet=true
# --field-end--
# --field-start--
fieldName=hour
useGetSet=true
# --field-end--
# --field-start--
fieldName=description
useGetSet=true
# --field-end--
# --field-start--
fieldName=location
useGetSet=true
# --field-end--
# --field-start--
fieldName=links
columnName=links
dataPersister=SERIALIZABLE
useGetSet=true
# --field-end--
# --field-start--
fieldName=isInteresting
useGetSet=true
# --field-end--
# --field-start--
fieldName=isDescriptionInGerman
useGetSet=true
# --field-end--
# --field-start--
fieldName=eventsOrigin
useGetSet=true
# --field-end--
# --field-start--
fieldName=originsWebsite
useGetSet=true
# --field-end--
# --field-start--
fieldName=themaTag
useGetSet=true
# --field-end--
# --field-start--
fieldName=typeTag
useGetSet=true
# --field-end--
# --table-fields-end--
# --table-end--
#################################

正如我所说,这只是一个糟糕的解决方法,但它可能会对某人有所帮助。:/

于 2014-06-05T12:54:13.540 回答
1

我不确定这是否对 Windows 有帮助,但在我放回运行配置部分之前,我无法让它在 Mac 上的 Android Studio 中Make工作Before Launch。可能值得一试,以避免在 Android Studio 和 NetBeans 之间切换的烦恼!

于 2013-08-14T05:30:50.143 回答
1

如果您尚未在 res 文件夹中创建 raw 文件夹,则会收到此错误。只需在 res 文件夹中手动创建原始文件夹并尝试。这发生在 MAC 的 Eclipse IDE 中。

于 2013-07-28T15:58:39.860 回答
1

由于我必须从上述所有答案中收集和撰写正确答案,我在这里给你我的完整解决方案:

  1. 将您的配置文件(例如“OrmliteDatabaseConfigUtil”)放在您的 Android 项目根包下-->app->src->java->com.your_package

  2. 确保您拥有文件所需的所有导入。

  3. 添加“原始”目录和“ormlite_config.txt”

  4. 如果您使用“使用表配置文件”的 ormLite 指南

    字符串 configPath = "\res\raw\ormlite_config.txt";

  5. 设置好之后,进入你的配置文件,然后右键单击“run...main()”,如果第一次运行不起作用,转到工作室工具栏中的运行部分,单击小箭头并单击'编辑配置”。确保以下内容:

一个。主类 - 具有完整的包名,它应该自动建议您的类名。

湾。工作目录 - C:\Users\...\app\src\main

c.使用模块的classpth:app

d.JRE:默认

e. 你可以离开'make; 单独 - 它应该在那里

F。就是这样,它现在应该可以工作了。

于 2016-10-15T20:43:26.673 回答
1

Android 的更好选择:给出写入文件的绝对路径。

// Following code goes in your database configuration main method.
String ORMLITE_CONFIGURATION_FILE_NAME = "ormlite_config.txt";

/**
 * Full configuration path includes the project root path, and the location
 * of the ormlite_config.txt file appended to it.
 */
File configFile = new File(new File("").getAbsolutePath()
        .split("app" +File.separator + "build")[0] + File.separator +
        "app" + File.separator +
        "src" + File.separator +
        "main" + File.separator +
        "res" + File.separator +
        "raw" + File.separator +
        ORMLITE_CONFIGURATION_FILE_NAME);

/**
 * Pass configFile as argument in configuration file writer method.
 */
writeConfigFile(configFile);
于 2016-03-01T10:44:56.577 回答
0

我找到了一个不错的解决方案。使用单独的 IDE(不是 Android Studio)来创建您的配置文件。在我的例子中,我使用了 NetBeans IDE 7.3.1,它工作得很好。

run:
Writing configurations to G:\MachineSoundsProject\MachineSounds\src\main\res\raw\ormlite_config.txt
Wrote config for class machinesoundandroidorm.RecordedSound
Done.
BUILD SUCCESSFUL (total time: 0 seconds)
于 2013-07-28T15:53:35.100 回答