I have a function in my app that adds offline pictures that are stored inside the app's memory to a listview.
The code is extremely simple as you can see:
if(FirstTag != null) {
if (FirstTag.equals("care"))
imageView.setImageDrawable(context.getApplicationContext().getResources().getDrawable(R.drawable.care));
else if (FirstTag.equals("holidays"))
imageView.setImageDrawable(context.getApplicationContext().getResources().getDrawable(R.drawable.holidays));
else if (FirstTag.equals("Thing Different"))
imageView.setImageDrawable(context.getApplicationContext().getResources().getDrawable(R.drawable.thinkdifferent2));
else if (FirstTag.equals("Fun Activities"))
imageView.setImageDrawable(context.getApplicationContext().getResources().getDrawable(R.drawable.fun));
else if (FirstTag.equals("מערך חברות")) }
it simply checks a value in a json object and put a picture in the listview by this value, of course there are 20 values and not 5, but I didn't think I should Include all...
All the pictures are compressed, and when I don't load many of them the app doesn't crash.
But when I try to launch the app with a picture per each item in the listview, everything seems to work perfectly fine, and then when you scroll down the app lags and in a second it crashes with the following error:
9-30 18:35:18.299 7859-7859/com.example.negev.peulibraryv201 E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.negev.peulibraryv201, PID: 7859
java.lang.OutOfMemoryError: Failed to allocate a 681099532 byte allocation with 16777216 free bytes and 261MB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:700)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:535)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:1179)
at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:770)
at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:621)
at android.content.res.Resources.getDrawable(Resources.java:1640)
at android.content.res.Resources.getDrawable(Resources.java:1611)
at com.example.negev.peulibraryv201.GamesLibraryAdapter.getView(GamesLibraryAdapter.java:70)
at android.widget.AbsListView.obtainView(AbsListView.java:3238)
at android.widget.ListView.makeAndAddView(ListView.java:2147)
at android.widget.ListView.fillDown(ListView.java:767)
at android.widget.ListView.fillGap(ListView.java:731)
at android.widget.AbsListView.trackMotionScroll(AbsListView.java:8292)
at android.widget.ListView.trackMotionScroll(ListView.java:2065)
at android.widget.AbsListView$FlingRunnable.run(AbsListView.java:7719)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:927)
at android.view.Choreographer.doCallbacks(Choreographer.java:702)
at android.view.Choreographer.doFrame(Choreographer.java:635)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:913)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6682)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
I already added those line to my manifest:
android:hardwareAccelerated="false"
android:largeHeap="true"
and it didn't work, wht do you think I can do?
Thank you!
What you should do is load the data dynamically as it becomes visible on the screen.
Since this is hard work Google already did it for you.
You need to use an ArrayAdapter with the list view and let Andriod ask you for more data when it is needed.
Its too much code to explain in detail but have a look at this Goolge I/O video.
There are many tutorials on the web that explains how to do that in detail.
Have a look here.
Related
I am trying to open an activity from the Image Cropper library to take images from fragments. When I click on the button to start that activity, the app is crashing and giving that error.
PID: 30654
java.lang.RuntimeException: android.os.TransactionTooLargeException: data parcel size 1714072 bytes
at android.app.servertransaction.PendingTransactionActions$StopInfo.run(PendingTransactionActions.java:160)
Complete Error:
Caused by: android.os.TransactionTooLargeException: data parcel size 1713760 bytes
at android.os.BinderProxy.transactNative(Native Method)
at android.os.BinderProxy.transact(Binder.java:1129)
at android.app.IActivityManager$Stub$Proxy.activityStopped(IActivityManager.java:4027)
at android.app.servertransaction.PendingTransactionActions$StopInfo.run(PendingTransactionActions.java:144)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6762)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
There's a limit on the size of a bundle and the data passed into an Intent. Last I checked (it may have changed) that limit was around 1MB. If you need to pass more data than that, you need to send it in some other manner, such as writing it to a file and sending the filename to the activity instead.
I came to this issue when I was trying to parcel around 4000+ objects while firing another activity with intent. So I strongly feel there's some limit to sending the data via intents.
So the main issue is not with intents it is how you parcel your data before/or at the time of transmitting data.
When the orientation of app change this error is occur kindly help me
W/ActionBarDrawerToggle: DrawerToggle may not show up because NavigationIcon is not visible. You may need to call actionbar.setDisplayHomeAsUpEnabled(true);
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.explore_kpk, PID: 24892
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.explore_kpk/com.example.explore_kpk.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void androidx.recyclerview.widget.RecyclerView.setLayoutManager(androidx.recyclerview.widget.RecyclerView$LayoutManager)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3256)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3352)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:5389)
at android.app.ActivityThread.access$1200(ActivityThread.java:223)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1803)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7231)
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)
***Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void androidx.recyclerview.widget.RecyclerView.setLayoutManager(androidx.recyclerview.widget.RecyclerView$LayoutManager)' on a null object reference***
***at com.example.explore_kpk.MainActivity.onCreate(MainActivity.java:121)
at android.app.Activity.performCreate(Activity.java:6877)***
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1136)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3209)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3352)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:5389)
at android.app.ActivityThread.access$1200(ActivityThread.java:223)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1803)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7231)
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)
I/Process: Sending signal. PID: 24892 SIG: 9
This is code in which error pointing**
at com.example.explore_kpk.MainActivity.onCreate(MainActivity.java:121)
RecyclerView recyclerView=(RecyclerView)findViewById(R.id.recyler_view);
RecyclerViewAdapter recyclerViewAdapter = new RecyclerViewAdapter(this, recyclerList);
long seed = System.nanoTime();
Collections.shuffle(recyclerList, new Random(seed));
GridLayoutManager gridLayoutManager=new GridLayoutManager(this, mNoOfColumns);
recyclerView.setLayoutManager(gridLayoutManager);
recyclerView.setAdapter(recyclerViewAdapter);
Your exception is saying that you are trying to use setLayoutManager on null object reference. This means that your recylcerView is null at the moment. I don't see your whole code so I can't give you an instant solution. What I can say for you is that each time the screen orientation is changed your current activity will be destroyed and called again. So, onCreate will be called again and everything else like you just started new Activity. Sometimes issues happen here so there is few options on how to handle these events.
Retaining an object during a configuration change
What this means is for you to keep your data while screen rotation is happening. This can be done with Bundle but if you have a large set of data then it is better to use the ViewModel object. How to do this check here:
Retaining an object during a configuration change | Android Developers
ViewModel Guide
Helpful answer on SO
Handling the configuration change yourself
This other option comes with big CAUTION. Consider this as a last resort when you really need to avoid restarts because of a configuration change. What this does is preventing your activity from the restart. If you can't save your instance then I would recommend doing this but first, try to play with ViewModel and Bundles to fix this issue.
Handling the configuration change yourself | Documentation
How to do this?
<activity
android:name=".MainActivity"
android:configChanges="orientation|screenSize|screenLayout" />
add android:configChanges line to your AndroidManifest.xml inside your <activity/> tag.
I've creating a nativescript application which uses the nativescript-barcodescanner plugin to scan and decode qr codes. This application is intended to be used to scan a lot of qr codes, but not in consecutive order. However, after a 1000 scans, the application is breaking with the following exception.
java.lang.RuntimeException: Unable to resume activity {org.nativescript.test/com.google.zxing.client.android.CaptureActivity}: java.lang.IllegalStateException: Too many receivers, total of 1000, registered for pid: 15623, callerPackage: org.nativescript.test
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4021)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4053)
at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:51)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:145)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1955)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7078)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:975)
Caused by: java.lang.IllegalStateException: Too many receivers, total of 1000, registered for pid: 15623, callerPackage: org.nativescript.test
at android.os.Parcel.createException(Parcel.java:1974)
at android.os.Parcel.readException(Parcel.java:19
// Allocate time for this cycle to end before issueing a validate request. Attempting to fix Fragment issue on some
// mobile devices34)
at android.os.Parcel.readException(Parcel.java:1884)
at android.app.IActivityManager$Stub$Proxy.registerReceiver(IActivityManager.java:3684)
at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1567)
at android.app.ContextImpl.registerReceiver(ContextImpl.java:1528)
at android.app.ContextImpl.registerReceiver(ContextImpl.java:1516)
at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:636)
at com.google.zxing.client.android.InactivityTimer.onResume(InactivityTimer.java:69)
at com.google.zxing.client.android.CaptureActivity.onResume(CaptureActivity.java:222)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1416)
at android.app.Activity.performResume(Activity.java:7609)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4013)
... 11 more
Caused by: android.os.RemoteException: Remote stack trace:
at com.android.server.am.ActivityManagerService.registerReceiver(ActivityManagerService.java:25447)
at android.app.IActivityManager$Stub.onTransact$registerReceiver$(IActivityManager.java:10896)
at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:126)
at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:4162)
at android.os.Binder.execTransact(Binder.java:739)
After attempting to debug the issue, from what i've found, it seems that when calling the BarcodeScanner.scan function offered by the nativescript-barcodescanner plugin, an Activity is started for result as per this code, which in turn, a receiver is registered by the google zxing library (used by this plugin). What seems to be the issue is that upon a successful scan, when the Activity returns the result, the google zxing library is not doing the necessary clean ups, resulting with dangling receivers registered. Note that when the scanner is closed by pressing the back button, the clean ups are carried out as expected.
Any help about going around this issue would be appreciated.
Edit: Added link to github repo for reproduction
https://github.com/jeanpaulattard/nativescript-barcodescanner-demo
I have an application that creates an Intent when selecting item menu, but the first time the user clicks this button, the app crashes with the following stack trace.
E/AndroidRuntime: FATAL EXCEPTION: main
Process: br.com.systemsat.monitriip, PID: 17818
java.lang.NoClassDefFoundError: br.com.systemsat.monitriip.activity.ConfigurationActivity
at br.com.systemsat.monitriip.activity.MainActivity.onOptionsItemSelected(MainActivity.java:212)
at android.app.Activity.onMenuItemSelected(Activity.java:2912)
at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:421)
at android.support.v7.app.AppCompatActivity.onMenuItemSelected(AppCompatActivity.java:188)
at android.support.v7.view.WindowCallbackWrapper.onMenuItemSelected(WindowCallbackWrapper.java:103)
at android.support.v7.app.AppCompatDelegateImplV7.onMenuItemSelected(AppCompatDelegateImplV7.java:663)
at android.support.v7.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:810)
at android.support.v7.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:152)
at android.support.v7.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:957)
at android.support.v7.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:947)
at android.support.v7.widget.ActionMenuView.invokeItem(ActionMenuView.java:618)
at android.support.v7.view.menu.ActionMenuItemView.onClick(ActionMenuItemView.java:155)
at android.view.View.performClick(View.java:5201)
at android.view.View$PerformClick.run(View.java:21163)
at android.os.Handler.handleCallback(Handler.java:746)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5443)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
Below is my Activity declaration inside AndroidManifest.xml:
<activity
android:name=".activity.ConfigurationActivity"
android:parentActivityName=".activity.MainActivity">
</activity>
Also, below is the line that is accused to be the cause of the problem by the call stack:
Intent hashCodeIntent = new Intent(getApplicationContext(), ConfigurationActivity.class);
Some answers found in StackOverflow pointed me that clean and rebuild would do the trick but I've tried without any luck. I have also tried adding MultiDex to gradle file as well as to my custom Application class, but that also resulted in a no go.
Could someone else have any insights as to what I might have done wrong? What is really intriguing is that this error only happens on the first time the user clicks the "Configuration" screen button. After the app crashes, the user can reopen it and click the button normally.
Thank you in advance.
UPDATE
I have forgot to mention that Android Monitor also logs the following info right before the crash:
Rejecting re-init on previously-failed class java.lang.Class<br.com.systemsat.monitriip.activity.ConfigurationActivity>
UPDATE 2
Here is my onOptionsItemSelected method:
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_action_config:
Intent hashCodeIntent = new Intent(this, ConfigurationActivity.class);
hashCodeIntent.putExtra("isConfigurationCall", true);
startActivity(hashCodeIntent);
break;
}
return true;
}
UPDATE 3
I have just generated an apk for testing purposes and the error did not show. Maybe it has something to do with debuging? Or even something to do with gradle version? I currently use the last version of gradle.
Try to change getAplicationContext() for getActivity()
Sometimes getAplicationContext returns null.
I have an app on Google play. I got a few error reports from the developer page and It's quite hard to figure out the problem.
This is what I have:
java.lang.NullPointerException
at com.seb.example.free.MainActivity$ApplyFilter.onPostExecute(MainActivity.java:828)
at com.seb.example.free.MainActivity$ApplyFilter.onPostExecute(v.java:1)
at android.os.AsyncTask.finish(AsyncTask.java:631)
at android.os.AsyncTask.access$600(AsyncTask.java:177)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:153)
at android.app.ActivityThread.main(ActivityThread.java:4987)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:821)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584)
at dalvik.system.NativeStart.main(Native Method)
As you can see I have an asynctask innerclass and the error seems to be in on postexecute.
I have checked my project in eclipse and, as the stacktrace says, the error is on line 828:
(iV.getVisibility() == ImageView.INVISIBLE)
My imageView, iV, is declared as private in MainActivity and I initiate it in oncreate.
I can't reproduce the problem on the three of my phones as i have tested on, so it's quite hard to understand what's causing it.
Anyone who has any ideas? Thanks!
I think that imageview object is becomes null in some where in your code..check whether it initialized or not..and if initialized check where it is used in your project.
It might have been derefferenced in some other place, initialize in onresume and see whether this persists or not.
please check have you initialized iv
try:
if(iv != null)
(iV.getVisibility() == View.INVISIBLE)
else
Log.e("CHECK","iv Null");
if you have not initialized iv then do that first.