java - Saving on sql using active android not actually saving -
everyone i've using activeandroid library in android avoid doing sql coding reason isn0t working
here code:
this manifest:
<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>
this myapplication class
public class myapplication extends application { @override public void oncreate() { super.oncreate(); activeandroid.initialize(this); }
}
this folders model
@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; }
}
this servers model
@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"); }
}
and code i'm trying working:
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()+""); (server serverloop:data) { log.v("mytag", serverloop.tostring()); }
the log should return elements in database, doesn't because says size of arraylist carrying data 0
here log: 04-09 22:59:30.824 27608- 27608/com.example.mariomarhuendabeltran.photokeeper v/mytag﹕ 5 04-09 22:59:30.824 27608-27608/com.example.mariomarhuendabeltran.photokeeper v/mytag﹕ ip: 192.168.1.191 folder: path: private/secret/ showallimages show-all-images.php 04-09 22:59:30.824 27608-27608/com.example.mariomarhuendabeltran.photokeeper v/mytag﹕ added 04-09 22:59:30.824 27608-27608/com.example.mariomarhuendabeltran.photokeeper v/mytag﹕ 0
as can see adding successful, list empty. 5 reveals element added fifth in database
help please!! in advance
you need define models in manifest well,
in manifest add this:
<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" />
i hope helps. other parts of code seems fine me