I am new on mobile development, so I decided to use Phonegap to develop my application. In my app I am using a SQLite plugin, because WebSQL is not attending my necessities. When I try to put one of the files required to use the plugin in my project, Eclipse return me errors in the following function:
public void processResults(Cursor cur, String query_id, String tx_id) {
String result = "[]";
// If query result has rows
if (cur.moveToFirst()) {
JSONArray fullresult = new JSONArray();
String key = "";
int colCount = cur.getColumnCount();
// Build up JSON result object for each row
do {
JSONObject row = new JSONObject();
try {
for (int i = 0; i < colCount; ++i) {
key = cur.getColumnName(i);
// for old Android SDK remove lines from HERE:
if(android.os.Build.VERSION.SDK_INT >= 11)
{
switch(cur.getType (i))
{
case Cursor.FIELD_TYPE_NULL:
row.put(key, null);
break;
case Cursor.FIELD_TYPE_INTEGER:
row.put(key, cur.getInt(i));
break;
case Cursor.FIELD_TYPE_FLOAT:
row.put(key, cur.getFloat(i));
break;
case Cursor.FIELD_TYPE_STRING:
row.put(key, cur.getString(i));
break;
case Cursor.FIELD_TYPE_BLOB:
row.put(key, cur.getBlob(i));
break;
}
}
else // to HERE.
{
row.put(key, cur.getString(i));
}
}
fullresult.put(row);
} catch (JSONException e) {
e.printStackTrace();
}
} while (cur.moveToNext());
result = fullresult.toString();
}
if(query_id.length() > 0)
this.sendJavascript(" SQLitePluginTransaction.queryCompleteCallback('" + tx_id + "','" + query_id + "', " + result + ");");
}
In the line 20 (when we have “switch(cur.getType (i))”), Eclipse returns the following error:
The method getType(int) is undefined for the type Cursor
When I saw this, I tried googling it, and on the Android’s documentation says that getType is a Cursor’s method.
Here is what this file imports:
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import com.phonegap.api.Plugin;
import com.phonegap.api.PluginResult;
import android.database.Cursor;
import android.database.sqlite.*;
import android.util.Log;
As don’t know Java, I could not figure this out and I haven’t found anything on my search, but I may be missing something. I hope someone can help me, thanks
Which version of Android are you targeting? The getType method was added in API 11 (Honeycomb).
You can see this on the right hand side of the header as (‘Since: API Level 11’) and you may find the ‘Filter by API level’ box at the top of the reference pages useful.