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

  • Home
  • SEARCH
  • 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 6078731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:52:00+00:00 2026-05-23T10:52:00+00:00

Could I get a NullPointerException because the button I am referencing is nested inside

  • 0

Could I get a NullPointerException because the button I am referencing is nested inside several layouts? Any time I reference browseEditBtn I get an exception. It’s a simple button! Come’on.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

 android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<TableLayout 
android:layout_width="wrap_content" 
android:layout_height="wrap_content"
android:orientation="horizontal" 
android:stretchColumns="*">
<!-- <include layout="@layout/mydesctextview" /> -->
<TableRow 
android:id="@+id/tableRow1" 
android:layout_width="wrap_content"
android:layout_height="wrap_content" 
android:orientation="horizontal">

        <TextView 
        android:text="TextView" 
        android:layout_width="wrap_content"
        android:layout_gravity="left|center_vertical" 
        android:id="@+id/txtItem" 
        android:textSize="20dip" 

        ></TextView>



        <ImageButton

        android:src="@drawable/editbtn"
        android:layout_marginRight="10dip" 
        android:layout_gravity="right|center_vertical"
        android:id="@+id/browseEditBtn"
        android:background="@drawable/my_group_statelist"
        ></ImageButton>

</TableRow>
</TableLayout>
</LinearLayout>

Source Code (The Button is called in the main onCreate()):

public class BrowseActivity extends ExpandableListActivity {

final private String[] asColumnsToReturn = {
        Items.ITEMS_TABLE_NAME + "." + Items.ITEMS_ITEM,
        Items.ITEMS_TABLE_NAME + "." + Items.ITEMS_DESC,
        Items.ITEMS_TABLE_NAME + "." + Items.ITEMS_MANU,
        Items.ITEMS_TABLE_NAME + "." + Items.ITEMS_ID };

@SuppressWarnings("unchecked")
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.browse);
    DbHelper dbh = new DbHelper(this.getApplicationContext());
    SQLiteDatabase db = dbh.getWritableDatabase();
    SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();
    queryBuilder.setTables(Items.ITEMS_TABLE_NAME);

    ExpandableListView browseView = (ExpandableListView)    findViewById(android.R.id.list);
    Button editBrowseBtn = (Button) findViewById(R.id.browseEditBtn);

    Cursor mCursor = queryBuilder.query(db, asColumnsToReturn, null, null,
            null, null, Items.DEFAULT_SORT_ORDER);
    startManagingCursor(mCursor);

    SimpleExpandableListAdapter mAdapter = new SimpleExpandableListAdapter(
            this, createGroup(), R.layout.row, R.layout.row, new String[] {
                    Items.ITEMS_ITEM, Items.ITEMS_DESC }, new int[] {
                    R.id.txtItem, R.id.dscItem }, createChildren(),
            R.layout.exprow, new String[] { Items.ITEMS_DESC,
                    Items.ITEMS_MANU }, new int[] { R.id.dscItem,
                    R.id.manuItem });
    browseView.setAdapter(mAdapter);

    editBrowseBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent(BrowseActivity.this,
                    EditItemActivity.class);
            startActivity(intent);

        }
    });

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    menu.add("Add Item").setIntent(new Intent(this, AddItemActivity.class));

    return super.onCreateOptionsMenu(menu);
}

@SuppressWarnings("rawtypes")
public List createGroup() {
    DbHelper dbh = new DbHelper(this.getApplicationContext());
    SQLiteDatabase db = dbh.getWritableDatabase();
    SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();
    queryBuilder.setTables(Items.ITEMS_TABLE_NAME);

    Cursor mCursor = queryBuilder.query(db, new String[] {
            Items.ITEMS_ITEM, Items.ITEMS_DESC }, null, null, null, null,
            Items.DEFAULT_SORT_ORDER);
    startManagingCursor(mCursor);

    ArrayList<HashMap<String, String>> groupList = new ArrayList<HashMap<String,   String>>();
    mCursor.moveToFirst();
    while (!(mCursor.isAfterLast())) {

        HashMap<String, String> groupMap = new HashMap<String, String>();
        groupMap.put(Items.ITEMS_ITEM,
                mCursor.getString(mCursor.getColumnIndex(Items.ITEMS_ITEM)));
        groupMap.put(Items.ITEMS_DESC,
                      mCursor.getString(mCursor.getColumnIndex(Items.ITEMS_DESC)));

        groupList.add(groupMap);
        mCursor.moveToNext();
    }

    return (List) groupList;
}

@SuppressWarnings("rawtypes")
public List createChildren() {
    DbHelper dbh = new DbHelper(this.getApplicationContext());
    SQLiteDatabase db = dbh.getWritableDatabase();
    SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();
    queryBuilder.setTables(Items.ITEMS_TABLE_NAME);

    Cursor mCursor = queryBuilder.query(db, new String[] {
            Items.ITEMS_ITEM, Items.ITEMS_DESC, Items.ITEMS_MANU }, null,
            null, null, null, Items.DEFAULT_SORT_ORDER);
    startManagingCursor(mCursor);
    mCursor.moveToFirst();

    ArrayList<ArrayList<HashMap<String, String>>> childList = new ArrayList<ArrayList<HashMap<String, String>>>();

    while (!(mCursor.isAfterLast())) {

        ArrayList<HashMap<String, String>> childListDesc = new                      ArrayList<HashMap<String, String>>();

        for (int i = 0; i < 1; i++) {
            HashMap<String, String> childMap = new HashMap<String, String>();
            childMap.put(Items.ITEMS_DESC, mCursor.getString(mCursor
                    .getColumnIndex(Items.ITEMS_DESC)));
            childMap.put(Items.ITEMS_MANU, mCursor.getString(mCursor
                    .getColumnIndex(Items.ITEMS_MANU)));

            childListDesc.add(childMap);

        }

        childList.add(childListDesc);
        mCursor.moveToNext();
    }

    return (List) childList;
}
}

And finally the logcat, I think…

06-30 13:01:29.390: ERROR/AndroidRuntime(9189): FATAL EXCEPTION: main
06-30 13:01:29.390: ERROR/AndroidRuntime(9189): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.simplyDesign.mdk/com.simplyDesign.mdk.BrowseActivity}: java.lang.NullPointerException
06-30 13:01:29.390: ERROR/AndroidRuntime(9189): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
06-30 13:01:29.390: ERROR/AndroidRuntime(9189): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
06-30 13:01:29.390: ERROR/AndroidRuntime(9189): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
06-30 13:01:29.390: ERROR/AndroidRuntime(9189): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
06-30 13:01:29.390: ERROR/AndroidRuntime(9189): at android.os.Handler.dispatchMessage(Handler.java:99)
06-30 13:01:29.390: ERROR/AndroidRuntime(9189): at android.os.Looper.loop(Looper.java:123)
06-30 13:01:29.390: ERROR/AndroidRuntime(9189): at android.app.ActivityThread.main(ActivityThread.java:4627)
06-30 13:01:29.390: ERROR/AndroidRuntime(9189): at java.lang.reflect.Method.invokeNative(Native Method)
06-30 13:01:29.390: ERROR/AndroidRuntime(9189): at java.lang.reflect.Method.invoke(Method.java:521)
06-30 13:01:29.390: ERROR/AndroidRuntime(9189): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
06-30 13:01:29.390: ERROR/AndroidRuntime(9189): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
06-30 13:01:29.390: ERROR/AndroidRuntime(9189): at dalvik.system.NativeStart.main(Native Method)
06-30 13:01:29.390: ERROR/AndroidRuntime(9189): Caused by: java.lang.NullPointerException
06-30 13:01:29.390: ERROR/AndroidRuntime(9189): at com.simplyDesign.mdk.BrowseActivity.onCreate(BrowseActivity.java:62)
06-30 13:01:29.390: ERROR/AndroidRuntime(9189): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
06-30 13:01:29.390: ERROR/AndroidRuntime(9189): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
06-30 13:01:29.390: ERROR/AndroidRuntime(9189): … 11 more

edit_01

public void doAction(View v) {

    startActivity(new Intent(getApplicationContext(),
            EditItemActivity.class));

}

I have used other buttons in the past to point to EditItemActivity and they have worked fine.

  • 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-23T10:52:01+00:00Added an answer on May 23, 2026 at 10:52 am

    What is the name of the layout XML file that you posted? It doesn’t appear to be browse.xml because that one has your ExpandableListView in it. The IDs that you reference in your Java code must appear in the content View that you set; otherwise, you must inflate the View yourself.

    Edit

    You would add something like

    android:onClick="doAction"
    

    to the XML of that ImageButton.

    Then you would have a doAction(View v) method in your Activity that would do your onClick actions.

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

Sidebar

Related Questions

Is there any way that I could get the source of a website (as
I could get the keyboard to work but on a UITextView but some how
Wondering if I could get some advice and direction on this following requirement: Need
hi im doing a loop so i could get dict of data, but since
I was wondering if there was somewhere I could get some starter kit /
Can anyone point me in the direction of how I could get a NUnit
I need to do the following and i was wondering if i could get
Apologies for the long post, but I wonder if I could get some more
Could I get some confirmations from the community that I'm not going mad, and
Could i get the apache mod_rewrite definition of urlbase via php scripting?

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.