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.
Related
Thank you guys! The reason is somewhere simpler than I think. I feel something futility.. :
-)
I have already added activity names on androidmanifest.xml.
My code is simple.
Intent intent=new Intent(MainActivity.this, AddAddressActivity.class);
intent.putExtra("respond", responsebody);
intent.putExtra("userid", txtID.getText().toString());
intent.putExtra("password", txtPW.getText().toString());
MainActivity.this.startActivity(intent);
just this.
Why are crashes caused in this code? I can't find on it.
But the more stranger thing is that crash aren't caused when I make AddAddressActivity like basic templete(source when it is made at first).
Then, is AddAddressActivity a problem?
Thanks to read my question. You could misunderstand it because of my short english. If you have something hard to understand, please ask me on comment.
Here is Logcat. I can't find reason in this text..
02-28 02:42:53.876: D/dalvikvm(6195): GC_FOR_ALLOC freed 122K, 19% free 9983K/12192K, paused 17ms, total 17ms
02-28 02:42:53.886: I/dalvikvm-heap(6195): Grow heap (frag case) to 15.536MB for 3936016-byte allocation
02-28 02:42:53.901: D/dalvikvm(6195): GC_FOR_ALLOC freed <1K, 14% free 13826K/16036K, paused 13ms, total 13ms
02-28 02:42:54.011: D/dalvikvm(6195): GC_FOR_ALLOC freed <1K, 14% free 13826K/16036K, paused 9ms, total 9ms
02-28 02:42:54.031: I/dalvikvm-heap(6195): Grow heap (frag case) to 30.549MB for 15744016-byte allocation
02-28 02:42:54.041: D/dalvikvm(6195): GC_FOR_ALLOC freed 0K, 8% free 29201K/31412K, paused 11ms, total 11ms
02-28 02:42:54.201: D/libEGL(6195): loaded /system/lib/egl/libEGL_mali.so
02-28 02:42:54.201: D/libEGL(6195): loaded /system/lib/egl/libGLESv1_CM_mali.so
02-28 02:42:54.206: D/libEGL(6195): loaded /system/lib/egl/libGLESv2_mali.so
02-28 02:42:54.211: E/(6195): Device driver API match
02-28 02:42:54.211: E/(6195): Device driver API version: 23
02-28 02:42:54.211: E/(6195): User space API version: 23
02-28 02:42:54.211: E/(6195): mali: REVISION=Linux-r3p2-01rel3 BUILD_DATE=Wed Oct 30 09:36:10 KST 2013
02-28 02:42:54.276: D/OpenGLRenderer(6195): Enabling debug mode 0
02-28 02:43:02.696: I/webclipboard(6195): clipservice: android.sec.clipboard.ClipboardExManager#4419e048
02-28 02:43:02.711: D/AndroidRuntime(6195): Shutting down VM
02-28 02:43:02.711: W/dalvikvm(6195): threadid=1: thread exiting with uncaught exception (group=0x420ac700)
02-28 02:43:02.721: E/AndroidRuntime(6195): FATAL EXCEPTION: main
02-28 02:43:02.721: E/AndroidRuntime(6195): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mcdelivery/com.example.mcdelivery.AddAddressActivity}: java.lang.NullPointerException
02-28 02:43:02.721: E/AndroidRuntime(6195): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2308)
02-28 02:43:02.721: E/AndroidRuntime(6195): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2362)
02-28 02:43:02.721: E/AndroidRuntime(6195): at android.app.ActivityThread.access$700(ActivityThread.java:168)
02-28 02:43:02.721: E/AndroidRuntime(6195): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1329)
02-28 02:43:02.721: E/AndroidRuntime(6195): at android.os.Handler.dispatchMessage(Handler.java:99)
02-28 02:43:02.721: E/AndroidRuntime(6195): at android.os.Looper.loop(Looper.java:137)
02-28 02:43:02.721: E/AndroidRuntime(6195): at android.app.ActivityThread.main(ActivityThread.java:5493)
02-28 02:43:02.721: E/AndroidRuntime(6195): at java.lang.reflect.Method.invokeNative(Native Method)
02-28 02:43:02.721: E/AndroidRuntime(6195): at java.lang.reflect.Method.invoke(Method.java:525)
02-28 02:43:02.721: E/AndroidRuntime(6195): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1209)
02-28 02:43:02.721: E/AndroidRuntime(6195): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1025)
02-28 02:43:02.721: E/AndroidRuntime(6195): at dalvik.system.NativeStart.main(Native Method)
02-28 02:43:02.721: E/AndroidRuntime(6195): Caused by: java.lang.NullPointerException
02-28 02:43:02.721: E/AndroidRuntime(6195): at com.example.mcdelivery.AddAddressActivity.onCreate(AddAddressActivity.java:18)
02-28 02:43:02.721: E/AndroidRuntime(6195): at android.app.Activity.performCreate(Activity.java:5372)
02-28 02:43:02.721: E/AndroidRuntime(6195): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)
02-28 02:43:02.721: E/AndroidRuntime(6195): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2270)
02-28 02:43:02.721: E/AndroidRuntime(6195): ... 11 more
02-28 02:43:02.751: V/webkit(6195): BrowserFrame constructor: this=Handler (android.webkit.BrowserFrame) {4419b1f0}
AddAddressActivity.java
package com.example.mcdelivery;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.webkit.WebView;
public class AddAddressActivity extends Activity {
WebView webview;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_addaddress);
Intent intent=new Intent(this.getIntent());
webview.loadUrl("https://www.mcdelivery.co.kr/kr/jsp/sys/customerLogin.do?userName=" + intent.getStringExtra("username") + "&password=" + intent.getStringExtra("password") + "&imgLogin.x=0&imgLogin.y=0");
}
}
webView gives a NPE on this line
webview.loadUrl("https://www.mcdelivery.co.kr/kr/jsp/sys/customerLogin.do?userName=" + intent.getStringExtra("username") + "&password=" + intent.getStringExtra("password") + "&imgLogin.x=0&imgLogin.y=0");
Because you haven't yet initialized it. You only declare it
WebView webview;
Somewhere (before that line and after setContentView()) you need to initialize it
You have only declared WebView not initialized it
setContentView(R.layout.activity_addaddress);
webview =(WebView)findViewById(R.id.webView); //missing
Intent intent= getIntent();
webview.loadUrl("https://www.mcdelivery.co.kr/kr/jsp/sys/customerLogin.do?userName=" + intent.getStringExtra("username") + "&password=" + intent.getStringExtra("password") + "&imgLogin.x=0&imgLogin.y=0");
I think that's from a bad handling of the Context belonging to your app.
Replace
Intent intent=new Intent(MainActivity.this, AddAddressActivity.class);
with
Intent intent=new Intent(this, AddAddressActivity.class); .
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.
I can't show alert dialog. Everything is right until I set the method dialog.show(), then I can't open my application. Without this method everything is fine.
I declared two global objects:
AlertDialog.Builder builder;
AlertDialog dialog;
Then in MainActivity, I build a dialog by builder and create it.
builder = new AlertDialog.Builder(this.getApplicationContext());
builder.setMessage("We're sorry, but on Your device accelerometer isn't available")
.setCancelable(false)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which)
{
MainActivity.this.finish();
}
});
dialog = builder.create();
To this moment everything works and there's no any exceptions, but when I want to show the dialog, some exceptions appear and I can't run this application:
dialog.show(); //this method doesn't work and causes problems
What did I do wrong?
EDIT:
Exceptions:
06-26 20:49:03.540: D/dalvikvm(4085): GC_FOR_ALLOC freed 38K, 8% free 2499K/2712K, paused 42ms, total 45ms
06-26 20:49:03.580: I/dalvikvm-heap(4085): Grow heap (frag case) to 6.146MB for 3712016-byte allocation
06-26 20:49:03.700: D/dalvikvm(4085): GC_FOR_ALLOC freed 2K, 4% free 6121K/6340K, paused 112ms, total 112ms
06-26 20:49:03.770: D/dalvikvm(4085): GC_CONCURRENT freed <1K, 4% free 6121K/6340K, paused 6ms+16ms, total 71ms
06-26 20:49:04.460: D/gralloc_goldfish(4085): Emulator without GPU emulation detected.
06-26 20:49:42.030: E/Trace(4138): error opening trace file: No such file or directory (2)
06-26 20:49:42.900: D/dalvikvm(4138): GC_FOR_ALLOC freed 41K, 8% free 2499K/2716K, paused 66ms, total 68ms
06-26 20:49:42.940: I/dalvikvm-heap(4138): Grow heap (frag case) to 6.146MB for 3712016-byte allocation
06-26 20:49:43.050: D/dalvikvm(4138): GC_FOR_ALLOC freed 2K, 4% free 6121K/6344K, paused 107ms, total 107ms
06-26 20:49:43.120: D/dalvikvm(4138): GC_CONCURRENT freed <1K, 4% free 6121K/6344K, paused 5ms+5ms, total 70ms
06-26 20:49:43.540: D/dalvikvm(4138): GC_FOR_ALLOC freed 3638K, 53% free 3483K/7300K, paused 36ms, total 37ms
06-26 20:49:43.621: D/AndroidRuntime(4138): Shutting down VM
06-26 20:49:43.630: W/dalvikvm(4138): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
06-26 20:49:43.640: E/AndroidRuntime(4138): FATAL EXCEPTION: main
06-26 20:49:43.640: E/AndroidRuntime(4138): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.accelerometertest/com.example.accelerometertest.MainActivity}: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
06-26 20:49:43.640: E/AndroidRuntime(4138): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
06-26 20:49:43.640: E/AndroidRuntime(4138): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
06-26 20:49:43.640: E/AndroidRuntime(4138): at android.app.ActivityThread.access$600(ActivityThread.java:141)
06-26 20:49:43.640: E/AndroidRuntime(4138): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
06-26 20:49:43.640: E/AndroidRuntime(4138): at android.os.Handler.dispatchMessage(Handler.java:99)
06-26 20:49:43.640: E/AndroidRuntime(4138): at android.os.Looper.loop(Looper.java:137)
06-26 20:49:43.640: E/AndroidRuntime(4138): at android.app.ActivityThread.main(ActivityThread.java:5041)
06-26 20:49:43.640: E/AndroidRuntime(4138): at java.lang.reflect.Method.invokeNative(Native Method)
06-26 20:49:43.640: E/AndroidRuntime(4138): at java.lang.reflect.Method.invoke(Method.java:511)
06-26 20:49:43.640: E/AndroidRuntime(4138): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
06-26 20:49:43.640: E/AndroidRuntime(4138): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
06-26 20:49:43.640: E/AndroidRuntime(4138): at dalvik.system.NativeStart.main(Native Method)
06-26 20:49:43.640: E/AndroidRuntime(4138): Caused by: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
06-26 20:49:43.640: E/AndroidRuntime(4138): at android.view.ViewRootImpl.setView(ViewRootImpl.java:571)
06-26 20:49:43.640: E/AndroidRuntime(4138): at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:246)
06-26 20:49:43.640: E/AndroidRuntime(4138): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
06-26 20:49:43.640: E/AndroidRuntime(4138): at android.app.Dialog.show(Dialog.java:281)
06-26 20:49:43.640: E/AndroidRuntime(4138): at com.example.accelerometertest.MainActivity.onCreate(MainActivity.java:67)
06-26 20:49:43.640: E/AndroidRuntime(4138): at android.app.Activity.performCreate(Activity.java:5104)
06-26 20:49:43.640: E/AndroidRuntime(4138): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
06-26 20:49:43.640: E/AndroidRuntime(4138): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
06-26 20:49:43.640: E/AndroidRuntime(4138): ... 11 more
change
builder = new AlertDialog.Builder(this.getApplicationContext());
to (As long as thisis your MainActivity )
builder = new AlertDialog.Builder(this);
I'm currently try to run some opencv filters (i.e find egde, Median, ...) on images which are stored in the image gallery folder.
But I get error for loading image. My device is galaxy tab 10.1 with android 3.2, my opencv - API level 8.
I have the following source on a Button:
#Override
public void onClick(View v) {
Bitmap myBitmap = BitmapFactory.decodeFile("/sdcard/image1.jpg");
Bitmap myBitmap32 = myBitmap.copy(Bitmap.Config.ARGB_8888, true);
Mat pic1 = Utils.bitmapToMat(myBitmap32);
}
Here is LogCat:
02-07 12:31:27.290: I/System.out(16522): Not a DRM File, opening notmally
02-07 12:31:27.290: I/System.out(16522): buffer returned
02-07 12:31:27.310: D/dalvikvm(16522): GC_FOR_ALLOC freed 11K, 21% free 6975K/8775K, paused 19ms
02-07 12:31:27.320: I/dalvikvm-heap(16522): Grow heap (frag case) to 12.918MB for 6291472-byte allocation
02-07 12:31:27.340: D/dalvikvm(16522): GC_FOR_ALLOC freed <1K, 13% free 13119K/14983K, paused 19ms
02-07 12:31:27.380: D/dalvikvm(16522): GC_CONCURRENT freed 0K, 13% free 13119K/14983K, paused 2ms+2ms
02-07 12:31:27.710: D/dalvikvm(16522): GC_FOR_ALLOC freed 55K, 13% free 13063K/14983K, paused 20ms
02-07 12:31:27.730: I/dalvikvm-heap(16522): Grow heap (frag case) to 24.864MB for 12582928-byte allocation
02-07 12:31:27.780: D/dalvikvm(16522): GC_FOR_ALLOC freed 0K, 8% free 25351K/27335K, paused 21ms
02-07 12:31:27.830: D/dalvikvm(16522): GC_CONCURRENT freed <1K, 8% free 25351K/27335K, paused 2ms+3ms
02-07 12:31:27.890: W/dalvikvm(16522): Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lorg/opencv/android/Utils;
02-07 12:31:27.890: D/AndroidRuntime(16522): Shutting down VM
02-07 12:31:27.890: W/dalvikvm(16522): threadid=1: thread exiting with uncaught exception (group=0x400fc760)
02-07 12:31:27.890: E/AndroidRuntime(16522): FATAL EXCEPTION: main
02-07 12:31:27.890: E/AndroidRuntime(16522): java.lang.ExceptionInInitializerError
02-07 12:31:27.890: E/AndroidRuntime(16522): at photo.klu.PhotoKLUActivity$1.onClick(PhotoKLUActivity.java:82)
02-07 12:31:27.890: E/AndroidRuntime(16522): at android.view.View.performClick(View.java:3127)
02-07 12:31:27.890: E/AndroidRuntime(16522): at android.view.View$PerformClick.run(View.java:12025)
02-07 12:31:27.890: E/AndroidRuntime(16522): at android.os.Handler.handleCallback(Handler.java:587)
02-07 12:31:27.890: E/AndroidRuntime(16522): at android.os.Handler.dispatchMessage(Handler.java:92)
02-07 12:31:27.890: E/AndroidRuntime(16522): at android.os.Looper.loop(Looper.java:132)
02-07 12:31:27.890: E/AndroidRuntime(16522): at android.app.ActivityThread.main(ActivityThread.java:4126)
02-07 12:31:27.890: E/AndroidRuntime(16522): at java.lang.reflect.Method.invokeNative(Native Method)
02-07 12:31:27.890: E/AndroidRuntime(16522): at java.lang.reflect.Method.invoke(Method.java:491)
02-07 12:31:27.890: E/AndroidRuntime(16522): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844)
02-07 12:31:27.890: E/AndroidRuntime(16522): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
02-07 12:31:27.890: E/AndroidRuntime(16522): at dalvik.system.NativeStart.main(Native Method)
02-07 12:31:27.890: E/AndroidRuntime(16522): Caused by: java.lang.UnsatisfiedLinkError: Couldn't load opencv_java: findLibrary returned null
02-07 12:31:27.890: E/AndroidRuntime(16522): at java.lang.Runtime.loadLibrary(Runtime.java:425)
02-07 12:31:27.890: E/AndroidRuntime(16522): at java.lang.System.loadLibrary(System.java:554)
02-07 12:31:27.890: E/AndroidRuntime(16522): at org.opencv.android.Utils.<clinit>(Utils.java:86)
02-07 12:31:27.890: E/AndroidRuntime(16522): ... 12 more
02-07 12:31:30.010: I/dalvikvm(16522): threadid=4: reacting to signal 3
02-07 12:31:30.010: I/dalvikvm(16522): Wrote stack traces to '/data/anr/traces.txt'
02-07 12:31:37.470: I/Process(16522): Sending signal. PID: 16522 SIG: 9
Any ideas?
Thank you.
The openCV library is not attached to your application. Please do the following (i assume that the openCV library is imported to your workspace). On Package Explorer > Right click on the application project > properties > under Library click Add > select openCV Be sure that on Java Build Path you don't have anything related to openCV
I'm designing an application that allows the user to retrieve his data from the server, I'm furnishing this using two different activities, the first one receives the username as a text input and the second one displays the user's data based on the username. I'm using JSON schema for storing and retrieving the data. The app works fine for the first time but when I logout from the second screen using finish() and try to re-enter a new username in the first screen "the app force closes". This has been giving me sleepless nights, want to be overwhelmed with your support.
12-04 16:28:35.289: D/dalvikvm(553): GC_FOR_ALLOC freed 64K, 4% free 6893K/7171K, paused 64ms
12-04 16:28:35.299: I/dalvikvm-heap(553): Grow heap (frag case) to 7.757MB for 1000016-byte allocation
12-04 16:28:35.399: D/dalvikvm(553): GC_CONCURRENT freed 1K, 5% free 7868K/8199K, paused 16ms+3ms
12-04 16:28:35.529: D/dalvikvm(553): GC_FOR_ALLOC freed <1K, 5% free 7869K/8199K, paused 31ms
12-04 16:28:35.539: I/dalvikvm-heap(553): Grow heap (frag case) to 8.180MB for 443572-byte allocation
12-04 16:28:35.589: D/dalvikvm(553): GC_CONCURRENT freed 0K, 4% free 8302K/8647K, paused 3ms+5ms
12-04 16:28:35.889: D/gralloc_goldfish(553): Emulator without GPU emulation detected.
12-04 16:29:16.819: D/dalvikvm(553): GC_FOR_ALLOC freed 1079K, 14% free 7509K/8711K, paused 221ms
12-04 16:29:16.829: I/dalvikvm-heap(553): Grow heap (frag case) to 8.360MB for 1000016-byte allocation
12-04 16:29:16.889: D/dalvikvm(553): GC_CONCURRENT freed 2K, 3% free 8483K/8711K, paused 4ms+4ms
12-04 16:29:17.229: D/dalvikvm(553): GC_CONCURRENT freed 1016K, 13% free 7979K/9159K, paused 3ms+11ms
12-04 16:29:18.149: E/log_tag(553): Error parsing data org.json.JSONException: No value for Alert
12-04 16:29:20.949: D/dalvikvm(553): GC_CONCURRENT freed 274K, 12% free 8090K/9159K, paused 6ms+5ms
12-04 16:29:26.259: E/log_tag(553): Error parsing data org.json.JSONException: No value for Alert
12-04 16:29:26.859: D/AndroidRuntime(553): Shutting down VM
12-04 16:29:26.859: W/dalvikvm(553): threadid=1: thread exiting with uncaught exception (group=0x409951f8)
12-04 16:29:26.929: E/AndroidRuntime(553): FATAL EXCEPTION: main
12-04 16:29:26.929: E/AndroidRuntime(553): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.bombil.kustomizer/com.bombil.kustomizer.Menus}: java.lang.IndexOutOfBoundsException: Invalid index 2, size is 2
12-04 16:29:26.929: E/AndroidRuntime(553): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
12-04 16:29:26.929: E/AndroidRuntime(553): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
12-04 16:29:26.929: E/AndroidRuntime(553): at android.app.ActivityThread.access$600(ActivityThread.java:122)
12-04 16:29:26.929: E/AndroidRuntime(553): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
12-04 16:29:26.929: E/AndroidRuntime(553): at android.os.Handler.dispatchMessage(Handler.java:99)
12-04 16:29:26.929: E/AndroidRuntime(553): at android.os.Looper.loop(Looper.java:137)
12-04 16:29:26.929: E/AndroidRuntime(553): at android.app.ActivityThread.main(ActivityThread.java:4340)
12-04 16:29:26.929: E/AndroidRuntime(553): at java.lang.reflect.Method.invokeNative(Native Method)
12-04 16:29:26.929: E/AndroidRuntime(553): at java.lang.reflect.Method.invoke(Method.java:511)
12-04 16:29:26.929: E/AndroidRuntime(553): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
12-04 16:29:26.929: E/AndroidRuntime(553): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
12-04 16:29:26.929: E/AndroidRuntime(553): at dalvik.system.NativeStart.main(Native Method)
12-04 16:29:26.929: E/AndroidRuntime(553): Caused by: java.lang.IndexOutOfBoundsException: Invalid index 2, size is 2
12-04 16:29:26.929: E/AndroidRuntime(553): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:251)
12-04 16:29:26.929: E/AndroidRuntime(553): at java.util.ArrayList.get(ArrayList.java:304)
12-04 16:29:26.929: E/AndroidRuntime(553): at com.bombil.kustomizer.Menus.AddEditText(Menus.java:309)
12-04 16:29:26.929: E/AndroidRuntime(553): at com.bombil.kustomizer.Menus.AddInsertView(Menus.java:121)
12-04 16:29:26.929: E/AndroidRuntime(553): at com.bombil.kustomizer.Menus.onCreate(Menus.java:88)
12-04 16:29:26.929: E/AndroidRuntime(553): at android.app.Activity.performCreate(Activity.java:4465)
12-04 16:29:26.929: E/AndroidRuntime(553): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
12-04 16:29:26.929: E/AndroidRuntime(553): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
12-04 16:29:26.929: E/AndroidRuntime(553): ... 11 more
12-04 16:29:27.009: D/dalvikvm(553): GC_CONCURRENT freed 273K, 10% free 8248K/9159K, paused 4ms+6ms
12-04 16:32:56.799: I/Process(553): Sending signal. PID: 553 SIG: 9
Apparently, you're trying to access an object in an ArrayList at in your Menus.java file at line 309. You're trying to access the object with the index of 2, but the total ArrayList size is only 2, meaning the highest index would be 1. This causes an IndexOutOfBounds exception as shown here:
ComponentInfo{com.bombil.kustomizer/com.bombil.kustomizer.Menus}:
java.lang.IndexOutOfBoundsException: Invalid index 2, size is 2
E/AndroidRuntime(553): at com.bombil.kustomizer.Menus.AddEditText(Menus.java:309)
Do you have any objects that are being used by both activities? I know I saw this issue once with a project. One of the activities was messing up the HTTPClient object for the other activity. If you are getting a null exception being thrown try and find the variable. If it is a shared resource for both activities then just make sure to deal with it in a clean way when you exit the second activity.