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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:46:36+00:00 2026-06-10T00:46:36+00:00

it might be my limited experience, but I just ran into a weird error

  • 0

it might be my limited experience, but I just ran into a weird error which confuses me. I have an Activity with a bunch of buttons which are then assigned into a 2-Dimensional Array (btns[][]). Initially, I used to set an OnClick Listener by using an anonymous class, which would basically be the following, for each and every button:

btns[x][y].setOnClickListener(new OnClickListener(() {
    onClick(View v) {
        btns_OnClick(x, y, btns[x][y]);
    }

Not that x and y in this case were hard coded constants.

Since this was really bugging me, I implemented:

private class TimerButtonOnClickListener implements OnClickListener {
    int[] crds;

    public TimerButtonOnClickListener(int row, int col) {
        crds = new int[] { row, col };
    }

    public void onClick(View v) {
        btns_OnClick(crds[0], crds[1],
        btns[crds[0]][crds[1]]);
    }
}

And assign the Listener to the Buttons as follows:

    for (int i = 0; i < 6; i++)
        for (int j = 0; j < 2; j++)
            btns[i][j].setOnClickListener(new TimerButtonOnClickListener(i, j));

The above happens in onCreate, yet the crash does not occur immediately. Actually, I have no Idea where it crashes. LogCat gives

FATAL EXCEPTION: main
 java.lang.NullPointerException
    at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:1061)
    at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:1078)
    at android.os.Handler.handleCallback(Handler.java:605)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4340)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
    at dalvik.system.NativeStart.main(Native Method)

I use a handler to invoke a ui update from a Timer Task, but even if I remove the timer I still receive this error, so its probably not my own Handler breaking there.

I did not make any changes to the source apart from that. (I even diff’d, and I also didn’t touch any other file.)

What did I do wrong?

  • 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-10T00:46:38+00:00Added an answer on June 10, 2026 at 12:46 am

    The error is not related to buttons. The stacktrace would mention “button”, “onClick” or something button related if that was the case.

    Instead the NullPointerException happens while the system connects to a Service. Looking at the source for the place where the exception happens

    at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:1061)

    if (service != null) {
        // mConnection is a ServiceConnection
        mConnection.onServiceConnected(name, service); // 1061
    }
    

    one can see that it is most likely related to Context#bindService() with a null ServiceConnection

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

Sidebar

Related Questions

This might come across as a simple question, but I have very limited experience
My possibilities are limited, as I do have a nice host but can just
I might have a flawed understanding of what shared_examples_for should do, but hear me
The questions might have been already asked, but I want to understand if iPhone's
Let me preface this with.. I have extremely limited experience with ASM, and even
I'm developing a WinForms application in C#. I have limited experience in GUI programming,
this might be the easiest problem to solve but I have searched through the
Might be my question sounds more naive. But I wanted to know if it
Might be my question is abstract or out of context, but i am asking
Might be a bit of noob question but it's something that's been getting me

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.