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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:16:45+00:00 2026-05-28T03:16:45+00:00

I am trying to get EditText value through below code. The activity is used

  • 0

I am trying to get EditText value through below code. The activity is used for adding two strings. In the layout, I already put onSave and onCancel method. But when I press button linked to onSave, it shows null pointer exception error.

Activity:

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

public class AddTimeActivity extends Activity {

public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.time_item);
}

public void onCancel(View view){
    this.setResult(RESULT_CANCELED);
    finish();
}

public void onSave(View view){
    Intent intent = getIntent();

    EditText timeView = (EditText)view.findViewById(R.id.time_view);
    String time = timeView.getText().toString();
    intent.putExtra(TimeTrackerActivity.TIME_KEY, time);

    EditText notesView = (EditText)view.findViewById(R.id.notes_view);
    String notes = notesView.getText().toString();
    intent.putExtra(TimeTrackerActivity.NOTES_KEY, notes);

    this.setResult(RESULT_OK, intent);

    finish();

}
}

Layout:

...
<EditText
    android:id="@+id/timeView"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >
</EditText>

<EditText
    android:id="@+id/notes_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="textMultiLine" 
    android:gravity="top"
    android:layout_weight="1"
    android:layout_marginBottom="10dp"/>
...
<Button
        android:onClick="onSave"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Save" />

<Button
        android:onClick="onCancel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Cancel" />
...

Error Message from Debugger

E/AndroidRuntime(1123): Caused by: java.lang.NullPointerException
E/AndroidRuntime(1123): at com.timetracker.AddTimeActivity.onSave(AddTimeActivity.java:34)

I tried to check and the value of timeView through debugger and it is null.

Could anybody help?

  • 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-28T03:16:46+00:00Added an answer on May 28, 2026 at 3:16 am

    You are looking for the id time_view (findViewById(R.id.time_view)), but you declare in the XML the ID timeView (android:id="@+id/timeView"). Make them the same and it should fix it.

    Also, you should not call it on the view, but on the activity, e.g:

    EditText timeView = (EditText)findViewById(R.id.time_view);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to get the value of a EditText in a dialog box.
Using the following code snippets, I'm trying to get the text value which has
I'm trying get values from a GridView using the following code: foreach (GridViewRow row
Trying to get parameters from a PUT request using HttpServlet#doPut: public void doPut(HttpServletRequest request,
Trying to get comfortable with jQuery and I have encountered some sample code that
I have been trying to get my EditText box to word wrap, but can't
I'm trying get LocalConnection to work between two swf's placed within two different IFRAMES.
Im trying to compare the values of two edittext boxes. What i would like
I'm trying to get my EditText field to not be as tall but to
I am trying to get to the point where I have a Input (EditText)

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.