Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
737 views
in Technique[技术] by (71.8m points)

database - compilation of Ormliteconfig file in Android studio

Can anyone guide me how to compile OrmLiteConfigUtil file in AndroidStudio i'm new to both ormlite and Android Studio.Thanks I checked the below link.but it is still giving the ClassnotFoundException.

Checked this but it is still giving the exception

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The pdf doc of ormLite said:

You will need to run this utility locally on your development box (not in an Android device), whenever you make a change to one of your data classes. This means that right now, this must be done by hand to keep the configuration file in sync with your database classes. To run the utility you will need to use the local Java runtime environment (JRE).

Under AndroidStudio, go to "Run" menu, and select "Edit Configurations...", this will make appear an dialog, click on the green button with the plus sign to add a new Run configuration (should be in the left-top corner of the dialog), in the contextual menu you should select "Application".

Next, click on "Main class" input and select your OrmLiteConfigUtil class. In the working directory input you should select the folder where the "res" android file is placed (in the android studio file structure you should have somthing as ".../app/src/main"). Also, select the checkbox "Use alternative JRE" and select a JRE path of a Java Runtime (for me java 7 of oracle works).

finally, click on "Ok" button to save the changes, and it's ready.

create a "raw" directory in your "res" android folder, do this before of run the config.

To run the new config: right click on the file class (your OrmLiteConfigUtil extended class, the same file that you select in the "Main class" input) and select Run '...'. wait for compiler and that is all!, you should see an config file in your res/raw folder

this is some of code for my OrmLiteConfigUtil extended class:

public class DatabaseConfigUtil extends OrmLiteConfigUtil {

    // put all your database classes in this array
    private static final Class<?>[] clases = new Class[]{Vendor.class};

    public static void main(String[] args) throws SQLException, IOException {
        writeConfigFile("ormlite_config.txt", clases);
    }
}

A screenshot of my configuration runner:

A screenshot of my configuration runner


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...