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 7967387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:41:01+00:00 2026-06-04T06:41:01+00:00

I tried to create a HelloWorld App that will update a text field with

  • 0

I tried to create a HelloWorld App that will update a text field with the current time, when a button is clicked. It seems to be fine (eclipse finds no errors), but every time I run it, my phone force crashes…. WHY?!?!?!

Anyway…

Here is the .Java file

package com.HelloWorld.test;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import java.util.Date;

public class HelloWorldActivity extends Activity implements View.OnClickListener{

Button btn;
EditText ET;

@Override
public void onCreate(Bundle icicle){
    super.onCreate(icicle);

    btn = (Button) findViewById(R.id.btn);
    btn.setOnClickListener(this);
    ET = (EditText) findViewById(R.id.ET);
    updateTime();
    setContentView(R.layout.main);

}

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

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

} 

Here is the .xml file

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >


<Button
    android:id= "@+id/btn"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="100dp"
    android:text="@string/UpdateTime" />

<EditText
   android:id="@+id/ET"
   android:inputType = "text"
   android:layout_width = "fill_parent"
   android:layout_height="wrap_content"/> 

</LinearLayout>

LogCat report…

05-23 02:53:00.661: D/AndroidRuntime(17859): Shutting down VM
05-23 02:53:00.671: W/dalvikvm(17859): threadid=1: thread exiting with uncaught exception (group=0x4001d5a0)
05-23 02:53:00.681: E/AndroidRuntime(17859): FATAL EXCEPTION: main
05-23 02:53:00.681: E/AndroidRuntime(17859): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.HelloWorld.test/com.HelloWorld.test.HelloWorldActivity}: java.lang.NullPointerException
05-23 02:53:00.681: E/AndroidRuntime(17859):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1872)
05-23 02:53:00.681: E/AndroidRuntime(17859):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1893)
05-23 02:53:00.681: E/AndroidRuntime(17859):    at android.app.ActivityThread.access$1500(ActivityThread.java:135)
05-23 02:53:00.681: E/AndroidRuntime(17859):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1054)
05-23 02:53:00.681: E/AndroidRuntime(17859):    at android.os.Handler.dispatchMessage(Handler.java:99)
05-23 02:53:00.681: E/AndroidRuntime(17859):    at android.os.Looper.loop(Looper.java:150)
05-23 02:53:00.681: E/AndroidRuntime(17859):    at android.app.ActivityThread.main(ActivityThread.java:4385)
05-23 02:53:00.681: E/AndroidRuntime(17859):    at java.lang.reflect.Method.invokeNative(Native Method)
05-23 02:53:00.681: E/AndroidRuntime(17859):    at java.lang.reflect.Method.invoke(Method.java:507)
05-23 02:53:00.681: E/AndroidRuntime(17859):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:849)
05-23 02:53:00.681: E/AndroidRuntime(17859):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
05-23 02:53:00.681: E/AndroidRuntime(17859):    at dalvik.system.NativeStart.main(Native Method)
05-23 02:53:00.681: E/AndroidRuntime(17859): Caused by: java.lang.NullPointerException
05-23 02:53:00.681: E/AndroidRuntime(17859):    at com.HelloWorld.test.HelloWorldActivity.onCreate(HelloWorldActivity.java:20)
05-23 02:53:00.681: E/AndroidRuntime(17859):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1072)
05-23 02:53:00.681: E/AndroidRuntime(17859):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1836)
05-23 02:53:00.681: E/AndroidRuntime(17859):    ... 11 more
05-23 02:53:02.883: D/Process(17859): killProcess, pid=17859

Any and all help is highly appreciated.

-Adrian

  • 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-06-04T06:41:02+00:00Added an answer on June 4, 2026 at 6:41 am

    Try this,

    Use the setContentView(R.layout.main) just after the super.onCreate(icicle), then other things. You should always 1st set the layout, then perform the work with views in it.

    eg:

        public void onCreate(Bundle icicle){
    
           super.onCreate(icicle);
           setContentView(R.layout.main);
    
           ET = (EditText) findViewById(R.id.ET);
           btn = (Button) findViewById(R.id.btn);
    
           btn.setOnClickListener(this);
           updateTime();
    
    
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have tried to create sample webservices helloworld in Java using Jersey and Tomcat
I have a Grails 2.0.0 project that was created using grails create-app . In
I created a sample webservice which contain default 'HelloWorld' function as 'webmethod' when tried
I tried to create this by following the video at http://www.asp.net/learn/videos/video-7026.aspx where Joe Stagner
I tried to create a Style for DataGridTextColumn with the following code <Style TargetType={x:Type
I tried to create a file using Oracle UTL_FILE.FOPEN command but i get this
I tried to create a new Swing GUI desktop application template using NetBean 7.0
Have anybody ever tried to create thumbnails/previews of MS Office files? I do not
when I tried to create a shared library file using the cl command in
This is the first Python script I've tried to create. I'm reading a xml

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.