Can't open a local PDF in webview using file:// - android

I need to display a PDF file located in my app dir in a webwiev without using Google Docs.
This is my code for the webview:
public void OpenPDF() {
WebView webview = new WebView(this);
setContentView(webview);
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl("file://mnt/data/data/com.example.android/files/Docs/test.pdf");;
}
I get a blank webview instead of below code works
public void OpenPDF() {
WebView webview = new WebView(this);
setContentView(webview);
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl("file://mnt/data/data/com.example.android/files/Docs/test.html");
}
I tested directly in my web browser with file://mnt/data/data/com.example.android/files/Docs/test.pdf and test.html and it worked for both. I installed a PDF reader.
07-25 17:09:07.967: W/webcore(11347): java.lang.Throwable: EventHub.removeMessages(int what = 107) is not supported before the WebViewCore is set up.
07-25 17:09:07.967: W/webcore(11347): at android.webkit.WebViewCore$EventHub.removeMessages(WebViewCore.java:1683)
07-25 17:09:07.967: W/webcore(11347): at android.webkit.WebViewCore$EventHub.access$7900(WebViewCore.java:926)
07-25 17:09:07.967: W/webcore(11347): at android.webkit.WebViewCore.removeMessages(WebViewCore.java:1795)
07-25 17:09:07.967: W/webcore(11347): at android.webkit.WebView.sendOurVisibleRect(WebView.java:2917)
07-25 17:09:07.967: W/webcore(11347): at android.webkit.ZoomManager.setZoomScale(ZoomManager.java:593)
07-25 17:09:07.967: W/webcore(11347): at android.webkit.ZoomManager.access$1700(ZoomManager.java:49)
07-25 17:09:07.967: W/webcore(11347): at android.webkit.ZoomManager$PostScale.run(ZoomManager.java:984)
07-25 17:09:07.967: W/webcore(11347): at android.os.Handler.handleCallback(Handler.java:605)
07-25 17:09:07.967: W/webcore(11347): at android.os.Handler.dispatchMessage(Handler.java:92)
07-25 17:09:07.967: W/webcore(11347): at android.os.Looper.loop(Looper.java:137)
07-25 17:09:07.967: W/webcore(11347): at android.app.ActivityThread.main(ActivityThread.java:4424)
07-25 17:09:07.967: W/webcore(11347): at java.lang.reflect.Method.invokeNative(Native Method)
07-25 17:09:07.967: W/webcore(11347): at java.lang.reflect.Method.invoke(Method.java:511)
07-25 17:09:07.967: W/webcore(11347): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
07-25 17:09:07.967: W/webcore(11347): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
07-25 17:09:07.967: W/webcore(11347): at dalvik.system.NativeStart.main(Native Method)
Any ideas about why only pdf files won't open ?

Their seems to be an answer to your question already in stack overflow at Open Local Html File in Webview - Android
to sum it up : Usage of file:/// before your actual path should solve your problem for everything except .pdf files
Webview does not support PDF in android :(. You need to use google doc according to different sources.

I think you should try with 3 slashes, like that:
webview.loadUrl("file:///mnt/data/data/com.example.android/files/Docs/test.pdf");

Related

nullpointerexception after rotating emulator in android

I have the above problem when i rotate the emulator while using the image editing app. It just crashes with a nullpointerexception. Here is the portion of code that is relevant for the problem.
HueseekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
public void onProgressChanged(SeekBar arg0, int progress,
boolean fromUser) {
try {
if (picclass.hasBitmap()) {
float hue = (float) (progress - 256);
float setHue = (float) hue * 360 / 256;
picclass.setHue(setHue);
if (!noUpdate) {
picclass.ApplyFilter();
Img.setImageBitmap(picclass.getDisplayedBitmap());
mUndoRedo.SetStateForUndoRedo();
}
}
} catch (OutOfMemoryError ome) {
AlertDialog ad = adb.create();
ad.setMessage("Leider reicht der Speicherplatz nicht aus!");
ad.show();
}
}
According to the logcat the problem is mUndoRedo.SetStateForUndoRedo();. The code compiles allright. I don't understand how this exception is triggered here. Any ideas?
EDIT: LOGCAT
07-25 18:26:07.328: D/dalvikvm(5989): GC_CONCURRENT freed 159K, 3% free 9134K/9351K, paused 4ms+3ms
07-25 18:26:07.348: D/TextLayoutCache(5989): Using debug level: 0 - Debug Enabled: 0
07-25 18:26:07.428: D/libEGL(5989): loaded /system/lib/egl/libGLES_android.so
07-25 18:26:07.428: D/libEGL(5989): loaded /system/lib/egl/libEGL_adreno200.so
07-25 18:26:07.438: D/libEGL(5989): loaded /system/lib/egl/libGLESv1_CM_adreno200.so
07-25 18:26:07.438: D/libEGL(5989): loaded /system/lib/egl/libGLESv2_adreno200.so
07-25 18:26:07.478: D/OpenGLRenderer(5989): Enabling debug mode 0
07-25 18:26:10.668: D/OpenGLRenderer(5989): Flushing caches (mode 0)
07-25 18:26:10.688: D/OpenGLRenderer(5989): Flushing caches (mode 0)
07-25 18:26:12.128: D/OpenGLRenderer(5989): Flushing caches (mode 1)
07-25 18:26:15.518: I/System.out(5989): Image Path : /mnt/sdcard/tiny_sd/rocknest_858x188.jpg
07-25 18:26:15.548: D/dalvikvm(5989): GC_FOR_ALLOC freed 102K, 2% free 9314K/9479K, paused 23ms
07-25 18:26:15.548: I/dalvikvm-heap(5989): Grow heap (frag case) to 9.747MB for 645232-byte allocation
07-25 18:26:15.598: D/dalvikvm(5989): GC_CONCURRENT freed 103K, 3% free 9841K/10119K, paused 5ms+2ms
07-25 18:26:15.598: W/CursorWrapperInner(5989): Cursor finalized without prior close()
07-25 18:26:17.538: D/OpenGLRenderer(5989): Flushing caches (mode 0)
07-25 18:26:17.808: D/dalvikvm(5989): GC_FOR_ALLOC freed 86K, 3% free 9902K/10119K, paused 37ms
07-25 18:26:17.808: I/dalvikvm-heap(5989): Grow heap (frag case) to 10.321MB for 645232-byte allocation
07-25 18:26:17.878: D/dalvikvm(5989): GC_CONCURRENT freed 4K, 3% free 10528K/10759K, paused 2ms+2ms
07-25 18:26:17.908: D/dalvikvm(5989): GC_FOR_ALLOC freed <1K, 3% free 10528K/10759K, paused 32ms
07-25 18:26:17.908: I/dalvikvm-heap(5989): Grow heap (frag case) to 10.931MB for 645232-byte allocation
07-25 18:26:17.978: D/dalvikvm(5989): GC_CONCURRENT freed 0K, 3% free 11158K/11399K, paused 5ms+2ms
07-25 18:26:20.098: D/AndroidRuntime(5989): Shutting down VM
07-25 18:26:20.098: W/dalvikvm(5989): threadid=1: thread exiting with uncaught exception (group=0x2b542210)
07-25 18:26:20.108: E/AndroidRuntime(5989): FATAL EXCEPTION: main
07-25 18:26:20.108: E/AndroidRuntime(5989): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.propra_fotoapp/com.example.propra_fotoapp.MainActivity}: java.lang.NullPointerException
07-25 18:26:20.108: E/AndroidRuntime(5989): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1967)
07-25 18:26:20.108: E/AndroidRuntime(5989): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
07-25 18:26:20.108: E/AndroidRuntime(5989): at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3371)
07-25 18:26:20.108: E/AndroidRuntime(5989): at android.app.ActivityThread.access$700(ActivityThread.java:127)
07-25 18:26:20.108: E/AndroidRuntime(5989): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1162)
07-25 18:26:20.108: E/AndroidRuntime(5989): at android.os.Handler.dispatchMessage(Handler.java:99)
07-25 18:26:20.108: E/AndroidRuntime(5989): at android.os.Looper.loop(Looper.java:137)
07-25 18:26:20.108: E/AndroidRuntime(5989): at android.app.ActivityThread.main(ActivityThread.java:4441)
07-25 18:26:20.108: E/AndroidRuntime(5989): at java.lang.reflect.Method.invokeNative(Native Method)
07-25 18:26:20.108: E/AndroidRuntime(5989): at java.lang.reflect.Method.invoke(Method.java:511)
07-25 18:26:20.108: E/AndroidRuntime(5989): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
07-25 18:26:20.108: E/AndroidRuntime(5989): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
07-25 18:26:20.108: E/AndroidRuntime(5989): at dalvik.system.NativeStart.main(Native Method)
07-25 18:26:20.108: E/AndroidRuntime(5989): Caused by: java.lang.NullPointerException
07-25 18:26:20.108: E/AndroidRuntime(5989): at com.example.propra_fotoapp.MainActivity$13.onProgressChanged(MainActivity.java:269)
07-25 18:26:20.108: E/AndroidRuntime(5989): at android.widget.SeekBar.onProgressRefresh(SeekBar.java:89)
07-25 18:26:20.108: E/AndroidRuntime(5989): at android.widget.ProgressBar.doRefreshProgress(ProgressBar.java:609)
07-25 18:26:20.108: E/AndroidRuntime(5989): at android.widget.ProgressBar.refreshProgress(ProgressBar.java:621)
07-25 18:26:20.108: E/AndroidRuntime(5989): at android.widget.ProgressBar.setProgress(ProgressBar.java:670)
07-25 18:26:20.108: E/AndroidRuntime(5989): at android.widget.ProgressBar.setProgress(ProgressBar.java:651)
07-25 18:26:20.108: E/AndroidRuntime(5989): at android.widget.ProgressBar.onRestoreInstanceState(ProgressBar.java:1096)
07-25 18:26:20.108: E/AndroidRuntime(5989): at android.view.View.dispatchRestoreInstanceState(View.java:10043)
07-25 18:26:20.108: E/AndroidRuntime(5989): at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2425)
07-25 18:26:20.108: E/AndroidRuntime(5989): at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2425)
07-25 18:26:20.108: E/AndroidRuntime(5989): at android.view.View.restoreHierarchyState(View.java:10021)
07-25 18:26:20.108: E/AndroidRuntime(5989): at com.android.internal.policy.impl.PhoneWindow.restoreHierarchyState(PhoneWindow.java:1619)
07-25 18:26:20.108: E/AndroidRuntime(5989): at android.app.Activity.onRestoreInstanceState(Activity.java:906)
07-25 18:26:20.108: E/AndroidRuntime(5989): at android.app.Activity.performRestoreInstanceState(Activity.java:878)
07-25 18:26:20.108: E/AndroidRuntime(5989): at android.app.Instrumentation.callActivityOnRestoreInstanceState(Instrumentation.java:1100)
07-25 18:26:20.108: E/AndroidRuntime(5989): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1945)
07-25 18:26:20.108: E/AndroidRuntime(5989): ... 12 more
07-25 18:26:20.158: D/dalvikvm(5989): GC_CONCURRENT freed 1333K, 13% free 10551K/12039K, paused 2ms+2ms
07-25 18:31:20.198: I/Process(5989): Sending signal. PID: 5989 SIG: 9
You need to save the bundle before the activity is destroyed and then set the values of the bundle when the activity is recreated
Android operating system is unique. When you rotate the screen, you are creating a new activity automatically, so that's why you get a null reference. My advice is to set your screen to potrait or landscape.

Cocos2dx android application runs on emulator but not on device

The project was working just fine last Thursday, then, some sort of Eclipse bug caused the project properties to get all messed up.
After a splitting and frustrating headache, managed to isolate the issue and fix it....on the emulator, running it on the device gives me the original error messages:
07-25 13:01:08.482: E/AndroidRuntime(4273): FATAL EXCEPTION: main
07-25 13:01:08.482: E/AndroidRuntime(4273): java.lang.ExceptionInInitializerError
07-25 13:01:08.482: E/AndroidRuntime(4273): at java.lang.Class.newInstanceImpl(Native Method)
07-25 13:01:08.482: E/AndroidRuntime(4273): at java.lang.Class.newInstance(Class.java:1319)
07-25 13:01:08.482: E/AndroidRuntime(4273): at android.app.Instrumentation.newActivity(Instrumentation.java:1027)
07-25 13:01:08.482: E/AndroidRuntime(4273): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1885)
07-25 13:01:08.482: E/AndroidRuntime(4273): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995)
07-25 13:01:08.482: E/AndroidRuntime(4273): at android.app.ActivityThread.access$600(ActivityThread.java:128)
07-25 13:01:08.482: E/AndroidRuntime(4273): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)
07-25 13:01:08.482: E/AndroidRuntime(4273): at android.os.Handler.dispatchMessage(Handler.java:99)
07-25 13:01:08.482: E/AndroidRuntime(4273): at android.os.Looper.loop(Looper.java:137)
07-25 13:01:08.482: E/AndroidRuntime(4273): at android.app.ActivityThread.main(ActivityThread.java:4514)
07-25 13:01:08.482: E/AndroidRuntime(4273): at java.lang.reflect.Method.invokeNative(Native Method)
07-25 13:01:08.482: E/AndroidRuntime(4273): at java.lang.reflect.Method.invoke(Method.java:511)
07-25 13:01:08.482: E/AndroidRuntime(4273): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
07-25 13:01:08.482: E/AndroidRuntime(4273): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
07-25 13:01:08.482: E/AndroidRuntime(4273): at dalvik.system.NativeStart.main(Native Method)
07-25 13:01:08.482: E/AndroidRuntime(4273): Caused by: java.lang.UnsatisfiedLinkError: Couldn't load game: findLibrary returned null
07-25 13:01:08.482: E/AndroidRuntime(4273): at java.lang.Runtime.loadLibrary(Runtime.java:365)
07-25 13:01:08.482: E/AndroidRuntime(4273): at java.lang.System.loadLibrary(System.java:535)
Already tried at least 12 different ways to fix the "Couldn't load game: findLibrary returned null" error to no avail.
UPDATE: Tried using a 4.0 simulator with the exact same results, so it's definitely tied to android version; however, the project was created and is indeed built for Android 4.0 as the minimum.
Any ideas what might be happening and how to fix it?
Thanks for any replies
Most probably your library is not properly generated. Goto ProjectHome->libs->armeabi->libgame.so . libgame.so file is missing.
This file could be generated when you run create-android-project.bat or equivalent linux file.
which creates empty android project.Try copy paste this file from there.
To build cocos2dx project for Android you should perform two steps.
Build C++ libraries. It can be done with build_native.sh
Build Java Project. It can be done through Eclipse.
Such error will happen if you have missed the first step.

Android - Out of memory Error. When it run on real device

I have an image gallery application, and I'm trying to get image from External Storage.My application can run on android emulator but on real device(HTC OneX) I got some exception.
My Log cat here.
07-25 17:17:49.027: E/dalvikvm-heap(3008): Out of memory on a 480016-byte allocation.
07-25 17:17:49.052: E/dalvikvm(3008): Out of memory: Heap Size=65571KB, Allocated=63717KB, Limit=65536KB
07-25 17:17:49.052: E/dalvikvm(3008): Extra info: Footprint=65315KB, Allowed Footprint=65571KB, Trimmed=0KB
07-25 17:17:49.052: E/MediaStore(3008): failed to allocate memory for thumbnail content://media/external/images/thumbnails/300; java.lang.OutOfMemoryError: (Heap Size=65571KB, Allocated=63717KB)
07-25 17:17:49.142: E/dalvikvm-heap(3008): Out of memory on a 480016-byte allocation.
07-25 17:17:49.152: E/dalvikvm(3008): Out of memory: Heap Size=65571KB, Allocated=63718KB, Limit=65536KB
07-25 17:17:49.152: E/dalvikvm(3008): Extra info: Footprint=65315KB, Allowed Footprint=65571KB, Trimmed=0KB
07-25 17:17:49.152: E/MediaStore(3008): failed to allocate memory for thumbnail content://media/external/images/thumbnails/300; java.lang.OutOfMemoryError: (Heap Size=65571KB, Allocated=63718KB)
07-25 17:17:49.302: E/dalvikvm-heap(3008): Out of memory on a 480016-byte allocation.
07-25 17:17:49.317: E/dalvikvm(3008): Out of memory: Heap Size=65571KB, Allocated=63749KB, Limit=65536KB
07-25 17:17:49.317: E/dalvikvm(3008): Extra info: Footprint=65315KB, Allowed Footprint=65571KB, Trimmed=0KB
07-25 17:17:49.327: E/AndroidRuntime(3008): FATAL EXCEPTION: AsyncTask #1
07-25 17:17:49.327: E/AndroidRuntime(3008): java.lang.RuntimeException: An error occured while executing doInBackground()
07-25 17:17:49.327: E/AndroidRuntime(3008): at android.os.AsyncTask$3.done(AsyncTask.java:299)
07-25 17:17:49.327: E/AndroidRuntime(3008): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
07-25 17:17:49.327: E/AndroidRuntime(3008): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
07-25 17:17:49.327: E/AndroidRuntime(3008): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
07-25 17:17:49.327: E/AndroidRuntime(3008): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
07-25 17:17:49.327: E/AndroidRuntime(3008): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
07-25 17:17:49.327: E/AndroidRuntime(3008): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
07-25 17:17:49.327: E/AndroidRuntime(3008): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
07-25 17:17:49.327: E/AndroidRuntime(3008): at java.lang.Thread.run(Thread.java:864)
07-25 17:17:49.327: E/AndroidRuntime(3008): Caused by: java.lang.OutOfMemoryError: (Heap Size=65571KB, Allocated=63749KB)
07-25 17:17:49.327: E/AndroidRuntime(3008): at android.graphics.BitmapFactory.nativeDecodeByteArray(Native Method)
07-25 17:17:49.327: E/AndroidRuntime(3008): at android.graphics.BitmapFactory.decodeByteArray(BitmapFactory.java:552)
07-25 17:17:49.327: E/AndroidRuntime(3008): at android.media.ThumbnailUtils.createThumbnailFromEXIF(ThumbnailUtils.java:515)
07-25 17:17:49.327: E/AndroidRuntime(3008): at android.media.ThumbnailUtils.createImageThumbnail(ThumbnailUtils.java:102)
07-25 17:17:49.327: E/AndroidRuntime(3008): at android.provider.MediaStore$InternalThumbnails.getThumbnail(MediaStore.java:626)
07-25 17:17:49.327: E/AndroidRuntime(3008): at android.provider.MediaStore$Images$Thumbnails.getThumbnail(MediaStore.java:987)
07-25 17:17:49.327: E/AndroidRuntime(3008): at com.mimi.ngsbusproject.GalleryActivity.Gallery(GalleryActivity.java:92)
07-25 17:17:49.327: E/AndroidRuntime(3008): at com.mimi.ngsbusproject.GalleryActivity.access$1(GalleryActivity.java:74)
07-25 17:17:49.327: E/AndroidRuntime(3008): at com.mimi.ngsbusproject.GalleryActivity$LoadGallery.doInBackground(GalleryActivity.java:58)
07-25 17:17:49.327: E/AndroidRuntime(3008): at com.mimi.ngsbusproject.GalleryActivity$LoadGallery.doInBackground(GalleryActivity.java:1)
07-25 17:17:49.327: E/AndroidRuntime(3008): at android.os.AsyncTask$2.call(AsyncTask.java:287)
07-25 17:17:49.327: E/AndroidRuntime(3008): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
07-25 17:17:49.327: E/AndroidRuntime(3008): ... 5 more
07-25 17:17:50.062: E/WindowManager(3008): Activity com.mimi.ngsbusproject.GalleryActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView#41ac90a8 that was originally added here
07-25 17:17:50.062: E/WindowManager(3008): android.view.WindowLeaked: Activity com.mimi.ngsbusproject.GalleryActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView#41ac90a8 that was originally added here
07-25 17:17:50.062: E/WindowManager(3008): at android.view.ViewRootImpl.<init>(ViewRootImpl.java:465)
07-25 17:17:50.062: E/WindowManager(3008): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:419)
07-25 17:17:50.062: E/WindowManager(3008): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:351)
07-25 17:17:50.062: E/WindowManager(3008): at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:171)
07-25 17:17:50.062: E/WindowManager(3008): at android.view.Window$LocalWindowManager.addView(Window.java:558)
07-25 17:17:50.062: E/WindowManager(3008): at android.app.Dialog.show(Dialog.java:282)
07-25 17:17:50.062: E/WindowManager(3008): at android.app.ProgressDialog.show(ProgressDialog.java:116)
07-25 17:17:50.062: E/WindowManager(3008): at android.app.ProgressDialog.show(ProgressDialog.java:99)
07-25 17:17:50.062: E/WindowManager(3008): at com.mimi.ngsbusproject.GalleryActivity$LoadGallery.onPreExecute(GalleryActivity.java:51)
07-25 17:17:50.062: E/WindowManager(3008): at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:586)
07-25 17:17:50.062: E/WindowManager(3008): at android.os.AsyncTask.execute(AsyncTask.java:534)
07-25 17:17:50.062: E/WindowManager(3008): at com.mimi.ngsbusproject.GalleryActivity.onCreate(GalleryActivity.java:43)
07-25 17:17:50.062: E/WindowManager(3008): at android.app.Activity.performCreate(Activity.java:5066)
07-25 17:17:50.062: E/WindowManager(3008): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1101)
07-25 17:17:50.062: E/WindowManager(3008): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2307)
07-25 17:17:50.062: E/WindowManager(3008): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
07-25 17:17:50.062: E/WindowManager(3008): at android.app.ActivityThread.access$600(ActivityThread.java:151)
07-25 17:17:50.062: E/WindowManager(3008): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1331)
07-25 17:17:50.062: E/WindowManager(3008): at android.os.Handler.dispatchMessage(Handler.java:99)
07-25 17:17:50.062: E/WindowManager(3008): at android.os.Looper.loop(Looper.java:155)
07-25 17:17:50.062: E/WindowManager(3008): at android.app.ActivityThread.main(ActivityThread.java:5485)
07-25 17:17:50.062: E/WindowManager(3008): at java.lang.reflect.Method.invokeNative(Native Method)
07-25 17:17:50.062: E/WindowManager(3008): at java.lang.reflect.Method.invoke(Method.java:511)
07-25 17:17:50.062: E/WindowManager(3008): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1028)
07-25 17:17:50.062: E/WindowManager(3008): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:795)
07-25 17:17:50.062: E/WindowManager(3008): at dalvik.system.NativeStart.main(Native Method)
07-25 17:17:50.962: E/dalvikvm-heap(3008): Out of memory on a 2264368-byte allocation.
07-25 17:17:50.967: E/dalvikvm(3008): Out of memory: Heap Size=65571KB, Allocated=63787KB, Limit=65536KB
07-25 17:17:50.967: E/dalvikvm(3008): Extra info: Footprint=65315KB, Allowed Footprint=65571KB, Trimmed=0KB
07-25 17:17:50.967: E/AndroidRuntime_2_crash(3008): crash in the same process: main
07-25 17:17:50.967: E/AndroidRuntime_2_crash(3008): java.lang.OutOfMemoryError: (Heap Size=65571KB, Allocated=63787KB)
07-25 17:17:50.967: E/AndroidRuntime_2_crash(3008): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
07-25 17:17:50.967: E/AndroidRuntime_2_crash(3008): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:626)
07-25 17:17:50.967: E/AndroidRuntime_2_crash(3008): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:473)
07-25 17:17:50.967: E/AndroidRuntime_2_crash(3008): at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:502)
07-25 17:17:50.967: E/AndroidRuntime_2_crash(3008): at com.mimi.ngsbusproject.LuancherActivity.decodeSampledBitmapFromResource(LuancherActivity.java:147)
07-25 17:17:50.967: E/AndroidRuntime_2_crash(3008): at com.mimi.ngsbusproject.LuancherActivity.AnimateandSlideShow(LuancherActivity.java:113)
07-25 17:17:50.967: E/AndroidRuntime_2_crash(3008): at com.mimi.ngsbusproject.LuancherActivity.access$0(LuancherActivity.java:106)
07-25 17:17:50.967: E/AndroidRuntime_2_crash(3008): at com.mimi.ngsbusproject.LuancherActivity$2.run(LuancherActivity.java:84)
And My code here.
final String[] columns = { MediaStore.Images.Media.DATA,
MediaStore.Images.Media._ID };
Cursor image_cursor;
image_cursor = managedQuery(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, columns, null,
null, null);
int image_column_index = image_cursor
.getColumnIndex(MediaStore.Images.Media._ID);
count = image_cursor.getCount();
thumbnails = new Bitmap[count];
arrPath = new String[count];
try {
for (int i = 0; i < count; i++) {
image_cursor.moveToPosition(i);
int id = image_cursor.getInt(image_column_index);
int dataColumnIndex = image_cursor
.getColumnIndex(MediaStore.Images.Media.DATA);
thumbnails[i] = MediaStore.Images.Thumbnails.getThumbnail(
getApplicationContext().getContentResolver(), id,
MediaStore.Images.Thumbnails.MINI_KIND, null);
arrPath[i] = image_cursor.getString(dataColumnIndex);
}
} catch (Exception e) {
e.printStackTrace();
}
Sorry for my language. Thanks.
Your Part:
count = image_cursor.getCount();
thumbnails = new Bitmap[count];
May cause this. For creating Bitmaps memory-efficient you should use BitmapOptions
Try THIS instead:
Bitmap bm;
bm = Bitmap.createScaledBitmap(BitmapFactory.decodeFile(filepath),100, 100, true);
mPicture = new ImageView(context);
mPicture.setImageBitmap(bm);
See
Strange out of memory issue while loading an image to a Bitmap object
Seems like these both logs may give you the hint:
failed to allocate memory for thumbnail
content://media/external/images/thumbnails/300;
.
android.graphics.BitmapFactory.nativeDecodeByteArray(Native Method)
07-25 17:17:49.327: E/AndroidRuntime(3008): at
android.graphics.BitmapFactory.decodeByteArray(BitmapFactory.java:552)
07-25 17:17:49.327: E/AndroidRuntime(3008): at
android.media.ThumbnailUtils.createThumbnailFromEXIF
Does your gallery contain a lot of big pictures?
In this case you dont have a problem with your Cursor but with your memory management when it comes to bitmaps!
Furthermore you should have this permission in your manifest:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
See also
http://developer.android.com/training/displaying-bitmaps/load-bitmap.html
Add this to your Manifest
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
As for the the out of memory i used to get this when i have very large images in size, try to
test it in small images ..
my advice to all , try dont use large image size use https://tinypng.com/ to decrease the image size
Second increase heap size from mainfest android:largeHeap="true" in application tag to be like this
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme"
android:largeHeap="true">
and bundle max heap size
android {
compileSdkVersion 23
buildToolsVersion '23.0.0'
.......
....
dexOptions {
javaMaxHeapSize "4g"
}
}
I hope this help
Add
android:largeHeap="true"
in your Manifest application tag.

requestFeature() must be called before adding error

This one I do not understand at all, I am trying to display a custom dialog with no title like this
d.setContentView(R.layout.incident_dialog_layout);
d.requestWindowFeature(Window.FEATURE_NO_TITLE);
doing this gives me an error
07-25 11:56:23.737: E/AndroidRuntime(15680): android.util.AndroidRuntimeException: requestFeature() must be called before adding content
07-25 11:56:23.737: E/AndroidRuntime(15680): at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:215)
07-25 11:56:23.737: E/AndroidRuntime(15680): at android.app.Dialog.requestWindowFeature(Dialog.java:1031)
07-25 11:56:23.737: E/AndroidRuntime(15680): at ecm2.android.MainActivity.createNewDialog(MainActivity.java:1121)
07-25 11:56:23.737: E/AndroidRuntime(15680): at ecm2.android.MainActivity$ListViews.onListItemClick(MainActivity.java:614)
07-25 11:56:23.737: E/AndroidRuntime(15680): at android.support.v4.app.ListFragment$2.onItemClick(ListFragment.java:58)
07-25 11:56:23.737: E/AndroidRuntime(15680): at android.widget.AdapterView.performItemClick(AdapterView.java:298)
07-25 11:56:23.737: E/AndroidRuntime(15680): at android.widget.AbsListView.performItemClick(AbsListView.java:1086)
07-25 11:56:23.737: E/AndroidRuntime(15680): at android.widget.AbsListView$PerformClick.run(AbsListView.java:2855)
07-25 11:56:23.737: E/AndroidRuntime(15680): at android.widget.AbsListView$1.run(AbsListView.java:3529)
07-25 11:56:23.737: E/AndroidRuntime(15680): at android.os.Handler.handleCallback(Handler.java:615)
07-25 11:56:23.737: E/AndroidRuntime(15680): at android.os.Handler.dispatchMessage(Handler.java:92)
07-25 11:56:23.737: E/AndroidRuntime(15680): at android.os.Looper.loop(Looper.java:137)
07-25 11:56:23.737: E/AndroidRuntime(15680): at android.app.ActivityThread.main(ActivityThread.java:4745)
07-25 11:56:23.737: E/AndroidRuntime(15680): at java.lang.reflect.Method.invokeNative(Native Method)
07-25 11:56:23.737: E/AndroidRuntime(15680): at java.lang.reflect.Method.invoke(Method.java:511)
07-25 11:56:23.737: E/AndroidRuntime(15680): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
07-25 11:56:23.737: E/AndroidRuntime(15680): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
07-25 11:56:23.737: E/AndroidRuntime(15680): at dalvik.system.NativeStart.main(Native Method)
ok that simple enough just change where the request is. So I then change it to this
d.requestWindowFeature(Window.FEATURE_NO_TITLE);
d.setContentView(R.layout.incident_dialog_layout);
dialog works until I start a new activity when I go back and click on the item that creates the dialog I get this error
07-25 11:51:19.182: E/AndroidRuntime(15376): android.util.AndroidRuntimeException: requestFeature() must be called before adding content
07-25 11:51:19.182: E/AndroidRuntime(15376): at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:215)
07-25 11:51:19.182: E/AndroidRuntime(15376): at android.app.Dialog.requestWindowFeature(Dialog.java:1031)
07-25 11:51:19.182: E/AndroidRuntime(15376): at ecm2.android.MainActivity.createNewDialog(MainActivity.java:1120)
07-25 11:51:19.182: E/AndroidRuntime(15376): at ecm2.android.MainActivity$ListViews.onListItemClick(MainActivity.java:614)
07-25 11:51:19.182: E/AndroidRuntime(15376): at android.support.v4.app.ListFragment$2.onItemClick(ListFragment.java:58)
07-25 11:51:19.182: E/AndroidRuntime(15376): at android.widget.AdapterView.performItemClick(AdapterView.java:298)
07-25 11:51:19.182: E/AndroidRuntime(15376): at android.widget.AbsListView.performItemClick(AbsListView.java:1086)
07-25 11:51:19.182: E/AndroidRuntime(15376): at android.widget.AbsListView$PerformClick.run(AbsListView.java:2855)
07-25 11:51:19.182: E/AndroidRuntime(15376): at android.widget.AbsListView$1.run(AbsListView.java:3529)
07-25 11:51:19.182: E/AndroidRuntime(15376): at android.os.Handler.handleCallback(Handler.java:615)
07-25 11:51:19.182: E/AndroidRuntime(15376): at android.os.Handler.dispatchMessage(Handler.java:92)
07-25 11:51:19.182: E/AndroidRuntime(15376): at android.os.Looper.loop(Looper.java:137)
07-25 11:51:19.182: E/AndroidRuntime(15376): at android.app.ActivityThread.main(ActivityThread.java:4745)
07-25 11:51:19.182: E/AndroidRuntime(15376): at java.lang.reflect.Method.invokeNative(Native Method)
07-25 11:51:19.182: E/AndroidRuntime(15376): at java.lang.reflect.Method.invoke(Method.java:511)
07-25 11:51:19.182: E/AndroidRuntime(15376): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
07-25 11:51:19.182: E/AndroidRuntime(15376): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
07-25 11:51:19.182: E/AndroidRuntime(15376): at dalvik.system.NativeStart.main(Native Method)
so what does it want me to do then since I cant have it after I set the content nore can I have it before I sent the content?????
You are getting that error because the second time you set the dialog layout(this is, when you come back from the second activity), you already have content in your screen.
So, calling requestWindowFeature this second time causes the error.
You'll have to move that statement to onCreate() method, hence only one time is called requestFeature, ensuring no content is added before its call.
Based on the second comment on the question, I would guess that you are calling requestFeature() in the onStart or onResume methods.
requestFeature, as well as setContentView, should called in onCreate(). if you do it anywhere else it will get called again and cause your app to throw an error.

How to Give Assets Folder Path for Playing mp4 video?

How to Give Assets Folder Path for Playing mp4 video? I am Using Following Code for that.
Please Help me.
String stringPath = "file:///android_asset/sample.mp4";
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setDisplay(surfaceHolder);
mediaPlayer.setDataSource(stringPath);
mediaPlayer.prepare();
mediaPlayer.start();
But Above Code is Give me Following Warnings & Errors.
07-25 13:11:40.833: ERROR/MediaPlayer(11295): error (1, -2147483648)
07-25 13:11:40.833: WARN/System.err(11295): java.io.IOException: Prepare failed.: status=0x1
07-25 13:11:41.103: WARN/System.err(11295): at android.media.MediaPlayer.prepare(Native Method)
07-25 13:11:41.103: WARN/System.err(11295): at com.arthisoft.tempforvideo2.AndroidVideoPlayer.playvideo(AndroidVideoPlayer.java:69)
07-25 13:11:41.103: WARN/System.err(11295): at com.arthisoft.tempforvideo2.AndroidVideoPlayer$2.onClick(AndroidVideoPlayer.java:52)
07-25 13:11:41.113: WARN/System.err(11295): at android.view.View.performClick(View.java:2408)
07-25 13:11:41.113: WARN/System.err(11295): at android.view.View$PerformClick.run(View.java:8816)
07-25 13:11:41.123: WARN/System.err(11295): at android.os.Handler.handleCallback(Handler.java:587)
07-25 13:11:41.123: WARN/System.err(11295): at android.os.Handler.dispatchMessage(Handler.java:92)
07-25 13:11:41.123: WARN/System.err(11295): at android.os.Looper.loop(Looper.java:123)
07-25 13:11:41.134: WARN/System.err(11295): at android.app.ActivityThread.main(ActivityThread.java:4627)
07-25 13:11:41.143: WARN/System.err(11295): at java.lang.reflect.Method.invokeNative(Native Method)
07-25 13:11:41.143: WARN/System.err(11295): at java.lang.reflect.Method.invoke(Method.java:521)
07-25 13:11:41.143: WARN/System.err(11295): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-25 13:11:41.153: WARN/System.err(11295): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-25 13:11:41.153: WARN/System.err(11295): at dalvik.system.NativeStart.main(Native Method)
07-25 13:11:41.153: ERROR/MediaPlayer(11295): start called in state 0
07-25 13:11:41.163: ERROR/MediaPlayer(11295): error (-38, 0)
07-25 13:11:41.243: ERROR/MediaPlayer(11295): Error (-38,0)
Move the .mp4 file to raw/ folder. Then, replace your string with this:
String stringPath = "android.resource://[your_package_name]/raw/sample"
Please specify your location is in the sd card or in the internal storage. If it is in the sd card then it will be:
String stringPath = "/sdcard/android_asset/sample.mp4";
You have to do something like this
mediaPlayer.setDataSource(AndroidVideoPlayer.this, Uri
.parse("android.resource://com.arthisoft.tempforvideo2/R.raw.sample"));

Categories

Resources