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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T13:04:21+00:00 2026-05-20T13:04:21+00:00

So, I have two classes, one that adds tasks and one that adds categories.

  • 0

So, I have two classes, one that adds tasks and one that adds categories. When adding a task you can associate that task with a category which is populated using a dropdown and the database enforces foreign keys by using triggers. I have got the application adding tasks correctly but I’m catching a null pointer exception with my add category class, and I’m having trouble pinning down where it is – I’ve looked in logcat but it hasn’t been particularly helpful.

The class is as follows:

public class AddCategory extends Activity {
    EditText txtCatName;
    DatabaseHelper dbHelper;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.addcategory);
        txtCatName = (EditText) findViewById(R.id.txtCatName);
    }

    public void btnAddCat_Click(View view) {
        boolean ok = true;
        try {
            String name = txtCatName.getText().toString();
            DatabaseMethods cat = new DatabaseMethods(name);

            dbHelper.AddCategory(cat);

        } catch (Exception ex) {
            ok = false;
            CatchError(ex.toString());
        } finally {
            if (ok) {
                // NotifyEmpAdded();
                Toasts.ShowTaskAddedAlert(this);
            }
        }
    }

    void CatchError(String Exception) {
        Dialog diag = new Dialog(this);
        diag.setTitle("Add new Category");
        TextView txt = new TextView(this);
        txt.setText(Exception);
        diag.setContentView(txt);
        diag.show();
    }

    void NotifyCatAdded() {
        Dialog diag = new Dialog(this);
        diag.setTitle(this.getString(R.string.add_category));
        TextView txt = new TextView(this);
        txt.setText(this.getString(R.string.category_added));
        diag.setContentView(txt);
        diag.show();
        try {
            diag.wait(1000);
        } catch (InterruptedException e) {
            CatchError(e.toString());
        }
        diag.notify();
        diag.dismiss();
    }

} 

If you need any more code then please just ask. Any help is much appreciated. Always helps to get a couple of more pairs of eyes on code to find errors :).

  • 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-20T13:04:22+00:00Added an answer on May 20, 2026 at 1:04 pm

    I don’t see where dbHelper is being initialized, so I would suspect it would be returning as null. Put a breakpoint at dbHelper.AddCategory(cat); and see if dbHelper is null.

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

Sidebar

Related Questions

I have a class that instantiates two classes which implement interfaces. I want one
I have created two viewController classes such that one is superclass of another.i have
I have a class that contains objects of two other classes. I need one
I have two classes one of which inherits from the other. Im trying to
i have two data classes which hold only data members(no functions). One is CallTask
If I have two classes, and one of them has a function that I
I have two classes, one of which is a subclass of another, and differs
I have two classes that can act as a delegate of a third class,
So my problem is that I have two classes with the same name. One
I have two classes. One is called Employee and the other EmployeeDetails that has

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.