Upload Video with Android Intent Crashes - android

I have an app that creates a video in WebM format. I want to use an Android intent to send this video to Youtube, facebook, etc.
I have code that creates an intent and starts a chooser where I can pick where to upload to, after selecting the destination and filling in the form with title etc. I hit the Upload button and the app I am trying to upload with crashes immediately.
Here is my relevant code:
Uri videoURI = Uri.fromFile(new File( pathName + fileName));
Intent intent = new Intent(Intent.ACTION_SEND);
//intent.setAction(Intent.ACTION_SEND);
intent.setType("video/webm");
intent.putExtra(Intent.EXTRA_STREAM, videoURI);
try {
startActivity(Intent.createChooser(intent,"Upload video via:"));
} catch (android.content.ActivityNotFoundException ex) {
Log.e("MWR", "No Way to Share!");
}
pathName + fileName is the absolute path of the video on the SD card.
Here is the relevant log info for a Youtube Crash
11-02 13:42:43.949: WARN/dalvikvm(4443): threadid=10: thread exiting with uncaught exception (group=0x40018560)
11-02 13:42:43.949: ERROR/AndroidRuntime(4443): FATAL EXCEPTION: Thread-12
11-02 13:42:43.949: ERROR/AndroidRuntime(4443): java.lang.NullPointerException
11-02 13:42:43.949: ERROR/AndroidRuntime(4443): at java.util.Calendar.setTime(Calendar.java:1325)
11-02 13:42:43.949: ERROR/AndroidRuntime(4443): at java.text.SimpleDateFormat.formatImpl(SimpleDateFormat.java:536)
11-02 13:42:43.949: ERROR/AndroidRuntime(4443): at java.text.SimpleDateFormat.format(SimpleDateFormat.java:818)
11-02 13:42:43.949: ERROR/AndroidRuntime(4443): at java.text.DateFormat.format(DateFormat.java:376)
11-02 13:42:43.949: ERROR/AndroidRuntime(4443): at com.google.android.apps.uploader.clients.youtube.YouTubeSettingsActivity.a(SourceFile:183)
11-02 13:42:43.949: ERROR/AndroidRuntime(4443): at com.google.android.apps.uploader.clients.SettingsActivity.b(SourceFile:43)
11-02 13:42:43.949: ERROR/AndroidRuntime(4443): at com.google.android.apps.uploader.clients.j.run(SourceFile:348)
11-02 13:42:43.949: ERROR/AndroidRuntime(4443): at java.lang.Thread.run(Thread.java:1019)
11-02 13:42:43.956: WARN/ActivityManager(2494): Force finishing activity com.google.android.apps.uploader/.clients.youtube.YouTubeSettingsActivity
11-02 13:42:44.261: ERROR/WindowManager(4443): Activity com.google.android.apps.uploader.clients.youtube.YouTubeSettingsActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView#40553f20 that was originally added here
11-02 13:42:44.261: ERROR/WindowManager(4443): android.view.WindowLeaked: Activity com.google.android.apps.uploader.clients.youtube.YouTubeSettingsActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView#40553f20 that was originally added here
11-02 13:42:44.261: ERROR/WindowManager(4443): at android.view.ViewRoot.<init>(ViewRoot.java:258)
11-02 13:42:44.261: ERROR/WindowManager(4443): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
11-02 13:42:44.261: ERROR/WindowManager(4443): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
11-02 13:42:44.261: ERROR/WindowManager(4443): at android.view.Window$LocalWindowManager.addView(Window.java:424)
11-02 13:42:44.261: ERROR/WindowManager(4443): at android.app.Dialog.show(Dialog.java:241)
11-02 13:42:44.261: ERROR/WindowManager(4443): at com.google.android.apps.uploader.clients.SettingsActivity.b(SourceFile:43)
11-02 13:42:44.261: ERROR/WindowManager(4443): at com.google.android.apps.uploader.clients.c.onClick(SourceFile:122)
11-02 13:42:44.261: ERROR/WindowManager(4443): at android.view.View.performClick(View.java:2485)
11-02 13:42:44.261: ERROR/WindowManager(4443): at android.view.View$PerformClick.run(View.java:9089)
11-02 13:42:44.261: ERROR/WindowManager(4443): at android.os.Handler.handleCallback(Handler.java:587)
11-02 13:42:44.261: ERROR/WindowManager(4443): at android.os.Handler.dispatchMessage(Handler.java:92)
11-02 13:42:44.261: ERROR/WindowManager(4443): at android.os.Looper.loop(Looper.java:123)
11-02 13:42:44.261: ERROR/WindowManager(4443): at android.app.ActivityThread.main(ActivityThread.java:3806)
11-02 13:42:44.261: ERROR/WindowManager(4443): at java.lang.reflect.Method.invokeNative(Native Method)
11-02 13:42:44.261: ERROR/WindowManager(4443): at java.lang.reflect.Method.invoke(Method.java:507)
11-02 13:42:44.261: ERROR/WindowManager(4443): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
11-02 13:42:44.261: ERROR/WindowManager(4443): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
11-02 13:42:44.261: ERROR/WindowManager(4443): at dalvik.system.NativeStart.main(Native Method)
And here is the relevant log for a Facebook crash:
11-02 13:57:40.476: ERROR/AndroidRuntime(4497): FATAL EXCEPTION: main
11-02 13:57:40.476: ERROR/AndroidRuntime(4497): java.lang.RuntimeException: Unable to start service com.facebook.katana.service.FacebookService#4068d4f8 with Intent { cmp=com.facebook.katana/.service.FacebookService (has extras) }: java.lang.NullPointerException
11-02 13:57:40.476: ERROR/AndroidRuntime(4497): at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2128)
11-02 13:57:40.476: ERROR/AndroidRuntime(4497): at android.app.ActivityThread.access$2800(ActivityThread.java:124)
11-02 13:57:40.476: ERROR/AndroidRuntime(4497): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1031)
11-02 13:57:40.476: ERROR/AndroidRuntime(4497): at android.os.Handler.dispatchMessage(Handler.java:99)
11-02 13:57:40.476: ERROR/AndroidRuntime(4497): at android.os.Looper.loop(Looper.java:123)
11-02 13:57:40.476: ERROR/AndroidRuntime(4497): at android.app.ActivityThread.main(ActivityThread.java:3806)
11-02 13:57:40.476: ERROR/AndroidRuntime(4497): at java.lang.reflect.Method.invokeNative(Native Method)
11-02 13:57:40.476: ERROR/AndroidRuntime(4497): at java.lang.reflect.Method.invoke(Method.java:507)
11-02 13:57:40.476: ERROR/AndroidRuntime(4497): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
11-02 13:57:40.476: ERROR/AndroidRuntime(4497): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
11-02 13:57:40.476: ERROR/AndroidRuntime(4497): at dalvik.system.NativeStart.main(Native Method)
11-02 13:57:40.476: ERROR/AndroidRuntime(4497): Caused by: java.lang.NullPointerException
11-02 13:57:40.476: ERROR/AndroidRuntime(4497): at com.facebook.katana.service.method.VideoUpload.getRealPathFromURI(VideoUpload.java:127)
11-02 13:57:40.476: ERROR/AndroidRuntime(4497): at com.facebook.katana.service.method.VideoUpload.start(VideoUpload.java:148)
11-02 13:57:40.476: ERROR/AndroidRuntime(4497): at com.facebook.katana.service.FacebookService.startOp(FacebookService.java:1250)
11-02 13:57:40.476: ERROR/AndroidRuntime(4497): at com.facebook.katana.service.FacebookService.onStart(FacebookService.java:742)
11-02 13:57:40.476: ERROR/AndroidRuntime(4497): at android.app.Service.onStartCommand(Service.java:428)
11-02 13:57:40.476: ERROR/AndroidRuntime(4497): at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2115)
11-02 13:57:40.476: ERROR/AndroidRuntime(4497): ... 10 more
So, an update:
The URI was preventing it from starting the process.
I found another post on how to create a URI with ContentResolver and this fixed the issue.
However, it doesn't get past 0% and says my video is 0 Bytes but I believe this may be an issue with my video creation.

Related

Error Loading Static Fragment and a FrameLayout (

I'm trying to load layout with a static fragment and a LinearLayout using this Layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false"
android:divider="?android:attr/dividerHorizontal"
tools:context="com.eldad.yossi.popularmovs.MainActivity">
<fragment
android:id="#+id/main_fragment"
android:name="com.eldad.yossi.popularmovs.MainActivityFragment"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
tools:layout="#android:layout/list_content" />
<FrameLayout
android:id="#+id/movies_detail_container"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="4" />
</LinearLayout>
But when the app is launched I get this error:
11-02 23:02:36.418 13809-13880/com.eldad.yossi.popularmovs E/AndroidRuntime: FATAL EXCEPTION: ModernAsyncTask #2
11-02 23:02:36.418 13809-13880/com.eldad.yossi.popularmovs E/AndroidRuntime: Process: com.eldad.yossi.popularmovs, PID: 13809
11-02 23:02:36.418 13809-13880/com.eldad.yossi.popularmovs E/AndroidRuntime: java.lang.RuntimeException: An error occurred while executing doInBackground()
11-02 23:02:36.418 13809-13880/com.eldad.yossi.popularmovs E/AndroidRuntime: at android.support.v4.content.ModernAsyncTask$3.done(ModernAsyncTask.java:142)
11-02 23:02:36.418 13809-13880/com.eldad.yossi.popularmovs E/AndroidRuntime: at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
11-02 23:02:36.418 13809-13880/com.eldad.yossi.popularmovs E/AndroidRuntime: at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
11-02 23:02:36.418 13809-13880/com.eldad.yossi.popularmovs E/AndroidRuntime: at java.util.concurrent.FutureTask.run(FutureTask.java:242)
11-02 23:02:36.418 13809-13880/com.eldad.yossi.popularmovs E/AndroidRuntime: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
11-02 23:02:36.418 13809-13880/com.eldad.yossi.popularmovs E/AndroidRuntime: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
11-02 23:02:36.418 13809-13880/com.eldad.yossi.popularmovs E/AndroidRuntime: at java.lang.Thread.run(Thread.java:818)
11-02 23:02:36.418 13809-13880/com.eldad.yossi.popularmovs E/AndroidRuntime: Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.net.Uri.getScheme()' on a null object reference
11-02 23:02:36.418 13809-13880/com.eldad.yossi.popularmovs E/AndroidRuntime: at android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:1437)
11-02 23:02:36.418 13809-13880/com.eldad.yossi.popularmovs E/AndroidRuntime: at android.content.ContentResolver.query(ContentResolver.java:462)
11-02 23:02:36.418 13809-13880/com.eldad.yossi.popularmovs E/AndroidRuntime: at android.support.v4.content.ContentResolverCompatJellybean.query(ContentResolverCompatJellybean.java:29)
11-02 23:02:36.418 13809-13880/com.eldad.yossi.popularmovs E/AndroidRuntime: at android.support.v4.content.ContentResolverCompat$ContentResolverCompatImplJB.query(ContentResolverCompat.java:57)
11-02 23:02:36.418 13809-13880/com.eldad.yossi.popularmovs E/AndroidRuntime: at android.support.v4.content.ContentResolverCompat.query(ContentResolverCompat.java:125)
11-02 23:02:36.418 13809-13880/com.eldad.yossi.popularmovs E/AndroidRuntime: at android.support.v4.content.CursorLoader.loadInBackground(CursorLoader.java:59)
11-02 23:02:36.418 13809-13880/com.eldad.yossi.popularmovs E/AndroidRuntime: at android.support.v4.content.CursorLoader.loadInBackground(CursorLoader.java:37)
11-02 23:02:36.418 13809-13880/com.eldad.yossi.popularmovs E/AndroidRuntime: at android.support.v4.content.AsyncTaskLoader.onLoadInBackground(AsyncTaskLoader.java:296)
11-02 23:02:36.418 13809-13880/com.eldad.yossi.popularmovs E/AndroidRuntime: at android.support.v4.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:54)
11-02 23:02:36.418 13809-13880/com.eldad.yossi.popularmovs E/AndroidRuntime: at android.support.v4.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:42)
11-02 23:02:36.418 13809-13880/com.eldad.yossi.popularmovs E/AndroidRuntime: at android.support.v4.content.ModernAsyncTask$2.call(ModernAsyncTask.java:128)
11-02 23:02:36.418 13809-13880/com.eldad.yossi.popularmovs E/AndroidRuntime: at java.util.concurrent.FutureTask.run(FutureTask.java:237)
11-02 23:02:36.418 13809-13880/com.eldad.yossi.popularmovs E/AndroidRuntime: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 
11-02 23:02:36.418 13809-13880/com.eldad.yossi.popularmovs E/AndroidRuntime: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 
11-02 23:02:36.418 13809-13880/com.eldad.yossi.popularmovs E/AndroidRuntime: at java.lang.Thread.run(Thread.java:818) 
The same Activity and fragments work when I'm loading them using a layout that contain only the fragment.
any ideas?
The full code is in a GitHub repo - https://github.com/yossildad/PopularMovs
Thanks.
From the stack trace I could see you are trying to get an URI from a null reference in the doInBackground() method in activity com.eldad.yossi.popularmovs.MainActivity .
Ok, I've found the bug. I was using a not initialized uri when creating the Loader
inside the fragment.
Thanks for your help and sorry for the trouble.
Your problem is not in the fragment declaration. According to the stacktrace, look into the doInBackground method of your ModernASyncTask which you are extends on.
java.lang.RuntimeException: An error occurred while executing doInBackground() - probably you may have null reference on a context object, i guess.

After opening PDF with intent, app crashes with NullPointerException

I have a app that shows a ListView with several documents (DOC, PDF, PPT...). Selection one of them, I use the following code to show the document:
Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
String extension = android.webkit.MimeTypeMap.getFileExtensionFromUrl(Uri.fromFile(outFile).toString());
String mimetype = android.webkit.MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
if (extension.equalsIgnoreCase("") || mimetype == null) {
intent.setDataAndType(Uri.fromFile(outFile), "text/*");
} else {
intent.setDataAndType(Uri.fromFile(outFile), mimetype);
}
startActivity(Intent.createChooser(intent, "Choose an Application:"));
That works fine for the the first document selected, Polaris Office opens and show the document - fine. When switching back for selecting the next document, my application is not on the last screen shown, instead it starts again. Selecting the document works and open fine in Polaris. When now switching back, the app crashes with Unable to start activity ...MainActivity ... NullPointerExpetion.
What can I do to solve this problem?
Here the LogCat:
10-25 10:07:43.476: D/AndroidRuntime(8396): Shutting down VM
10-25 10:07:43.476: W/dalvikvm(8396): threadid=1: thread exiting with uncaught exception (group=0x415092a0)
10-25 10:07:43.507: E/AndroidRuntime(8396): FATAL EXCEPTION: main
10-25 10:07:43.507: E/AndroidRuntime(8396): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.astrex.ppastrex/com.astrex.ppastrex.MainActivity}: java.lang.NullPointerException
10-25 10:07:43.507: E/AndroidRuntime(8396): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
10-25 10:07:43.507: E/AndroidRuntime(8396): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2122)
10-25 10:07:43.507: E/AndroidRuntime(8396): at android.app.ActivityThread.access$600(ActivityThread.java:140)
10-25 10:07:43.507: E/AndroidRuntime(8396): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1228)
10-25 10:07:43.507: E/AndroidRuntime(8396): at android.os.Handler.dispatchMessage(Handler.java:99)
10-25 10:07:43.507: E/AndroidRuntime(8396): at android.os.Looper.loop(Looper.java:137)
10-25 10:07:43.507: E/AndroidRuntime(8396): at android.app.ActivityThread.main(ActivityThread.java:4895)
10-25 10:07:43.507: E/AndroidRuntime(8396): at java.lang.reflect.Method.invokeNative(Native Method)
10-25 10:07:43.507: E/AndroidRuntime(8396): at java.lang.reflect.Method.invoke(Method.java:511)
10-25 10:07:43.507: E/AndroidRuntime(8396): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:994)
10-25 10:07:43.507: E/AndroidRuntime(8396): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761)
10-25 10:07:43.507: E/AndroidRuntime(8396): at dalvik.system.NativeStart.main(Native Method)
10-25 10:07:43.507: E/AndroidRuntime(8396): Caused by: java.lang.NullPointerException
10-25 10:07:43.507: E/AndroidRuntime(8396): at com.astrex.ppastrex.FrameDocumentos.onCreateView(FrameDocumentos.java:66)
10-25 10:07:43.507: E/AndroidRuntime(8396): at android.support.v4.app.Fragment.performCreateView(Fragment.java:1478)
10-25 10:07:43.507: E/AndroidRuntime(8396): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:927)
10-25 10:07:43.507: E/AndroidRuntime(8396): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
10-25 10:07:43.507: E/AndroidRuntime(8396): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1086)
10-25 10:07:43.507: E/AndroidRuntime(8396): at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1877)
10-25 10:07:43.507: E/AndroidRuntime(8396): at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:552)
10-25 10:07:43.507: E/AndroidRuntime(8396): at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1178)
10-25 10:07:43.507: E/AndroidRuntime(8396): at android.app.Activity.performStart(Activity.java:5173)
10-25 10:07:43.507: E/AndroidRuntime(8396): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2070)
10-25 10:07:43.507: E/AndroidRuntime(8396): ... 11 more
I had a similar issue happening for me on Android 6.0, but not in 4.4, so for older devices, it would work fine and there would be no crash.
In my case, I was downloading a url, saving the file and opening them in 3rd party viewers.
I've discovered that as long as I save the pdf to the Downloads Directory, it fixes it for my situation.
File root = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
File dir = new File(root.getAbsolutePath());
if (dir.exists() == false) {
dir.mkdirs();
}
String fileName = "filename.pdf";
file = new File(dir, fileName);
try like this:
File file = new File(pdfpath);
if (file.exists()) {
Uri path = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(path, "application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
try {
startActivity(intent);
finish();
}
catch (ActivityNotFoundException e) {
}
}
The intent looks like it was called correctly it works for some. Seems like you'd have a null reference without checking if the file exists.
Experience tells me the null comes because your device ran out of memory while opening the pdf file so your app was shut down to free up some memory.
The solution is to add the savedinstancestate method saving what your app needs and check if the savedinstancestate != null in your oncreate method then recreate what your app needs from the savedinstancestate.

get database called recursively error only on HTC Sensation XL

I'm working on a application where the database is imported like in this tutorial: http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/
This works fine on most devices,only at HTC Sensation XL it doesn't work.
Thanks for your Help
Here is error code
11-02 21:35:33.748: W/System.err(14878): java.lang.IllegalStateException: getReadableDatabase called recursively
11-02 21:35:33.748: W/System.err(14878): at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:245)
11-02 21:35:33.748: W/System.err(14878): at at.klettern.database.DatabaseHelper.createDataBase(DatabaseHelper.java:54)
11-02 21:35:33.748: W/System.err(14878): at at.klettern.database.DatabaseHelper.onCreate(DatabaseHelper.java:148)
11-02 21:35:33.758: W/System.err(14878): at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:183)
11-02 21:35:33.758: W/System.err(14878): at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:249)
11-02 21:35:33.758: W/System.err(14878): at at.klettern.database.DatabaseRouten.(DatabaseRouten.java:39)
11-02 21:35:33.758: W/System.err(14878): at at.klettern.wachauclimbing.SplashActivity.onCreate(SplashActivity.java:28)
11-02 21:35:33.758: W/System.err(14878): at android.app.Activity.performCreate(Activity.java:4531)
11-02 21:35:33.768: W/System.err(14878): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1071)
11-02 21:35:33.768: W/System.err(14878): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2150)
11-02 21:35:33.768: W/System.err(14878): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2229)
11-02 21:35:33.768: W/System.err(14878): at android.app.ActivityThread.access$600(ActivityThread.java:139)
11-02 21:35:33.768: W/System.err(14878): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1261)
11-02 21:35:33.778: W/System.err(14878): at android.os.Handler.dispatchMessage(Handler.java:99)
11-02 21:35:33.778: W/System.err(14878): at android.os.Looper.loop(Looper.java:154)
11-02 21:35:33.778: W/System.err(14878): at android.app.ActivityThread.main(ActivityThread.java:4945)
11-02 21:35:33.778: W/System.err(14878): at java.lang.reflect.Method.invokeNative(Native Method)
11-02 21:35:33.778: W/System.err(14878): at java.lang.reflect.Method.invoke(Method.java:511)
11-02 21:35:33.788: W/System.err(14878): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
11-02 21:35:33.788: W/System.err(14878): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
11-02 21:35:33.788: W/System.err(14878): at dalvik.system.NativeStart.main(Native Method)
What android version are running on this device? [I found some fatal errors Android 2.1 or less.]
Otherwise, I have been able to cannibalize most if not all of the tutorial you reference and it works flawlessly from 2.2 and up.

error when retrieving a record from the data base?

I'm trying to retrieve a name stred in SQLite table, despite the database has 11 or more records, when I try to retrieve any name from the stored records, The App. Crashs.
Java code:
OnClickListener btn_NavaigateListsner = new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
if (!btn_Save.isEnabled()) {
int c = mpoh.getCurrentRowNumber();
Toast.makeText(getBaseContext(), ""+mpoh.getMP_Name(0), Toast.LENGTH_SHORT).show();
Bundle bundle = new Bundle();
//bundle.putString("name", mpoh.getMP_Name(c));
//bundle.putDouble("lat", mpoh.getMP_Lat(c));
//bundle.putDouble("lng", mpoh.getMP_Lng(c));
//bundle.putString("date", mpoh.getMP_Date(c));
//bundle.putString("time", mpoh.getMP_Time(c));
intent01 = new Intent(MPData.this, MPInfo.class);
intent01.putExtras(bundle);
startActivity(intent01);
}// End of If
}
};
Method that retrieves the stored name:
public String getMP_Name(long id) {
SQLiteDatabase db = this.getReadableDatabase();
SQLiteCursor c = (SQLiteCursor) db.rawQuery("SELECT name FROM MPData WHERE "+
BaseColumns._ID+" = "+
Long.toString(id) +" AND name IS NOT NULL ", null);
c.moveToFirst();
String r = c.getString(0);
c.close();
db.close();
return r;
}
some of LogCat's output:
03-05 12:16:48.288: E/AndroidRuntime(973): FATAL EXCEPTION: main
03-05 12:16:48.288: E/AndroidRuntime(973): android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
03-05 12:16:48.288: E/AndroidRuntime(973): at android.database.AbstractCursor.checkPosition(AbstractCursor.java:580)
03-05 12:16:48.288: E/AndroidRuntime(973): at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:214)
03-05 12:16:48.288: E/AndroidRuntime(973): at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:41)
03-05 12:16:48.288: E/AndroidRuntime(973): at com.androidbook.MP.MP_DB.getMP_Name(MP_DB.java:45)
03-05 12:16:48.288: E/AndroidRuntime(973): at com.androidbook.MP.MPData$1.onClick(MPData.java:57)
03-05 12:16:48.288: E/AndroidRuntime(973): at android.view.View.performClick(View.java:2485)
03-05 12:16:48.288: E/AndroidRuntime(973): at android.view.View$PerformClick.run(View.java:9080)
03-05 12:16:48.288: E/AndroidRuntime(973): at android.os.Handler.handleCallback(Handler.java:587)
03-05 12:16:48.288: E/AndroidRuntime(973): at android.os.Handler.dispatchMessage(Handler.java:92)
03-05 12:16:48.288: E/AndroidRuntime(973): at android.os.Looper.loop(Looper.java:130)
03-05 12:16:48.288: E/AndroidRuntime(973): at android.app.ActivityThread.main(ActivityThread.java:3683)
03-05 12:16:48.288: E/AndroidRuntime(973): at java.lang.reflect.Method.invokeNative(Native Method)
03-05 12:16:48.288: E/AndroidRuntime(973): at java.lang.reflect.Method.invoke(Method.java:507)
03-05 12:16:48.288: E/AndroidRuntime(973): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
03-05 12:16:48.288: E/AndroidRuntime(973): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-05 12:16:48.288: E/AndroidRuntime(973): at dalvik.system.NativeStart.main(Native Method)
03-05 12:32:19.897: E/AndroidRuntime(1022): FATAL EXCEPTION: main
03-05 12:32:19.897: E/AndroidRuntime(1022): android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
03-05 12:32:19.897: E/AndroidRuntime(1022): at android.database.AbstractCursor.checkPosition(AbstractCursor.java:580)
03-05 12:32:19.897: E/AndroidRuntime(1022): at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:214)
03-05 12:32:19.897: E/AndroidRuntime(1022): at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:41)
03-05 12:32:19.897: E/AndroidRuntime(1022): at com.androidbook.MP.MP_DB.getMP_Name(MP_DB.java:45)
03-05 12:32:19.897: E/AndroidRuntime(1022): at com.androidbook.MP.MPData$1.onClick(MPData.java:57)
03-05 12:32:19.897: E/AndroidRuntime(1022): at android.view.View.performClick(View.java:2485)
03-05 12:32:19.897: E/AndroidRuntime(1022): at android.view.View$PerformClick.run(View.java:9080)
03-05 12:32:19.897: E/AndroidRuntime(1022): at android.os.Handler.handleCallback(Handler.java:587)
03-05 12:32:19.897: E/AndroidRuntime(1022): at android.os.Handler.dispatchMessage(Handler.java:92)
03-05 12:32:19.897: E/AndroidRuntime(1022): at android.os.Looper.loop(Looper.java:130)
03-05 12:32:19.897: E/AndroidRuntime(1022): at android.app.ActivityThread.main(ActivityThread.java:3683)
03-05 12:32:19.897: E/AndroidRuntime(1022): at java.lang.reflect.Method.invokeNative(Native Method)
03-05 12:32:19.897: E/AndroidRuntime(1022): at java.lang.reflect.Method.invoke(Method.java:507)
03-05 12:32:19.897: E/AndroidRuntime(1022): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
03-05 12:32:19.897: E/AndroidRuntime(1022): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-05 12:32:19.897: E/AndroidRuntime(1022): at dalvik.system.NativeStart.main(Native Method)
03-05 12:39:24.627: E/AndroidRuntime(1093): FATAL EXCEPTION: main
03-05 12:39:24.627: E/AndroidRuntime(1093): android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
03-05 12:39:24.627: E/AndroidRuntime(1093): at android.database.AbstractCursor.checkPosition(AbstractCursor.java:580)
03-05 12:39:24.627: E/AndroidRuntime(1093): at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:214)
03-05 12:39:24.627: E/AndroidRuntime(1093): at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:41)
03-05 12:39:24.627: E/AndroidRuntime(1093): at com.androidbook.MP.MP_DB.getMP_Name(MP_DB.java:45)
03-05 12:39:24.627: E/AndroidRuntime(1093): at com.androidbook.MP.MPData$1.onClick(MPData.java:57)
03-05 12:39:24.627: E/AndroidRuntime(1093): at android.view.View.performClick(View.java:2485)
03-05 12:39:24.627: E/AndroidRuntime(1093): at android.view.View.onKeyUp(View.java:4257)
03-05 12:39:24.627: E/AndroidRuntime(1093): at android.widget.TextView.onKeyUp(TextView.java:4587)
03-05 12:39:24.627: E/AndroidRuntime(1093): at android.view.KeyEvent.dispatch(KeyEvent.java:1280)
03-05 12:39:24.627: E/AndroidRuntime(1093): at android.view.View.dispatchKeyEvent(View.java:3855)
03-05 12:39:24.627: E/AndroidRuntime(1093): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:789)
03-05 12:39:24.627: E/AndroidRuntime(1093): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:789)
03-05 12:39:24.627: E/AndroidRuntime(1093): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:789)
03-05 12:39:24.627: E/AndroidRuntime(1093): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:789)
03-05 12:39:24.627: E/AndroidRuntime(1093): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchKeyEvent(PhoneWindow.java:1687)
03-05 12:39:24.627: E/AndroidRuntime(1093): at com.android.internal.policy.impl.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1120)
03-05 12:39:24.627: E/AndroidRuntime(1093): at android.app.Activity.dispatchKeyEvent(Activity.java:2073)
03-05 12:39:24.627: E/AndroidRuntime(1093): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1663)
03-05 12:39:24.627: E/AndroidRuntime(1093): at android.view.ViewRoot.deliverKeyEventToViewHierarchy(ViewRoot.java:2560)
03-05 12:39:24.627: E/AndroidRuntime(1093): at android.view.ViewRoot.handleFinishedEvent(ViewRoot.java:2535)
03-05 12:39:24.627: E/AndroidRuntime(1093): at android.view.ViewRoot.handleMessage(ViewRoot.java:1867)
03-05 12:39:24.627: E/AndroidRuntime(1093): at android.os.Handler.dispatchMessage(Handler.java:99)
03-05 12:39:24.627: E/AndroidRuntime(1093): at android.os.Looper.loop(Looper.java:130)
03-05 12:39:24.627: E/AndroidRuntime(1093): at android.app.ActivityThread.main(ActivityThread.java:3683)
03-05 12:39:24.627: E/AndroidRuntime(1093): at java.lang.reflect.Method.invokeNative(Native Method)
03-05 12:39:24.627: E/AndroidRuntime(1093): at java.lang.reflect.Method.invoke(Method.java:507)
03-05 12:39:24.627: E/AndroidRuntime(1093): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
03-05 12:39:24.627: E/AndroidRuntime(1093): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-05 12:39:24.627: E/AndroidRuntime(1093): at dalvik.system.NativeStart.main(Native Method)
The code looks fine to me. Are you 100% sure you have an entry in your DB with an _id corresponding to 0?
If you call getMP_Name with an invalid _id then the exception will get raised as you posted it.
You should check for this case as follows:
if (c.getCount()==0) return "";
// rest of code
But I wouldn't do it like this anyway because your current implementation of getMP_XXX is very inefficient because you hit the database for each field and each row. You should minimise your number of queries and then iterate over the resulting cursor.
Look at the following line :
String r = c.getString(0);
You are not safe checking your cursor and just assuming a result was recieved.
Check you SQL query and add a safe check for making sure your cursor has retrieved results.

Thread runtime exception

synchronized (this.childrenGroupsLock) {
for (int i = 0; i < numGroups; i++) {
suspendCurrent |= this.childrenGroups[i].suspendHelper();
}
}
return suspendCurrent;
This is the thread that force closes my application(any android application). I dunno how to handle it.
Can anyone please help me?
The application just force closes after it reaches this point.
05-12 10:22:28.582: ERROR/AndroidRuntime(352): FATAL EXCEPTION: main
05-12 10:22:28.582: ERROR/AndroidRuntime(352): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.android/com.android.GraphicsActivity}: java.lang.IllegalAccessException: access to class not allowed
05-12 10:22:28.582: ERROR/AndroidRuntime(352): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1544)
05-12 10:22:28.582: ERROR/AndroidRuntime(352): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1638)
05-12 10:22:28.582: ERROR/AndroidRuntime(352): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
05-12 10:22:28.582: ERROR/AndroidRuntime(352): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:928)
05-12 10:22:28.582: ERROR/AndroidRuntime(352): at android.os.Handler.dispatchMessage(Handler.java:99)
05-12 10:22:28.582: ERROR/AndroidRuntime(352): at android.os.Looper.loop(Looper.java:123)
05-12 10:22:28.582: ERROR/AndroidRuntime(352): at android.app.ActivityThread.main(ActivityThread.java:3647)
05-12 10:22:28.582: ERROR/AndroidRuntime(352): at java.lang.reflect.Method.invokeNative(Native Method)
05-12 10:22:28.582: ERROR/AndroidRuntime(352): at java.lang.reflect.Method.invoke(Method.java:507)
05-12 10:22:28.582: ERROR/AndroidRuntime(352): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
05-12 10:22:28.582: ERROR/AndroidRuntime(352): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
05-12 10:22:28.582: ERROR/AndroidRuntime(352): at dalvik.system.NativeStart.main(Native Method)
05-12 10:22:28.582: ERROR/AndroidRuntime(352): Caused by: java.lang.IllegalAccessException: access to class not allowed
05-12 10:22:28.582: ERROR/AndroidRuntime(352): at java.lang.Class.newInstanceImpl(Native Method)
05-12 10:22:28.582: ERROR/AndroidRuntime(352): at java.lang.Class.newInstance(Class.java:1409)
05-12 10:22:28.582: ERROR/AndroidRuntime(352): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
05-12 10:22:28.582: ERROR/AndroidRuntime(352): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1536)
This is the error I am getting in the LogCat

Categories

Resources