Android 'Spinning Wheel' application crashes at launch - java

I've taken a code from a tutorial about a spinning wheel.
I've adjusted the code to work from my application but it's crashing for some reason and I can't figure out why.
I'll really appreciate any kind of help.
The logcat information is :
com.truthordareyakir.android.truthordare E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.truthordareyakir.android.truthordare, PID: 2404
java.lang.OutOfMemoryError: Failed to allocate a 37748748 byte allocation with 4194304 free bytes and 27MB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:609)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444)
at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:467)
at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:497)
at com.truthordareyakir.android.truthordare.MainActivity.onCreate(MainActivity.java:45)
at android.app.Activity.performCreate(Activity.java:5937)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

Sounds to me like your animated image is too large. You have have separate sized images for each drawable type? hdpi, mdpi, xhdpi, etc...
Use the Android Asset Studio to scale images if needed.

Have you tried to initialise the byte with a lower value ?
Sometimes the Memory of your phone can't process such high va. lues.

Related

Cannot capture image in the second time - Android

im using kevalpatel2106's android hidden camera library.
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.exampleapp, PID: 10608
java.lang.RuntimeException: takePicture failed
at android.hardware.Camera.native_takePicture(Native Method)
at android.hardware.Camera.takePicture(Camera.java:1865)
at android.hardware.Camera.takePicture(Camera.java:1806)
at com.androidhiddencamera.CameraPreview.takePictureInternal(CameraPreview.java:196)
at com.androidhiddencamera.HiddenCameraActivity.takePicture(HiddenCameraActivity.java:92)
at com.example.exampleapp.MainActivity.lambda$onCreate$3$MainActivity(MainActivity.java:152)
at com.example.exampleapp.MainActivity$$ExternalSyntheticLambda4.run(Unknown Source:2)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7888)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:981)
when the application instance taking picture the first time it works fine, but in the second time it throws me this error.
I'm using LGE LM-K520 device android 11.
this is the code:
findViewById(R.id.pic).setOnClickListener((a) -> takePicture());
this is my config:
mCameraConfig = new CameraConfig()
.getBuilder(MainActivity.this)
.setCameraFacing(CameraFacing.REAR_FACING_CAMERA)
.setCameraResolution(CameraResolution.HIGH_RESOLUTION)
.setImageFormat(CameraImageFormat.FORMAT_JPEG)
.setImageRotation(CameraRotation.ROTATION_90)
.build();
Thank You!!!

Android Studio Weather Application Crashing

So, I have been following a YouTube tutorial for an android Weather application. The app seems to compile, however crashes whenever opened on the emulator. I'm not the most fluent programmer, however the code is understood. I can't figure out what's causing the issue though. The app is supposed to fetch weather data for the location of the hardcoded location in "MainActivity.java". The data is fetched from Yahoo! using an API.
Link for the project files: https://drive.google.com/drive/folders/0B2dQ9-JQjysVeXlqZENBZDExN0E?usp=sharing
Below is the error I get:
--------- beginning of crash
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.mattbenson.cw_2_weather, PID: 2529
java.lang.NullPointerException: Attempt to invoke virtual method 'int org.json.JSONObject.optInt(java.lang.String)' on a null object reference
at com.example.mattbenson.cw_2_weather.service.WeatherService$1.onPostExecute(WeatherService.java:81)
at com.example.mattbenson.cw_2_weather.service.WeatherService$1.onPostExecute(WeatherService.java:38)
at android.os.AsyncTask.finish(AsyncTask.java:667)
at android.os.AsyncTask.-wrap1(AsyncTask.java)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:684)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
E/Surface: queueBuffer: error queuing buffer to SurfaceTexture, -19
E/EGL_emulation: tid 2570: swapBuffers(487): error 0x300d (EGL_BAD_SURFACE)
W/OpenGLRenderer: swapBuffers encountered EGL error 12301 on 0x76990bb1c580, halting rendering...
Application terminated.
(Sorry, I am new to this site!)
Any help is greatly appreciated.
As StackTrace says the error is at Class WeatherService at line 81 int count = queryResults.optInt("Count"); because it is returning NULL.
Try using method optInt with fallback value queryResults.optInt("Count", 0);

java.lang.OutofMemoryError issues [duplicate]

This question already has an answer here:
java.lang.OutOfMemoryError: Failed to allocate a 31961100 byte allocation with 15257484 free bytes and 14MB until OOM
(1 answer)
Closed 6 years ago.
I'm developing a little game app for my collage project. The moment I'm at the point that my app runs smoothly for the first and second round it crashes after that along with this error java.lang.OutofMemoryError. I can't find the issue to this problem.
if (pic == null)
pic = BitmapFactory.decodeResource(context.getResources(), R.drawable.background);
scalepic = Bitmap.createScaledBitmap(pic, 720, 3840, false);
pic.recycle();
background = new Background(scalepic);
and this is the error:
java.lang.OutOfMemoryError: Failed to allocate a 117964812 byte allocation with 16777216 free bytes and 18MB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:856)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:675)
at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:703)
at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:733)
at de.hs_kl.imst.gatav.runner.GameView.<init>(GameView.java:88)
at de.hs_kl.imst.gatav.runner.Start.onCreate(Start.java:39)
at android.app.Activity.performCreate(Activity.java:6876)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3207)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3350)
at android.app.ActivityThread.access$1100(ActivityThread.java:222)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1795)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7229)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
if i erase the recycle, then the game crushes after the first attempt...
You can call System.gc(); method to call garbage collector as you want.

App crash on large string in TextView

I am trying to display 4 long pieces of text (about 250 chars long each) inside a TextView separated by a few images on android. This is inside a fragment which is placed in a scrollView on the Host activity to make it scrollable.
But it throws
java.lang.OutOfMemoryError
I was surprised to see that the app went out of memory by this because the only thing it has to do is display 250 characters and apply word wrap to it. So after googling it I set android:largeHeap to true to see what would happen. The application does load the text but it uses a lot of CPU resources and makes the UI come to a snail phase.
So I am wondering: what I am doing wrong here?
Thanks for reading.
Here is the complete crash:
java.lang.OutOfMemoryError: Failed to allocate a 69120012 byte
allocation with 8388608 free bytes and 10MB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:609)
at
android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444)
at
android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:1080)
at
android.content.res.Resources.loadDrawableForCookie(Resources.java:2730)
at android.content.res.Resources.loadDrawable(Resources.java:2635)
at android.content.res.TypedArray.getDrawable(TypedArray.java:870)
at android.widget.ImageView.(ImageView.java:152)
at android.widget.ImageView.(ImageView.java:140)
at
android.support.v7.widget.AppCompatImageView.(AppCompatImageView.java:57)
at
android.support.v7.widget.AppCompatImageView.(AppCompatImageView.java:53)
at
android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:106)
at
android.support.v7.app.AppCompatDelegateImplV7.createView(AppCompatDelegateImplV7.java:980)
at
android.support.v7.app.AppCompatDelegateImplV7.onCreateView(AppCompatDelegateImplV7.java:1039)
at
android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44)
at
android.view.LayoutInflater$FactoryMerger.onCreateView(LayoutInflater.java:189)
at
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:746)
at
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
at
android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at
nl.evhb.evhbmijnopbrengst.FragmentCoTwoInformation.onCreateView(FragmentCoTwoInformation.java:25)
at
android.support.v4.app.Fragment.performCreateView(Fragment.java:1974)
at
android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
at
android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1252)
at
android.support.v4.app.BackStackRecord.run(BackStackRecord.java:742)
at
android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1617)
at
android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:517)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5461)
at java.lang.reflect.Method.invoke(Native Method)
at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
I am sorry but after looking into the log again I realized that I imported the images on full 1080p resolution which is too much to process for android.graphics.BitmapFactory and that is why it goes out of memory.
I made the images to a mobile friendly size and it worked fine.
OutOfMemoryErrorenter code here error is thrown by the Java Virtual Machine (JVM) when an object cannot be allocated due to lack of memory space and also, the garbage collector cannot free some space.
Try it...
<application
.......................
............
android:largeHeap="true"
>

Card.io java.lang.OutOfMemoryError

Sometimes after the card is captured the app will crash.
java.lang.OutOfMemoryError
at android.graphics.Bitmap.nativeCreate(Bitmap.java)
at android.graphics.Bitmap.createBitmap(Bitmap.java:924)
at android.graphics.Bitmap.createBitmap(Bitmap.java:901)
at android.graphics.Bitmap.createBitmap(Bitmap.java:868)
at io.card.payment.ah.a()
at io.card.payment.CardIOActivity.a()
at io.card.payment.CardScanner.onPreviewFrame()
at android.hardware.Camera$EventHandler.handleMessage(Camera.java:1016)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5579)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
at dalvik.system.NativeStart.main(NativeStart.java)
It happens every time i capture on the Galaxy S5.
Here are the parameters which I'm using to start scan intent:
Intent scanIntent = new Intent(CardInfoActivity.this, CardIOActivity.class);
scanIntent.putExtra(CardIOActivity.EXTRA_APP_TOKEN, Constants.CARD_IO_TOKEN);
scanIntent.putExtra(CardIOActivity.EXTRA_REQUIRE_CVV, true);
scanIntent.putExtra(CardIOActivity.EXTRA_REQUIRE_EXPIRY, true);
scanIntent.putExtra(CardIOActivity.EXTRA_SUPPRESS_CONFIRMATION, true);
scanIntent.putExtra(CardIOActivity.EXTRA_SUPPRESS_MANUAL_ENTRY, true);
startActivityForResult(scanIntent, MY_SCAN_REQUEST_CODE);
Maybe anyone knows how to solve this problem?
Android bitmaps keep the image in native memory, not on the Java heap. If you allocate a bunch of images quickly this can happen, since cleanup only happens when the Java GC runs, which is tied to the Java heap. Ensuring you call bitmap.recycle() when you're done with images you've been working with can help.

Categories