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.      @Override
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to