views:

40

answers:

2

In my onCreate method for the first loaded Activity I have:

super.onCreate(savedInstanceState);
final int splash = R.layout.splash;
setContentView(splash);

This causes the app to crash. But if I use:

super.onCreate(savedInstanceState);
setContentView(R.layout.splash);

everything is fine. What gives?

The only reason I am experimenting with this is because I want to load different layouts based on a set of data-driven options that will come from another class depending on the customer's choices.

+1  A: 

I'm having a hard time believing that's actually causing the crash. Can you provide the exception?

Brandon
I agree with brandon, I tested this code on my emulator, and it works perfectly fine... So you must have an issue somewhere else
Sephy
I tried it again and it's working. The first attempt at it must have been put together too early in the morning - so I think I was using the wrong type of resource ID like R.drawable.splash instead of the R.id.splash. Thanks for creating sanity in my day. :^)
stinkbutt
It's also possible you might have needed to do a Clean to get the R file to regenerate from the XML.
Brandon
+1  A: 

Most likely the other part of your code that's not pasted was trying to access resources of that content view BEFORE you had called setContentView().

Brad Hein