I am getting NullPointer exception for my app when switching from potrait mode to landscape mode and vice versa

by manoj » Wed, 11 Feb 2009 13:02:22 GMT

Sponsored Links
 Hi friends,

I have written a small example which displays the photos from the

Its working fine when the device is in one of the mode (landscape of
potrait ).

But if I switch to landscape to potrait or potrait  to landscape while
downloading the photos from the server,

I am getting NullPointerException, showing with

Can any one please help to solve this problem?

I am using LinearLayout -> ImageView

I am using threads to download the images.


I am getting NullPointer exception for my app when switching from potrait mode to landscape mode and vice versa

by clark » Wed, 11 Feb 2009 13:15:16 GMT

 You may want to try adding android:configChanges="orientation" to
AndroidManifest.xml and overriding onConfigurationChanged().  If a
configuration change is not specified in android:configChanges then
Android will take care of it for you, which means restarting your
app.  Without seeing code it is hard to say exactly what you should do
to handle this, but the information I listed should get you started.
I'd do a search regarding onConfigurationChanged() in the SDK

I hope that gets you going in the right direction.



Sponsored Links

I am getting NullPointer exception for my app when switching from potrait mode to landscape mode and vice versa

by Mark Murphy » Wed, 11 Feb 2009 21:59:38 GMT


Without the source code for the area where the exception is occurring,
and knowing which line is the one raising the exception, it is rather
difficult to give you a precise solution.

Bear in mind that, on a rotation like this, by default your existing
activity is destroyed and a new one created.

Here is a series of blog posts on handling rotation events that may help
you understand what is going on:

 http://androidguys.com/?s=rotational +forces

Mark Murphy (a Commons Guy)
_The Busy Coder's Guide to Android Development_ Version 2.0 Published!


Other Threads

1. Android custom hardware

Hi all,

I need to create a custom phone hardware using android platform that
will use minimal functions..I don't need accelerometer, camera even
mic and loud speaker. all i need is a SIM card slot and minimal
hardware features that will accommodate a custom compiled android
platform. I need pointers on

a) where i can find help to create such a hardware. Even if it's in
PCB board with the right chipsets, that's good enough for prototyping.
b) are there any pointers on dos and don'ts on stripping down android
platform code to bare bones. minimalist version of android platform
needed, again i will not leverage apis pertaining to GPS,
Accelerometer, camera etc,

Any help will be much appreciated.



2. trying to write to file and failing

hi im just trying to save some text to a file on android and while it
works fine on the emulator "dont crash", when i try it on my phone it
crashes, what am i doing wrong? heres the code:

            File root = Environment.getExternalStorageDirectory();
            if (root.canWrite()){
                 File file = new File(root, "file.txt");
                 FileWriter writer = new FileWriter(file);
                 BufferedWriter out = new BufferedWriter(writer);
                 out.write("some data");
                 showMes("File saved.");
                 showMes("Could not save file.");
        }catch(Exception e){

i do know it crashes on " File root =
Environment.getExternalStorageDirectory(); " i just dont know why.
showMes() is just a function to make toast. thanks for any help.


3. My app crashes upon relaunch

4. Something wrong here, didn't expect com.commonsware.android.rotation.two to be resumed

5. Linkify-ed TextView non-linked text disappears on touch

6. No Phone Signal in Emulator (2.1)

7. catching both click and long click on a ListView