FC when looking for record in SQLite - android

I have several methods for getting a record in my app
But for some reason this one keeps giving me FC !
I'm using the following method to get the Cursor :
Cursor c=helper.getRecordById(num);
Which is implemented as follows :
public Cursor getRecordById(int rowId) {
String rowIDs=""+rowId;
String SelectById = "SELECT id, OrderName, OrderLink, DateYear, DateMonth, DateDay, OrderPrice FROM Orders WHERE id=?";
String[] args={rowIDs};
return(getReadableDatabase().rawQuery(SelectById, args));
}
I have tried also without converting the Int to String but i just left it this way.. get the same error for both ways.
Whenever i get to the following line :
String name=c.getString(c.getColumnIndexOrThrow("OrderName"));
I get the FC.
The GetColumnIndex works just fine... i've tested it exclusively.
But the getString throws the error. :
06-02 21:07:13.656: W/KeyCharacterMap(4329): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
06-02 21:07:16.006: D/AndroidRuntime(4329): Shutting down VM
06-02 21:07:16.006: W/dalvikvm(4329): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
06-02 21:07:16.026: E/AndroidRuntime(4329): FATAL EXCEPTION: main
06-02 21:07:16.026: E/AndroidRuntime(4329): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.Sagi.MyOrders/com.Sagi.MyOrders.DisplayRecord}: android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 0
06-02 21:07:16.026: E/AndroidRuntime(4329): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
06-02 21:07:16.026: E/AndroidRuntime(4329): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
06-02 21:07:16.026: E/AndroidRuntime(4329): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
06-02 21:07:16.026: E/AndroidRuntime(4329): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
06-02 21:07:16.026: E/AndroidRuntime(4329): at android.os.Handler.dispatchMessage(Handler.java:99)
06-02 21:07:16.026: E/AndroidRuntime(4329): at android.os.Looper.loop(Looper.java:123)
06-02 21:07:16.026: E/AndroidRuntime(4329): at android.app.ActivityThread.main(ActivityThread.java:4627)
06-02 21:07:16.026: E/AndroidRuntime(4329): at java.lang.reflect.Method.invokeNative(Native Method)
06-02 21:07:16.026: E/AndroidRuntime(4329): at java.lang.reflect.Method.invoke(Method.java:521)
06-02 21:07:16.026: E/AndroidRuntime(4329): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
06-02 21:07:16.026: E/AndroidRuntime(4329): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
06-02 21:07:16.026: E/AndroidRuntime(4329): at dalvik.system.NativeStart.main(Native Method)
06-02 21:07:16.026: E/AndroidRuntime(4329): Caused by: android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 0
06-02 21:07:16.026: E/AndroidRuntime(4329): at android.database.AbstractCursor.checkPosition(AbstractCursor.java:580)
06-02 21:07:16.026: E/AndroidRuntime(4329): at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:214)
06-02 21:07:16.026: E/AndroidRuntime(4329): at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:41)
06-02 21:07:16.026: E/AndroidRuntime(4329): at com.Sagi.MyOrders.DisplayRecord.onCreate(DisplayRecord.java:48)
06-02 21:07:16.026: E/AndroidRuntime(4329): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-02 21:07:16.026: E/AndroidRuntime(4329): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
06-02 21:07:16.026: E/AndroidRuntime(4329): ... 11 more
06-02 21:12:16.126: I/Process(4329): Sending signal. PID: 4329 SIG: 9
The funny thing is i copied the same exact Lookup method i used in another place which works just fine !, i even tried giving it a constant to look for which i know to exists just to check. but nothing. error over and over again !
Thanks !!!

A Cursor initially points to a record one before the start, to allow this kind of code:
final Cursor cursor = /* get cursor */;
while(cursor.moveToNext()) {
/* do something with cursor */
}
If you are only expecting one record, and you are sure there will be one record, then before accesing your Cursor do:
cursor.moveToNext();
or:
cursor.moveToFirst();

Related

AVD crashes saying 'Unfortunately, libcocos2dx has crashed'

I just loaded my app created by cocos2dx-3.10 and when I open with it an AVD (again I haven't done any modifications to the app) the app crashes and gives the error: Unfortunately, libcocos2dx has crashed.
here is what I get in my android Monitor:
03-05 18:34:56.668 1435-1435/? D/dalvikvm: Not late-enabling CheckJNI (already on)
03-05 18:34:56.989 1435-1435/com.trying.name E/Trace: error opening trace file: No such file or directory (2)
03-05 18:34:57.419 1435-1435/com.trying.name D/AndroidRuntime: Shutting down VM
03-05 18:34:57.419 1435-1435/com.trying.name W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0xb2f2b288)
03-05 18:34:57.518 1435-1435/com.trying.name E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.UnsatisfiedLinkError: Couldn't load cocos2dcpp: findLibrary returned null
at java.lang.Runtime.loadLibrary(Runtime.java:365)
at java.lang.System.loadLibrary(System.java:535)
at org.cocos2dx.lib.Cocos2dxActivity.onLoadNativeLibraries(Cocos2dxActivity.java:248)
at org.cocos2dx.lib.Cocos2dxActivity.onCreate(Cocos2dxActivity.java:263)
at android.app.Activity.performCreate(Activity.java:5008)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
at android.app.ActivityThread.access$600(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
03-05 18:35:11.559 1435-1435/? I/Process: Sending signal. PID: 1435 SIG: 9

Problems with executing a method with asynctask from the main activity

So, I have an app which uses the Viewpager and swiping. I got 3 fragments which contains a listview, and a custom adapter to set the rows.
In each fragment, I have a method to call the asynctask and fetch the JSON. I run this method in the onActivityCreated.
When I start the app, everything is working fine, the progressdialog shows, and all the list's are being set with the correct data.
The problem is that i want to be able to refresh all the lists when click the refresh-button in the actionbar (to check for new tweets).
The only way I've been able to use the refreshbutton is when I use the onOptionsItemSelected() in the MainActivity.
So I'm thinking, I can just call the methods who then again calls the asynctask.
case R.id.menu_refresh:
MSFTHost host = new MSFTHost();
host.getTweets();
...
But when I click the button, the whole thing force closes:
02-05 21:46:57.959: W/dalvikvm(15292): threadid=1: thread exiting with uncaught exception (group=0x40d5a930)02-05 21:46:58.045:
E/AndroidRuntime(15292): FATAL EXCEPTION: main
02-05 21:46:58.045: E/AndroidRuntime(15292): java.lang.NullPointerException
02-05 21:46:58.045: E/AndroidRuntime(15292): at com.sandan.HostingNorge.MSFTHost$DownloadWebPageTask.onPostExecute(MSFTHost.java:95)
02-05 21:46:58.045: E/AndroidRuntime(15292): at com.sandan.HostingNorge.MSFTHost$DownloadWebPageTask.onPostExecute(MSFTHost.java:1)
02-05 21:46:58.045: E/AndroidRuntime(15292): at android.os.AsyncTask.finish(AsyncTask.java:631)
02-05 21:46:58.045: E/AndroidRuntime(15292): at android.os.AsyncTask.access$600(AsyncTask.java:177)
02-05 21:46:58.045: E/AndroidRuntime(15292): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
02-05 21:46:58.045: E/AndroidRuntime(15292): at android.os.Handler.dispatchMessage(Handler.java:99)
02-05 21:46:58.045: E/AndroidRuntime(15292): at android.os.Looper.loop(Looper.java:137)
02-05 21:46:58.045: E/AndroidRuntime(15292): at android.app.ActivityThread.main(ActivityThread.java:5202)
02-05 21:46:58.045: E/AndroidRuntime(15292): at java.lang.reflect.Method.invokeNative(Native Method)
02-05 21:46:58.045: E/AndroidRuntime(15292): at java.lang.reflect.Method.invoke(Method.java:511)
02-05 21:46:58.045: E/AndroidRuntime(15292): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:799)
02-05 21:46:58.045: E/AndroidRuntime(15292): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:566)
02-05 21:46:58.045: E/AndroidRuntime(15292): at dalvik.system.NativeStart.main(Native Method)
the line 95 contains this:
listItems.add(new GetListItems(oneObject.getString("text"),oneObject.getString("created_at"),obj
.getString("profile_image_url"), obj
.getString("screen_name")));
I tried clearing listItems, but it didn't have any effect.
Any help please?
Edit:
If I was unclear, I want to get the JSON again and show in the list, just like on the first run.

runTime error in libGDX

in past i worked with my projects and everything was good. but recently, i have this errors:
06-02 04:52:27.954: W/dalvikvm(344): Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lcom/badlogic/gdx/backends/android/AndroidApplication;
06-02 04:52:27.954: W/dalvikvm(344): Class init failed in newInstance call (Lcom/Jumper/ProjectAndroidActivity;)
06-02 04:52:27.963: D/AndroidRuntime(344): Shutting down VM
06-02 04:52:27.963: W/dalvikvm(344): threadid=1: thread exiting with uncaught exception (group=0x40015560)
06-02 04:52:27.993: E/AndroidRuntime(344): FATAL EXCEPTION: main
06-02 04:52:27.993: E/AndroidRuntime(344): java.lang.ExceptionInInitializerError
06-02 04:52:27.993: E/AndroidRuntime(344): at java.lang.Class.newInstanceImpl(Native Method)
06-02 04:52:27.993: E/AndroidRuntime(344): at java.lang.Class.newInstance(Class.java:1409)
06-02 04:52:27.993: E/AndroidRuntime(344): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
06-02 04:52:27.993: E/AndroidRuntime(344): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)
06-02 04:52:27.993: E/AndroidRuntime(344): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
06-02 04:52:27.993: E/AndroidRuntime(344): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
06-02 04:52:27.993: E/AndroidRuntime(344): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
06-02 04:52:27.993: E/AndroidRuntime(344): at android.os.Handler.dispatchMessage(Handler.java:99)
06-02 04:52:27.993: E/AndroidRuntime(344): at android.os.Looper.loop(Looper.java:123)
06-02 04:52:27.993: E/AndroidRuntime(344): at android.app.ActivityThread.main(ActivityThread.java:3683)
06-02 04:52:27.993: E/AndroidRuntime(344): at java.lang.reflect.Method.invokeNative(Native Method)
06-02 04:52:27.993: E/AndroidRuntime(344): at java.lang.reflect.Method.invoke(Method.java:507)
06-02 04:52:27.993: E/AndroidRuntime(344): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
06-02 04:52:27.993: E/AndroidRuntime(344): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
06-02 04:52:27.993: E/AndroidRuntime(344): at dalvik.system.NativeStart.main(Native Method)
06-02 04:52:27.993: E/AndroidRuntime(344): Caused by: java.lang.UnsatisfiedLinkError: Couldn't load gdx: findLibrary returned null
06-02 04:52:27.993: E/AndroidRuntime(344): at java.lang.Runtime.loadLibrary(Runtime.java:429)
06-02 04:52:27.993: E/AndroidRuntime(344): at java.lang.System.loadLibrary(System.java:554)
06-02 04:52:27.993: E/AndroidRuntime(344): at com.badlogic.gdx.utils.GdxNativesLoader.load(GdxNativesLoader.java:116)
06-02 04:52:27.993: E/AndroidRuntime(344): at com.badlogic.gdx.backends.android.AndroidApplication.<clinit>(AndroidApplication.java:59)
06-02 04:52:27.993: E/AndroidRuntime(344): ... 15 more
i think this errors are from my libs. but i change them with new ones. is there any solution for it?
This error occurs when the armeabi and armeabi-v7a directories cannot be found. Copy both of these directories and their contents into the libs directory of your project.
It should look something like this:
you copied the wrong .so files in the folders. I assume you extracted them from gdx-natives.jar. Instead directly copy the armeabi and armeabi-v7a folders from the release/nightly. Make sure to use jars and natives only from a single release, do not mix jars and natives from multiple releases.
Alternatively use the gdx-setup-ui, as described here http://code.google.com/p/libgdx/wiki/ProjectSetupNew
I got that same error on my VM and other emulators, and found it was because they ran x86 O/S'es, which libgdx does not support.
If it doesn't work on the device either, try this:
android-project -> properties -> java Build Path -> Order and Export.
Click the project you've linked to (your plain java-project or desktop-project) and click the "Up"-button until it is at the very top. Make sure it's ticked [V].
I did that with the jars too, just in case, and now it runs on my device. I still get that same error on my x86 VM, because libgdx does not support x86 Android devices.

assetmanager has been finalized?

I'm getting that exception when I pick a wallpaper. I'm actually not sure what function is the culprit. Here's the error log:
I/ActivityManager( 1360): Starting activity: Intent { cmp=com.android.wallpaper.livepicker/.LiveWallpaperPreview (has extras) }
W/dalvikvm(29175): threadid=1: thread exiting with uncaught exception (group=0x40020ac0)
E/AndroidRuntime(29175): FATAL EXCEPTION: main
E/AndroidRuntime(29175): java.lang.IllegalStateException: AssetManager has been finalized!
E/AndroidRuntime(29175): at android.content.res.AssetManager.isUpToDate(Native Method)
E/AndroidRuntime(29175): at android.app.ActivityThread.getPackageInfo(ActivityThread.java:2350)
E/AndroidRuntime(29175): at android.app.ActivityThread.getPackageInfoNoCheck(ActivityThread.java:2337)
E/AndroidRuntime(29175): at android.app.ActivityThread.handleCreateService(ActivityThread.java:2935)
E/AndroidRuntime(29175): at android.app.ActivityThread.access$3300(ActivityThread.java:125)
E/AndroidRuntime(29175): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2087)
E/AndroidRuntime(29175): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(29175): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime(29175): at android.app.ActivityThread.main(ActivityThread.java:4627)
E/AndroidRuntime(29175): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(29175): at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime(29175): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878)
E/AndroidRuntime(29175): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)
E/AndroidRuntime(29175): at dalvik.system.NativeStart.main(Native Method)
I/ActivityManager( 1360): Displayed activity com.android.wallpaper.livepicker/.LiveWallpaperPreview: 331 ms (total 331 ms)
W/InputManagerService( 1360): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy#44bf5a08
I/ActivityManager( 1360): Process com.bukabros.videolivewallpaper (pid 29175) has died.
W/ActivityManager( 1360): Scheduling restart of crashed service com.bukabros.videolivewallpaper/.VideoLiveWallpaper in 5000ms
I/ActivityManager( 1360): Start proc com.bukabros.videolivewallpaper for service com.bukabros.videolivewallpaper/.VideoLiveWallpaper: pid=29207 uid=10090 gids={}
The only thing I can think of is that onCreate doesn't get called in the right order when the wallpaper gets picked cuz that's where I instantiate the asset manager.
And yes, I'm using the NDK but the asset manager doesn't get used there.
Ah nevermind. The culprit was that the handle to the assetmanager was a static variable. (That was just a quick hack for something else). Making that a normal variable solved the problem.

Android browsable intent fails on gmail links, but works with default mail client

I have set up intent filters to handle certain email links with my app. This works well in Android's basic mail program. I click the link, I am prompted whether to open it using the browser or my app, and after selecting my app it is handled correctly. The same is not true for using the Gmail app. How can I be sure to handle this app correctly as well? The intent filter seems to work - I am prompted for the browser or my app, however upon selecting my app, it is forced to close. Here is the error from my logcat:
06-02 01:23:11.337: ERROR/AndroidRuntime(11145): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android/com.example.android.Example}: java.lang.NullPointerException
06-02 01:23:11.337: ERROR/AndroidRuntime(11145): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
06-02 01:23:11.337: ERROR/AndroidRuntime(11145): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
06-02 01:23:11.337: ERROR/AndroidRuntime(11145): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
06-02 01:23:11.337: ERROR/AndroidRuntime(11145): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
06-02 01:23:11.337: ERROR/AndroidRuntime(11145): at android.os.Handler.dispatchMessage(Handler.java:99)
06-02 01:23:11.337: ERROR/AndroidRuntime(11145): at android.os.Looper.loop(Looper.java:123)
06-02 01:23:11.337: ERROR/AndroidRuntime(11145): at android.app.ActivityThread.main(ActivityThread.java:4627)
06-02 01:23:11.337: ERROR/AndroidRuntime(11145): at java.lang.reflect.Method.invokeNative(Native Method)
06-02 01:23:11.337: ERROR/AndroidRuntime(11145): at java.lang.reflect.Method.invoke(Method.java:521)
06-02 01:23:11.337: ERROR/AndroidRuntime(11145): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
06-02 01:23:11.337: ERROR/AndroidRuntime(11145): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
06-02 01:23:11.337: ERROR/AndroidRuntime(11145): at dalvik.system.NativeStart.main(Native Method)
06-02 01:23:11.337: ERROR/AndroidRuntime(11145): Caused by: java.lang.NullPointerException
06-02 01:23:11.337: ERROR/AndroidRuntime(11145): at com.example.android.Example.onCreate(Example.java:301)
06-02 01:23:11.337: ERROR/AndroidRuntime(11145): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-02 01:23:11.337: ERROR/AndroidRuntime(11145): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
06-02 01:23:11.337: ERROR/AndroidRuntime(11145): ... 11 more
Also, here is my code for handling the incoming intent in onCreate:
if (getIntent().getCategories().contains("android.intent.category.BROWSABLE")){
try{
Uri uri = getIntent().getData();
String url = uri.getFragment();
//parse url and handle its contents
}catch(Exception e){
Toast.makeText(this, "could not open url", Toast.LENGTH_LONG).show();
}
}
Any help would be much appreciated!
getIntent().getCategories() will return null if there are no categories. To fix the problem, I changed this if statement to:
if (getIntent().getAction().equals("android.intent.action.VIEW")){...}

Categories

Resources