Android :: Catching NullPointerException And Returning 0?
Oct 15, 2010
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;
View 3 Replies
May 5, 2009
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?
View 2 Replies
View Related
Mar 18, 2009
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 Related
Aug 12, 2009
In 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 ?
View 2 Replies
View Related
Aug 2, 2009
I'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 Replies
View Related
Aug 22, 2009
I 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 Related
Jul 9, 2009
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?
View 2 Replies
View Related
Nov 15, 2010
This does not refer to anywhere in my code at all.
How do I go about getting to the bottom of it?
CODE:..........................
Here is the draw method of the ItemizedOverlay
CODE:..........................
I now print out the stacktrace and no difference!
View 1 Replies
View Related
Mar 17, 2009
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 Related
Jul 28, 2010
i get NullPointerException at the start of the for where am i going wrong?
public void checkzone(Location loc)
{
X = new List<float[]>() {
};
Y = new List<float[]>() {
};
X.clear();
Y.clear();
float x = (float) loc.getLatitude();
float y = (float) loc.getLongitude();
float A1X[] = {(float) 41.992853, (float) 41.994815, (float) 41.995158, (float) 41.993065};//DOMA..........................
View 2 Replies
View Related
Oct 9, 2010
I'm using a lazy image loader for my ListView with the following code inside getView():
CODE:.........
And the following inside the AsyncImageLoader class:
CODE:........
For an unknown reason to me, after to switched from using the common SQLiteOpenHelper to a custom one which allows me to store my database on the SD card, every 6th or 7th image that is loaded throws a NullPointer at:
imageCallback.imageLoaded((Bitmap) message.obj, wallpaperNumber);
I've checked everything and don't actually know what variable is actually null.
View 1 Replies
View Related
Jan 27, 2010
Has 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 Related
Nov 11, 2009
I 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?
View 6 Replies
View Related
Mar 12, 2010
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 Related
Jun 23, 2009
The 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?
View 7 Replies
View Related
Jun 19, 2009
In 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 Related
Jan 11, 2010
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...
View 4 Replies
View Related
Jun 23, 2010
I am trying to save the date of file parsing, so that when next time user, opens the application, the date can be checked against the last parsing date. I am using shared preference to save the data and retrieve it, but getting error. here is the code:
SharedPreferences settings = getPreferences(0);
String today = new Date(System.currentTimeMillis()).toString();
SharedPreferences.Editor edit = settings.edit();
System.out.println("******** Today : " + today);
edit.putString("lastdate", today);
String fetch = settings.getString("lastdate", "0");
System.out.println("******** Fetch : " + fetch);
txtTest.setText(fetch);
but I am getting null pointer error. am I missing something?
View 2 Replies
View Related
Oct 12, 2009
I'm trying to use NinePatchDrawables in a LayerDrawable, but for some reason I get a NullPointerException. I've isolated the problem to the getPadding() method; the following code reproduces the problem:
CODE:...............
What am I missing? Do I have to do anything special with the NinePatch? The program seems to work if I use the NinePatch directly (instead of putting it in a LayerDrawable).
View 6 Replies
View Related
Oct 3, 2010
This is the code for my custom provider, mostly copied from the SDK notepad project i cant understand why am i getting nullPointException, why doesnt the provider instance get created?
CODE:............
LogCat
CODE:..........................
View 1 Replies
View Related
Mar 8, 2010
I'm trying to change the content of a row in ListView programmatically. In one row there are 3 TextView and a ProgressBar. I want to animate the ProgressBar if the 'result' column of the current row is zero.
After reading some tutorials and docs, I came to the conclusion that LayoutInflater has to be used and getView() - overriden. Maybe I am wrong on this. code...
View 1 Replies
View Related
Apr 28, 2010
I am trying to create a list view which as TextView that can display html content , an WebView and other basic TextViews.I tried to extend SimpleAdapter but i struck with the problem ,I will be glad if someone can point out the mistake i am doing.
In onCreate method:
CODE:.............
And my row.xml file looks like:
CODE:.............
The error i was getting was:
CODE:..................................
View 1 Replies
View Related
Nov 3, 2010
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.
View 10 Replies
View Related
Jun 12, 2009
I created a custom SurfaceView called CaptureView and tried to add it into main.xml file.The application seems to work fine but if I switch from main.xml tab to Layout in Eclipse the text NullPointerException appears instead of layout preview.Does anyone know how this issue could be solved?
View 2 Replies
View Related
Jun 28, 2010
I am using Eclipse 3.6.0, when I try to edit the strings.xml the Eclipse show me NullPointerException.
Any solution or advice how to handle this?
View 3 Replies
View Related
Jun 30, 2010
I have looked and looked, and cant seem to get to the bottom of this.
I am getting the error: "java.lang.NullPointerException"
whenever I try to change anything at all within "strings.xml" when using eclipse, does anyone know of a reason behind this? I havnt changed anything else in the project at all, I'm just going straight into strings to try editting a few things.
View 18 Replies
View Related
Jun 28, 2010
it has taken more than i expected to get the dev environment up and running - mostly a PATH issue which was solved using: http://groups.google.com/group/android-developers/browse_thread/threa...
My emulator now works (and i can run it and get the default android screen) however when i try to run the hello world sample code i get this error message:
An internal error occurred during: "Launching HelloAndroid". java.lang.NullPointerException
View 2 Replies
View Related
Oct 20, 2010
I'm getting this crazy error on multiple projects, even when I revert back to prior versions that compiled just fine. Unknown Error - java.lang.NullPointerException Android Packaging Problem Path is blank Location is Unknown. 1 - Project -> Clean -> All 2 - Deleting .metadata folder 3 - reimporting projects into the eclipse 4 - reverting my projects back to prior working versions using git. I just can't get anything to compile now, and I've searched for solutions here and on eclipse forums.
View 3 Replies
View Related
Oct 20, 2010
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.
View 3 Replies
View Related
Oct 31, 2010
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?
View 2 Replies
View Related