CMF wrote:
> I have a self-define view class, I would like to add this view into
> the layout , but there is a problem
<snip>
> 02-21 17:23:07.853: ERROR/AndroidRuntime(1253): Caused by:
> java.lang.NullPointerException
> 02-21 17:23:07.853: ERROR/AndroidRuntime(1253): at
> com.example.helloandroid.HelloAndroid.onCreate(HelloAndroid.java:16)
You have a NullPointerException in line 16 of HelloAndroid.java.
> Here is my code, I want the SelfView to be under the TextView.
>
> public class HelloAndroid extends Activity {
> private SelfView mSelfView;
> /** Called when the activity is first created. */
> @Override
> public void onCreate(Bundle savedInstanceState) {
> super.onCreate(savedInstanceState);
> LinearLayout mlayout =
> (LinearLayout)findViewById(R.id.mylayout);
> mSelfView = new SelfView(this);
> mlayout.addView(mSelfView);
> setContentView(R.layout.main);
> }
> }
You are calling findViewById() before calling setContentView(). That
will never work. Call setContentView(), then call findViewById().
--
Mark Murphy (a Commons Guy)
http://commonsware.com | http://twitter.com/commonsguy
_The Busy Coder's Guide to *Advanced* Android Development_
Version 1.3 Available!
--
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