Android :: Catching Memory Exception
Aug 2, 2009I've got this problem: When my program using too much memory, it die. Is there an exception or something else to warn me? How can I catch it?
View 11 RepliesI've got this problem: When my program using too much memory, it die. Is there an exception or something else to warn me? How can I catch it?
View 11 RepliesIn the Eclipse log I can clearly see a warning pop up (something about buffer overflow) every time I don't read from the AudioRecord buffer fast enough and consequently miss a chunk of audio samples. Is there any way I can detect that notification programatically so I know exactly when I have missed a chunk?
View 2 Replies View RelatedI am getting an outofmemory error (java.lang.outofmememoryerror) from a bitmapfactory that doesn't seem to be caught despite the fact that it is in a try{ }catch block. Can I catch this error somehow or is it outofmemory inherently uncatchable?
View 9 Replies View RelatedI have a problem with a strange out of memory exception that only occurs on some devices (mostly HTC Desire). It happens there every time a user starts a certain activity (no matter how - there are two paths to that activity) and i'm really puzzled as to why (i checked for leaks and couldn't find any)...
The error is either thrown when calling setContentView or shortly after.
This is the code block that throws the error:
CODE:.........
As i said - the error is usually thrown when calling setContentView or when calling getMonthTimeStamps()
getMonthTimeStamps is a helper function which creates a list of dates available in the internal database. It creates a couple of (small objects) and returns an ArrayList.
Here is the function:
CODE:.............
I'm not claiming that my code is flawless or perfect, but i really don't understand why this error is thrown. The XML-layout doesn't contain any references to images and not very complicated (textview, spinner, tablelayout).
Here is the error log i received from one user:
CODE:.....................
I have a strange problem on my htc hero. When launching camera, i get out of memory exception. After that, if i launch any other application that uses camera, they also crash(when trying to use camera function).
I call camera.release and camera.stoppreview in surfacedestroyed function, but that doesnt help.
What is the right way to release all resources? Could somebody please show his working surfacechanged, surfacecreated and surfacedestroyed functions? I have empty onPreviewFrame function, should i put something there?
Have a dump_log which points to "Out of Memory exception". How do I fix the issue as we have a number of applications running on the Android target?
View 2 Replies View RelatedI am downloading a audio file from server on sd card. It is showing me OutOfMemoryException. This is my code.. --------------------------- package com.android;
import java.io.BufferedInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.net.URLConnection;.....................
This is the sequence part of this question: http://stackoverflow.com/questions/3674441/combining-2-images-overlayed
so the problem is: if the image size is too big - it'll got an exception (out of memory exception)
what i want is, to handle even if the handset got the lower spec hardware, it doesn't go to that exception (but it'll take a longer time to process the image) is it possible to do that?
The code snippet is like this:
CODE:......
And that block of code is inside the async task.
I need to post some files on my server, it works fine for small files like 1mb but when i try for more than 4 mb ; it force close because of memory overload.
Have a look on my code below:
CODE:.................
I've been trying to diagnose a memory leak in an Android application I'm writing. I got a heap dump loaded into Eclipse, but the results I'm seeing are very curious. There are some 20,000 instances of an exception (specifically, LDAPException from the UnboundID LDAP library) in the heap with no inbound references.
That is, they show up at the root of the dominator tree. The OQL SELECT objects e FROM com.unboundid.ldap.sdk.LDAPException e WHERE (inbounds(e).length = 0) returns over 20,000 results, totalling to nearly all of the heap. And yet, the GC runs before the heap dump and I can see that it's running in the console, repeatedly, during the execution of the leaky code. If these instances have no inbound refs, what could be keeping them alive?
I also tried doing a "shortest paths to GC" query. It shows one LDAPConnectionReader row retaining 2 instances, and ~20k LDAPException @ <addr> unknown rows with various hex addresses.
Update: I haven't had time to further diagnose this since posting it, and the bounty I posted is ending before I likely will. I'm awarding it as best I can now, lest the points go to waste. Thanks to everyone who looked into this! I will come back later and update again with the results of further diagnosis, when life is a little less hectic.
I created a sql lite database with the following columns:
static final String dbName="demoDB";
static final String tableName="Employees";
static final String colID="EmployeeID";
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
db.execSQL("CREATE TABLE "+tableName+" ("+colID+" INTEGER PRIMARY KEY AUTOINCREMENT, "+
colName+" TEXT, "+colAge+" Integer);");
I want to select all the records in the database like this and display them in a gridview:SQLiteDatabase db=this.getWritableDatabase();Cursor cur= db.rawQuery("Select "+colName+", "+colAge+" from "+tableName, new String [] {});String [] from=new String []{DatabaseHelper.colName,DatabaseHelper.colAge};
int [] to=new int [] {R.id.colName,R.id.colAge};
SimpleCursorAdapter sca=new SimpleCursorAdapter(this,R.layout.gridrow,c,from,to);
GridView grid=(GridView)findViewById(R.id.grid);
grid.setAdapter(sca);but i receive the following exception:java.lang.IllegalArgumentException: column '_id' does not exist.the db table does not have a column with name '_id'so what is wrong with this code
I am trying to write a code about catch lat. and long. points with the GPS, actually I am using the shell with the commands "geo fix" because the DDMS doesn't work in linux apparently, I am using this scripts:
getBestProvider(criteria, true); getLastKnownLocation(provider); requestLocationUpdates(provider, 2000, 10, locationListener);
The questions is: the program is working right now in the emulator, but what about if I move the program to the real cellphone? Is the same? I need think in something else?
I am (supposedly) catching NullPointerException and returning 0 if that happens. But occasionally I get NullPointerException failure anyway. Is catching it this way no enough to prevent this failure?
private char getCharBehindCursor (int offset){ // get a single char behind cursor + offsett CharSequence cSeq; InputConnection inputConnection = getCurrentInputConnection(); if (inputConnection != null){ try { cSeq = inputConnection.getTextBeforeCursor (offset + 1, 0); } catch (NullPointerException npe) { /* failure*/ return (char)0; }
if (cSeq.length() == offset+1){ return cSeq.charAt(0); } } return (char)0;
I have tried all day to capture a trackball event in a View. Basically I want to use the trackball to move a Sprite in a 2D game left and right. The onTouchEvent works perfectly well in the View to move the Sprite with my finger but it would be nicer and cleaner to use the trackball.Can anyone provide me with a simple example that uses the trackball to move something in a View in a 2D type game world (not a menu or UI type of example)? Or can someone explain what I'm not doing. Thanks so much for any help you can give me.
View 3 Replies View RelatedIn my application I would like to catch all exceptions globally - it should not matter, where those exceptions occur. Some runtime exceptions are practically impossible to catch (OutOfMemoryError for instance), but I want to show an informative dialog and resume execution at some well-defined point (main menu activity or something).
Using Thread.setDefaultUncaughtExceptionHandler() does this for background threads, but it is of no help in the UI thread (or adjacent handlers). If an exception occurs in the UI thread, the UI will be jammed - not reacting to any key or touch events anymore. Of course, this seems natural since it did not catch that exception; but I wonder if there is a way to recover the UI thread. So:
- Can I recover / restart the UI thread after an uncaught exception (from another thread) ?
- Is there another way to catch uncaught exceptions globally ?
- Are there viable alternatives to handle this problem ?
I want my app to catch downloads of a particular kind of file.
Here's the corresponding part of AndroidManifest.xml:
CODE:............
Now, open a page with a link to an .exe file, click it. The download manager starts and then tells that The content is not supported on the phone. My activity doesn't even get called.
The questions are:
1) Why doesn't my activity get called?
2) What's the correct way of letting download manager do it's job and then get notified upon file download completion?
I am trying to intercept xml links that are clicked in the android web browser. I want my activity to handle these xml files, however I cannot seem to get this to work. Whenever I click on the xml file in the browser it just displays the xml file.Here is the entry that I have in my AndroidManifest.xml. Is this enough or do I need to do something more?
View 2 Replies View RelatedHas anyone found a way to catch outgoing calls from the Htc Hero Dialer?I currently use the NEW_OUTGOING_CALL intent in my app and this works for the standard Android dialer but not for the Htc Hero one.The hero dialer seems to not fire that specific intent.Is there any other way to achieve this?
View 2 Replies View RelatedI have the following code...
CODE:.................
My mClient get method is a simple HttpClient execute with an output buffer to read the input stream, so it's very trivial. Everytime I execute this task UnknownHostException will be triggered which will in turn call onTaskError on my currect Activity, but I still get a RuntimeException, but I don't see why. Maybe it's because it's late and i've done about 12 hours of writing code so it's something simple I just can't see?
I've a piece of code that launches an Intent. I'm wondering if there's any way to get return codes and/or catch exceptions? The particular scenario I'm facing is when I launch an Intent passing a 'rtsp' URL but it turns out the URL isn't available.
View 1 Replies View RelatedThe JavaDoc of Context's public abstract void startActivity (Intent intent) said:
This method throws ActivityNotFoundException if there was no Activity found to run the given Intent.
But when I look at the android source code, it does not catch ActivityNotFoundException.
For example in AlarmClock.java:
CODE:..................
what is the code which handles the case when there is no activity for that intent?
I'm trying to catch an action like ACTION_HEADSET_PLUG. But I think it might be too much to set this action on the manifest file.
How could I register a listener for this action? I only need to care about it when my application is running not all the time as I think it would happen when registering it under the manifest file...
I thought I knew how to catch list selection events in Android and then I regained consciousness. In my situation, I have a ListView that I populate with a custom view, all of the same class (let's call it the NewsChannel() class). NewsChannel consists of a LinearLayout of ImageViews and TextViews. When the list is displayed, the user may select a NewsChannel item in the list; I want to find out which list item was selected. Also, I registered an onClickListener to one of the TextViews and that works fine: when the text is clicked on, an activity is launched which is looking for the position of the NewsChannel item in the list. So, here's what my code looks like:
1. Registering the onClickListener in the ListActivity:
public class NewsListActivity extends ListActivity {...
public void onCreate(Bundle icicle) { super.onCreate(icicle);
setContentView(R.layout.news_list_format); ListView lv = getListView();
lv.setOnItemClickListener(new OnItemClickListener()
{ public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// When clicked, show a toast with the TextView text item_index = position;
Toast.makeText(getApplicationContext(), "item clicked = " + position,
Toast.LENGTH_SHORT).show(); }}); ...
2. The layout for the ListView associated with NewsListActivity:
<?xml version="1.0" encoding="UTF-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/ android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:background="@drawable/wpaper_tile" >
<ListView android:id="@id/android:list" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_alignParentTop="true"
android:dividerHeight="15dp" android:divider="@android:color/transparent"
android:cacheColorHint="@android:color/transparent" android:scrollbars="none" />
<FrameLayout android:layout_width="fill_parent" android:layout_height="55dp"
android:layout_centerHorizontal="true" android:layout_alignParentBottom="true"
android:background="#88000000"/>
<ImageView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true" android:src="@drawable/phonetop_bg" /> </RelativeLayout>
3. The NewsChannel layout:
<?xml version="1.0" encoding="UTF-8"?> <RelativeLayout xmlns:
android="http://schemas.android.com/apk/res/ android"
android:layout_width="fill_parent" android:layout_height="wrap_content">
<include layout="@layout/news_heading_format"
android:id="@+id/news_heading_header"/>
<ImageView android:id="@+id/news_channel_image" android:layout_width="88dp"
android:layout_height="66dp" android:layout_alignParentLeft="true"
android:layout_below="@id/news_heading_header" android:padding="10dp" />
<TextView android:id="@+id/news_channel_text" android:lines="4"
android:inputType="textMultiLine" android:layout_toRightOf="@id/news_channel_image"
android:layout_below="@id/news_heading_header" android:layout_width="fill_parent"
android:layout_height="wrap_content"/> </RelativeLayout>
When I run the app, the ItemClickListener is never called. However, if NewsChannel were of a simpler type, say, a single ImageView or TextView embedded in the layout, the callback does get called. Any idea what I'm doing wrong? My whole goal is simply to let the activity launched by NewsChannel (not shown) to find out which instance of NewsChannel it was launched from.
I need to specify the full button images for both the up and down positions. My impression is that the most probable choice is to use an custom button based on the ImageView and specify the image for up and down positions. I am using the OnTouchEvent method to capture the ACTION_DOWN, but I'm not getting the ACTION_UP event.
Is there a better choice for creating a button that controls the full button image, catches the Down/Up and can subdivide the down time into time slices? If not, how do I catch the up event.
My application expects a screen touch on the "button" and not a keyboard action.
I noticed that a toast isn't displayed when it's used inside a catch block.
Does anyone know how to show toasts when catching exceptions?
I love the fact that I can type words like "im" and it predicts into "I'm". Is it an all or nothing though because I'm continually getting odd words thrown into my texts and not catching it. Mostly happens with slang usage or proper names. Is the only trick to keep entering these things into the personal dictionary until you root out the majority of mishaps or is there a better way. Almost wish there was a list of usual suspects that it'd auto fix but that it'd leave alone proper name entries and abbreviations and so forth. Wishful thinking or possible?
View 4 Replies View RelatedAlright how does one catch and stop a one decimal point error? The user inputs a single . and that is all; you can not allow that because you will be doing math with that input.if you have this in your xml file:
Code:
<EditText
android:id="@+id/edittext01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="number|numberDecimal"
android:lines="1" >
</EditText>
and the user types just one decimal and nothing else the program will blow up.I tried the following code but the program blows up at the second IF.At first the two IFs were just one line, they got broken up to see where the problem was As you can see if the length of the user input is only 1 we check to see if it is only one decimal only
The program blows up at the second IF, but errx is a STRING.I used the Log.i to see how far to program went. And the errx is a "."
Code:
if (stop == 0) // checking for one decimal only and nothing else
{
String errx =null;
errx = (edtxt01.getText().toString());
Log.i("ONE DEC:", "START OF IF xxxx: " + errx);
if (edtxt01.length() == 1 ) // *********** 1st if
[code]...
I have a ListView in my Activity. I am trying to catch both a click and a long click (which should bring up a context menu).
ListView lv = (ListView) findViewById(R.id.MyListView); ... lv.setOnItemClickListener(this); lv.setOnCreateContextMenuListener(this); ...
I notice that if I have both the click and long click listeners up, I won't ever get the long click listener (i.e. the context menu). If I remove the setOnItemClickListener() call, i get a call into
@Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscribe@googlegroups.com For more options, visit this group at
How to tell the installer intent to install on memory card or on phone memory ?
View 2 Replies View RelatedMy application is designed to support both portrait and landscape orientations. Using my HTC IO device, it survives 12 orientation changes before throwing an out of memory exception while inflating my activity.When I follow the recommended procedure of using DDMS to first force a GC and then write a heap dump, and then load it into the Eclipse Memory Analyzer, there is only one retained instance of my application, as there should be. None of the other retained objects are obvious offenders. Just for yuks, I reran the test, and did everything the same way except I didn't force a GC. In this case I see 13 instances of my application, which is more consistent with throwing an OOM exception. Is this telling me something useful? If forcing a GC with DDMS reclaims the memory used by now-defunct instances of my activity, I would have thought the VM would have garbage collected some, if not all of these defunct activities automatically. Do I need to request GC at the very beginning of my activity lifecycle to make sure?
View 7 Replies View Related