How do I declare "Member Fields" in Java?

Posted by Bub on Stack Overflow See other posts from Stack Overflow or by Bub
Published on 2010-05-10T20:03:47Z Indexed on 2010/05/10 20:14 UTC
Read the original article Hit count: 266

Filed under:
|

This question probably reveals my total lack of knowledge in Java. But let me first show you what I thought was the correct way to declare a "member field":

public class NoteEdit extends Activity {

private Object mTitleText;
private Object mBodyText;

I'm following a google's notepad tutorial for android (here) and they simply said: "Note that mTitleText and mBodyText are member fields (you need to declare them at the top of the class definition)." I thought I got it and then realized that this little snippet of code wasn't working.

if (title != null) {
            mTitleText.setText(title);
        }
        if (body != null) {
            mBodyText.setText(body);
        }

So either I didn't set the "member fields" correctly which I thought all that was needed was to declare them private Objects at the top of the NoteEdit class or I'm missing something else. Thanks in advance for any help.UPDATE

I was asked to show where these fields were being intialized here is another code snippet hope that it's helpful...

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.note_edit);
    Long mRowId;
    mTitleText = (EditText) findViewById(R.id.title);
    mBodyText = (EditText) findViewById(R.id.body);

© Stack Overflow or respective owner

Related posts about android

Related posts about java