我在android中使用activeandroid库的每个人都避免执行sql编码,但是由于某些原因它不起作用
这是我的代码:
这是我的清单:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

<application
    android:name=".MyApplication"
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme">

    <meta-data
        android:name="AA_DB_Name"
        android:value="knownFiles2.db"/>

    <meta-data
        android:name="AA_DB_Version"
        android:value="5"/>

    <activity
        android:name=".MainActivity"
        android:label="@string/app_name" >



        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

这是myapplication类
    public class MyApplication extends Application {
@Override
public void onCreate() {
    super.onCreate();

    ActiveAndroid.initialize(this);
}

}
这是文件夹模型
    @Table(name="Folders")
public class Folder extends Model implements Serializable{
@Column(name="Path")
public String path;

@Column(name = "ShowAllImages")
public String showAllImages;

Folder() {
    super();
}

Folder(String path, String showAllImages) {
    super();

    this.path = path;

    this.showAllImages = showAllImages;
}

@Override
public String toString() {
    return "Path: "+path+
            " ShowAllImages "+showAllImages;
}

}
这是服务器模型
    @Table(name = "Servers")
    public class Server extends Model implements Serializable{

@Column(name = "Ip")
String ip;

@Column(name = "Folder")
Folder folder;

Server() {
    super();
}

Server(String ip, Folder folder) {
    super();
    this.ip = ip;

    this.folder = folder;
}

@Override
public String toString() {

    return "Ip: "+ip+" Folder: "+folder.toString();
}

public List<Server> getServer() {
    return getMany(Server.class, "Ip");
}

}
这就是我想用的代码:
       Folder folder = new Folder("private/secret/","show-all-images.php");

                folder.save();

                Server server = new Server("192.168.1.191",
                        folder);
                server.save();

                Log.v("MyTag",server.getId()+"");

                Log.v("MyTag",server.toString());

                Log.v("MyTag","Added");

                ArrayList<Server> data = new Select()
                        .all()
                        .from(Server.class)
                        .execute();

                Log.v("MyTag", data.size()+"");
                for (Server serverLoop:data) {
                    Log.v("MyTag", serverLoop.toString());
                }

日志应该返回数据库中的所有元素,但它没有返回,因为它说携带数据的arraylist的大小是0
这是日志:
04-09 22:59:30.824 27608-27608/com.example.mariomarhundabeltran.photokeeper v/mytag:5
04-09 22:59:30.824 27608-27608/com.example.mariomarhundabeltran.photokeeper v/mytag:IP:192.168.1.191文件夹:路径:private/secret/show all images show-all-images.php
04-09 22:59:30.824 27608-27608/com.example.mariomarhundabeltran.photokeeper v/mytag:已添加
04-09 22:59:30.824 27608-27608/com.example.mariomarhundabeltran.photokeeper v/mytag:0
如您所见,添加成功,但列表为空。5表示刚刚添加的元素是数据库中的第五个元素
救命啊!啊!
提前谢谢

最佳答案

你还需要在manifest中定义你的模型,
在清单中添加:

<meta-data
    android:name="AA_DB_Name"
    android:value="knownFiles2.db"/>

<meta-data
    android:name="AA_DB_Version"
    android:value="5"/>

<meta-data
        android:name="AA_MODELS"
        android:value=".YourModel1, .YourModel2" />

我希望这会有帮助。
你代码的其他部分在我看来很好

关于java - 使用 Activity Android在SQL上保存实际上没有保存,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29549355/

10-10 09:58