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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:27:01+00:00 2026-06-16T00:27:01+00:00

This is my Method private TextView monthTotal; private TextView yearTotal; private ExpenseDal expenseDal; private

  • 0

This is my Method

private TextView monthTotal;
    private TextView yearTotal;
    private ExpenseDal expenseDal;

    private EditText amountText;
    private EditText descText;
    private EditText categoryText;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        expenseDal = new ExpenseDal(this);
        amountText = (EditText) findViewById(R.id.amountText);
        descText = (EditText) findViewById(R.id.descText);
        categoryText = (EditText) findViewById(R.id.categoryText);

        setContentView(R.layout.activity_expense_list);
        monthTotal = (TextView) findViewById(R.id.monthTotal);
        yearTotal = (TextView) findViewById(R.id.yearTotal);
        monthTotal.setText(expenseDal.getCurrentMonthTotal());
        yearTotal.setText(expenseDal.getCurrentYearTotal());

        //Event For Save Button
        Button saveButton = (Button) findViewById(R.id.saveBtn);
        saveButton.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                if (amountText.getText().length() != 0) {
                    AsyncTask<Object, Object, Object> saveExpenseTask = new AsyncTask<Object, Object, Object>() {
                        @Override
                        protected Object doInBackground(Object... params) {
                            saveExpense();
                            return null;
                        }
                        @Override
                        protected void onPostExecute(Object result) {
                            finish();
                        }
                    };

                    saveExpenseTask.execute((Object[]) null);
                }

                else {
                    AlertDialog.Builder alert = new AlertDialog.Builder(
                            ExpenseList.this);
                    alert.setTitle(R.string.errorTitle);
                    alert.setMessage(R.string.errorMessage);
                    alert.setPositiveButton(R.string.errorButton, null);
                    alert.show();
                }
            }
        });

    }

    private void saveExpense() { }

My trace below

12-17 04:53:53.003: D/AndroidRuntime(2484): Shutting down VM
12-17 04:53:53.003: W/dalvikvm(2484): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
12-17 04:53:53.003: E/AndroidRuntime(2484): FATAL EXCEPTION: main
12-17 04:53:53.003: E/AndroidRuntime(2484): java.lang.NullPointerException
12-17 04:53:53.003: E/AndroidRuntime(2484):     at com.technowizsol.easyexpensemanager.ExpenseList$1.onClick(ExpenseList.java:45)
12-17 04:53:53.003: E/AndroidRuntime(2484):     at android.view.View.performClick(View.java:4084)
12-17 04:53:53.003: E/AndroidRuntime(2484):     at android.view.View$PerformClick.run(View.java:16966)
12-17 04:53:53.003: E/AndroidRuntime(2484):     at android.os.Handler.handleCallback(Handler.java:615)
12-17 04:53:53.003: E/AndroidRuntime(2484):     at android.os.Handler.dispatchMessage(Handler.java:92)
12-17 04:53:53.003: E/AndroidRuntime(2484):     at android.os.Looper.loop(Looper.java:137)
12-17 04:53:53.003: E/AndroidRuntime(2484):     at android.app.ActivityThread.main(ActivityThread.java:4745)
12-17 04:53:53.003: E/AndroidRuntime(2484):     at java.lang.reflect.Method.invokeNative(Native Method)
12-17 04:53:53.003: E/AndroidRuntime(2484):     at java.lang.reflect.Method.invoke(Method.java:511)
12-17 04:53:53.003: E/AndroidRuntime(2484):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
12-17 04:53:53.003: E/AndroidRuntime(2484):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
12-17 04:53:53.003: E/AndroidRuntime(2484):     at dalvik.system.NativeStart.main(Native Method)

The error is on the line where i check the amount is null or not. Any ideas why im getting this.

  • 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-16T00:27:02+00:00Added an answer on June 16, 2026 at 12:27 am

    Take the line

    setContentView(R.layout.activity_expense_list);
    

    move it so it is directly below

    super.onCreate(savedInstanceState);
    

    The way you have it set up now, is you’re trying to find some Views in the layout before actually setting the layout. And so, findViewById() isn’t finding anything for those Views (nothing exists yet), and so, it returns null.

    Also, you’re not checking if amountText is null, you’re checking to see if its text length is 0 – two separate things. Since amountText is actually not holding a reference to anything, you get a NPE.

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

Sidebar

Related Questions

click the button to call this method: private void goRegister(final boolean isUsername) { new
I have this method to transfer files using a FTP Server: private void TransferNeededFiles(IEnumerable<string>
I have this recursive method which deletes empty folders: private void DeleteEmpty(DirectoryInfo directory) {
I've got a simple method that does this: private void searchButton_Click(object sender, EventArgs e)
Is there any other method that is faster than doing like this? private void
With a classic method implementation, I usually perform BeginInvoke like this: private delegate void
Using sharedpreferences I run this method: private Button button1; private Button button2; private TextView
I have a method private static DataTable ParseTable(HtmlNode table) and sometimes this method has
I'm currently using this method in calling batch files in vb.net: Private Sub Button3_Click(ByVal
When i run this demo it's call TestBean's writeObject method which is private How

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.