Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6164135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:56:32+00:00 2026-05-23T21:56:32+00:00

So I just started learning Android and I am reading the commonsware android development

  • 0

So I just started learning Android and I am reading the commonsware android development guide as a starting point. So basically I tried to create a view using xml and this xml is located in

res/layout/edittext.xml

and the xml looks like:

<?xml version="1.0" encoding="utf-8" ?>
<EditText xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/field"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:singleLine="false"/>

and my code

public class HelloWorld extends Activity implements View.OnClickListener {

    Button btn;

    /**
     * Called when the activity is first created.
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        System.out.println("HEY");

        btn = new Button(this);
        EditText editText = (EditText) findViewById(R.id.field);

        editText.setText("Hey there how are you doing");
        updateTime();
        setContentView(R.layout.main);
    }

    public void onClick(View view) {
        updateTime();
    }

    public void updateTime() {
        btn.setText(new Date().toString());
    }
}

and the editText returns null… This is R class if it matters.

/* AUTO-GENERATED FILE.  DO NOT MODIFY.
 *
 * This class was automatically generated by the
 * aapt tool from the resource data it found.  It
 * should not be modified by hand.
 */

package com.dennis;

public final class R {
    public static final class attr {
    }
    public static final class drawable {
        public static final int icon=0x7f020000;
    }
    public static final class id {
        public static final int field=0x7f050000;
        public static final int helloText=0x7f050001;
    }
    public static final class layout {
        public static final int edittext=0x7f030000;
        public static final int main=0x7f030001;
    }
    public static final class string {
        public static final int app_name=0x7f040000;
    }
}

stack trace

07-22 11:30:46.670: ERROR/AndroidRuntime(674): FATAL EXCEPTION: main
        java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dennis/com.dennis.HelloWorld}: java.lang.NullPointerException
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
        at android.app.ActivityThread.access$2300(ActivityThread.java:125)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:123)
        at android.app.ActivityThread.main(ActivityThread.java:4627)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:521)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
        at dalvik.system.NativeStart.main(Native Method)
        Caused by: java.lang.NullPointerException
        at com.dennis.HelloWorld.onCreate(HelloWorld.java:25)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T21:56:33+00:00Added an answer on May 23, 2026 at 9:56 pm

    In your onCreate() method, make sure you call setContentView() before any other UI-related tasks. i.e. most people call it right after super.onCreate()

    Also, it looks like you have some misconceptions about layouts. You should normally have an encompassing “layout” object like a LinearLayout that you place View objects into, such as your EditText. The variable passed to setContentView() will be R.layout.name of your xml file.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just started learning Zend. I managed to get the basic working (using zf
I've just started learning Lisp and I can't figure out how to compile and
I've just started learning linq and lambda expressions, and they seem to be a
I have just started learning Erlang and am trying out some Project Euler problems
I'm just getting started with learning about Unit testing (and TDD in general). My
I have just started writing my own JavaScript Framework (just for the learning experience),
Have just started using Google Chrome , and noticed in parts of our site,
Have just started using Visual Studio Professional's built-in unit testing features, which as I
I just started using GNU Emacs as my text editor and I am concerned
Just started learning C# (in xaml), so appreciate some elaboration: ((MSAvalon.Windows.Serialization.ILoaded)(_Text_2_)).DeferLoad(); Not sure what

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.