The second one is the way its meant to be. I don't know the exact
reason but its probably similar to the fact why there are no
Constructors for Activities, but the onCreate()/onDestroy()/onResume()
Lifecycle-Stuff.

Regards, plusminus
http://anddev.org
#  Worlds largest Android Development Community / Tutorials

On 2 Okt., 18:55, 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 android-developers@googlegroups.com
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