I'm getting this "sqlite3_close(0x1f7f708) failed: 27" error sometimes and I can0t understand why. Here is my code:
xMessage[] msgs = new xMessage[howMany];
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor, cursorData = null;
cursor = db.query(mail_bridge_table_name, new String[] {mbfn_mbridge_PK, mbfn_mdata_FK, mbfn_contacts, mbfn_subject, mbfn_sentTime, mbfn_receivedTime, mbfn_maccount_FK }, null,
null, null, null, mbfn_sentTime + " desc", first + "," + howMany);
if (cursor != null)
cursor.moveToFirst();
else
{
msgs[0] = new xMessage();
msgs[0].set_bodyPlain("Mail data not found!");
return msgs;
}
long count = cursor.getCount();
for (int i = 0; i < count; i++)
{
[omissis: db unrelated code....]
cursorData = db.query(mail_data_table_name, new String[] {mdfn_mdata_PK, mdfn_header, mdfn_body }, mdfn_mdata_PK + "=?",
new String[]{cursor.getString(mbfi_mdata_FK)}, null, null, null, null);
if (cursorData != null)
{
cursorData.moveToFirst();
}
cursor.moveToNext();
}
if (cursor != null)
{
cursor.close();
}
if (cursorData != null)
{
cursorData.close();
}
db.close(); <----- here I get sometime the error
return msgs;
I have another thread working with the same database, but I get the error even stopping it. I had a look around and I have found on the forum that the failed: 27 lasts for a try to close a db with some action still open...but I just open two cursors that I close.
anyone can help? I'm stack on this problem since 2 days..
I think here is the answer. What does sqlite3_close failed 27 mean?. It is basically means there are statements have not called close().
Related
i'm new to android and java.
i made a cardview and populated it with a simple loop like so:
private ArrayList<DataObject> getTheData(){
ArrayList res = new ArrayList<DataObject>();
for (int index = 0; index < 5; index++){
DataObject obj = new DataObject("shit","happen");
res.add(index,obj);
}
return res;
}
it worked. now i created a database and want to populate it with this data. so i have this:
public ArrayList<DataObject> getData() {
SQLiteDatabase db = this.getReadableDatabase();
ArrayList res = null;
try {
res = new ArrayList<DataObject>();
String selectQuery = "SELECT * FROM quotes a LEFT JOIN authors b ON b.author_id=a.quote_author";
Cursor cursor = db.rawQuery(selectQuery, null);
if (cursor != null) {
if (cursor.moveToFirst()) {
do {
Log.d("CHECKDB",cursor.getString(cursor.getColumnIndex("first_name")) + " " + cursor.getString(cursor.getColumnIndex("last_name")));
Log.d("CHECKDB2",cursor.getString(cursor.getColumnIndex("quote_text")));
DataObject obj = new DataObject(
cursor.getString(cursor.getColumnIndex("first_name")) + " " + cursor.getString(cursor.getColumnIndex("last_name")),
cursor.getString(cursor.getColumnIndex("quote_text"))
);
res.add(obj);
} while (cursor.moveToNext());
}
}
} catch (SQLiteException se) {
Log.e(getClass().getSimpleName(), "Could not create or Open the database");
} finally {
if (db != null)
db.close();
}
return res;
}
the log show all the results, but when i run the app i get the last result the right amount of times. in this case 4 quotes in my database, so i see 4 but the last one 4 times.
please , since i'm new to it, good explanations will be appreciated.
the issue was that my dataobject attributes were set to static
I am trying to get the player's username and then display it.
Recently, there was a breaking changes; IResult replacement for FBResult.
I was able to return a texture from the IGraphResult instead of FBResult, to display the profile picture, so I expect that the Text would be available as well but no.
So my issue is, where can I return the Text from?
Do I have to add anything to the IGraphResult?
Here is the code,
void DealWithUserName(FBResult result)
{
if(result.Error != null)
{
Debug.Log ("Problems with getting profile picture");
FB.API ("/me?fields=id,first_name", HttpMethod.GET, DealWithUserName);
return;
}
profile = Util.DeserializeJSONProfile(result.Text);
Text UserMsg = UIFBUsername.GetComponent<Text>();
UserMsg.text = "Hello, " + profile["first_name"];
}
Edited:
Okay, I did it.
It seems that I can also get the username from the IGraphResult.
So, I changed the FBResult to IGraphResult.
I changed result.Text to result.RawResult.
Here is the code, for anyone who needs it.
void DealWithUserName(IGraphResult result)
{
if(result.Error != null)
{
Debug.Log ("Problems with getting profile picture");
FB.API ("/me?fields=id,first_name", HttpMethod.GET, DealWithUserName);
return;
}
profile = Util.DeserializeJSONProfile(result.RawResult);
Text UserMsg = UIFBUsername.GetComponent<Text>();
UserMsg.text = "Hello, " + profile["first_name"];
}
Let's try it
private void DealWithUserName(IGraphResult result){
if (result.ResultDictionary != null) {
foreach (string key in result.ResultDictionary.Keys) {
Debug.Log(key + " : " + result.ResultDictionary[key].ToString());
// first_name : Chris
// id : 12345678901234567
}
}
Text UserName = UIUserName.GetComponent<Text>();
UserName.text = "Hello, "+ result.ResultDictionary["name"].ToString();
}
I want to get followers Id's for a particular userId using java program. where I want to implement the cursor concept with rate limit set ... Can any one post me the code.
Use the following code snippet to get follower id. After getting the ids you use show user to get other details. Remember to use this code in background thread like in asynctask.
long[] tempids = null;
ConfigurationBuilder config =
new ConfigurationBuilder()
.setOAuthConsumerKey(custkey)
.setOAuthConsumerSecret(custsecret)
.setOAuthAccessToken(accesstoken)
.setOAuthAccessTokenSecret(accesssecret);
twitter1 = new TwitterFactory(config.build()).getInstance();
while(cursor != 0) {
try {
IDs temp = twitter1.friendsFollowers().getFollowersIDs("username", cursor);
cursor = temp.getNextCursor();
tempids = temp.getIDs();
} catch (twitter4j.TwitterException e) {
System.out.println("twitter: failed");
e.printStackTrace();
return null;
}
if(tempids != null) {
for (long id : tempids) {
ids.add(id);
System.out.println("followerID: " + id);
}
}
}
These are the ids in my table:
KEY_ID(autoincremented integer primary key) KEY_NAME(text) KEY_PH_NO(text)
1 james 1234567890
2 kristein 6484996755
3 Roen 4668798989
4 Ashlie 6897980909
What I want to know is, how can I get a single record from this table on the basis of unique(KEY_ID), for this i have built a getContact() method like this,
Contact getContact(int id) {
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(TABLE_CONTACTS, new String[] { KEY_ID,
KEY_NAME, KEY_PH_NO }, KEY_ID + "=?",
new String[] { String.valueOf(id) }, null, null, null, null);
if (cursor != null)
cursor.moveToFirst();
Contact contact = new Contact(Integer.parseInt(cursor.getString(0)),
cursor.getString(1), cursor.getString(2));
// return contact
return contact;
}
And Contact is a class where I have set all the getter and setter method for all attributes.
Please help with complete code.
See if this can help you out..
Assuming your table name is Employee
public String getEmployeeName(String empNo) {
Cursor cursor = null;
String empName = "";
try {
cursor = SQLiteDatabaseInstance_.rawQuery("SELECT EmployeeName FROM Employee WHERE EmpNo=?", new String[] {empNo + ""});
if(cursor.getCount() > 0) {
cursor.moveToFirst();
empName = cursor.getString(cursor.getColumnIndex("EmployeeName"));
}
return empName;
}finally {
cursor.close();
}
}
Contact getContact(int id) {
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(TABLE_CONTACTS, new String[] { KEY_ID,
KEY_NAME, KEY_PH_NO }, KEY_ID + "=?",
new String[] { String.valueOf(id) }, null, null, null, null);
if (cursor != null)
cursor.moveToFirst();
Contact contact = new Contact(Integer.parseInt(cursor.getString(0)),
cursor.getString(1), cursor.getString(2));
// return contact
return contact;
}
Assuming you have Entity Class for contact, And then you just call it your method above with this.
Contact singleContact = database.getContact(id);
then call contact entity, Im assuming you have method getter getPhone();
Log.d("Phone Number :" , singleContact.getPhone());
Try this
cursor.moveToPosition(position);
cursor.getString(listaTarefas1.getColumnIndex("Item"))
I'm using GWT-Strophe to connect to my XMPP server. Things are going well and I am able to connect to my XMPP server and send other users messages. I'm having a problem with receiving messages. I'm attempting to copy the Strophe echobot example, but the code in my Handler is not getting executed when a message is received.
Here is the code I am using to connect and register the handler:
connection = new Connection("http://localhost/proxy/");
handler = new Handler<Element>() {
#Override
public boolean handle(Element element) {
GWT.log("Handling...");
GWT.log(element.toString());
String to = element.getAttribute("to");
String from = element.getAttribute("from");
String type = element.getAttribute("type");
NodeList<com.google.gwt.dom.client.Element> elems = element.getElementsByTagName("body");
if ((type == null ? "chat" == null : type.equals("chat")) && elems.getLength() > 0) {
Element body = (Element) elems.getItem(0);
GWT.log("ECHOBOT: I got a message from " + from + ": " + body.getText());
String[][] attributes = {{"to", from}, {"from", to}, {"type", "chat"}};
Builder reply = Builder.$msg(attributes).cnode(body.copy());
connection.send(reply.tree());
GWT.log("ECHOBOT: I sent " + from + ": " + body.getText());
}
return true;
}
};
StatusCallback callback = new Connection.StatusCallback() {
#Override
public void statusChanged(Status status, String reason) {
if (status == Status.CONNECTING) {
GWT.log("Strophe is connecting.");
} else if (status == Status.CONNFAIL) {
GWT.log("Strophe failed to connect.");
} else if (status == Status.DISCONNECTING) {
GWT.log("Strophe is disconnecting.");
} else if (status == Status.DISCONNECTED) {
GWT.log("Strophe is disconnected.");
} else if (status == Status.CONNECTED) {
GWT.log("Strophe is connected.");
connection.addHandler(null, null, "message", null, null, handler);
Builder pres = Builder.$pres(null);
connection.send(pres);
GWT.log("ECHOBOT: Send a message to " + connection.getJid() + " to talk to me.");
}
}
};
connection.connect("me#myserver.com", "password", callback);
Change your line
connection.addHandler(null, null, "message", null, null, handler);
with
connection.addHandler(null, "message", null, null, null, handler);
and it should work fine.
Can you post here how you connected gwt-strophe (if you successfully connected)?
Or if you found better solution please post it here. I've made GWT compatible module from gwt-strophe(included gwt.xml and all sources) and used in my GWT project. During compilation there was no error but when i called my widget it says "Cannot read property 'Connection' of undefined". After some code inspection i didn't found where Strophe object is initialized
private native JavaScriptObject connection(String boshService) /*-{
var connection = new $wnd.Strophe.Connection(boshService);
return connection;
}-*/;
Error thrown during runtime execution because window.Strophe object is undefined
p.s. i haven't found here how to add comment so i've made "answer" to ask question in this thread...
All i need is connection from GWT to my openfire server