Amazingly it didn't though, it was working for quite some time until I
changed something and then it broke. I guess it's a race condition of
some kind.
Peter
On Oct 2, 6:01 pm, hackbod <[EMAIL PROTECTED]> wrote:
> You shouldn't do work in the constructor, because the activity class
> is not initialized until onCreate() is called.
>
> The code you quote should fail every single time the activity is
> constructed.
>
> On Oct 2, 3:55 pm, PAS <[EMAIL PROTECTED]> wrote:
>
> > It seems like the R.string resource is not available as early as I
> > would like. The following code looks fine in Eclipse, but sometimes
> > when I run it, it will sometimes throw a NullPointerException on line
> > 2 (as I figured out from the log):
>
> > 1. public class Foo extends Activity {
> > 2. private Uri mLink =
> > Uri.parse(getString(R.string.my_site_url));
> > 3.
> > 4. [EMAIL PROTECTED]
> > 5. public void onCreate(Bundle savedInstanceState) {
> > 6. super.onCreate(savedInstanceState);
> > 7.
> > 8. Intent i = new Intent(Intent.ACTION_VIEW, mLink);
> > 9. startActivity(i);
> > 10. }
> > 11. }
>
> > BUT, if I move the private member variable inside the onCreate method,
> > it works every time:
>
> > public void onCreate(Bundle savedInstanceState) {
> > super.onCreate(savedInstanceState);
>
> > Uri link = Uri.parse(getString(R.string.my_site_url));
> > Intent i = new Intent(Intent.ACTION_VIEW, link);
> > startActivity(i);
> > }
>
> > Has anyone had an experience like this, or know why this may be
> > happening?
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---