On Aug 7, 2012, at 12:13 AM, simpleweb <[email protected]> wrote:
> Thanks for the info guys. I found that the problem is an image button. When 
> screen rotates, I get a null exception.

Stack trace?

> When I remove the image button I don't. I have a FindViewByID call in 
> OnCreate(Bundle bundle)
> 
> see below: 
> 
> // this return null exception when screen orientation changes.
> var hm= FindViewById<ImageButton>(Resource.Id.ibHomeFromLink);

So `hm` is null, and then you later try to use `hm` which results in the 
NullReferencException, right?

I suspect that you have multiple layouts:

        
http://developer.android.com/guide/practices/screens_support.html#qualifiers

For example, you may have Resources\Layout\Main.axml and 
Resources\Layout-land\Main.axml files. When you rotate to landscape 
orientation, then Resources\Layout-land\Main.axml file will be used, not 
Resources\Layout\Main.axml. This thus requires that your layout files be 
semantically equivalent: if you have a button with a given ID in 
Resources\Layout\Main.axml, then Resources\Layout-land\Main.axml must also have 
a button with the same ID. Failure to keep your layouts consistent with each 
other will result in FindViewById() returning null for some files.

The fix is to ensure that your layouts are consistent: if you have buttons & 
fields in one layout, then the all all configurations should have the same 
buttons & fields (or you need to handle the "missing" IDs in your code).

 - Jon

_______________________________________________
Monodroid mailing list
[email protected]

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid

Reply via email to