views:

18

answers:

1
    public class MyActivity extends Activity {

        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);

            //R.layout.main has an illegal element (e.g. no layout_height attribute) 
            //But no ecxeption is thrown at this line.
            setContentView(R.layout.main); 

        } //Exception will be thrown after this line. Where to catch it?
    }
+3  A: 

Are you serious? That kind of things cannot be just "catched"... they have to be fixed. Just fix your XML file and that's it... it does not make sense to catch such as Exception; what would you do after catching it?

Cristian
+1 to Cristian. @OneWorld: If your Layout XML is malformed then your application is broken.
Octavian Damiean
@Christian: Of course this things must be fixed. However, it also must be possible to catch those things. @Octavian: If the XML of an activity is malformed then this Activity is broken, not the application. So, I can finish it, show appropriate Toasts and Log the error.
OneWorld
@OneWorld: Why should the layout of an activity you built be malformed? This makes no sense. Why would you publish an application with a broken activity?
Flo
@OneWorld trust me, while developing with Android you will find that not all Exceptions can be caught. Just fix your layout, case closed.
Cristian