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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:28:53+00:00 2026-05-22T16:28:53+00:00

My Main Activity extends ListActivity and displays a List. I am using custom Listitems

  • 0

My Main Activity extends ListActivity and displays a List. I am using custom Listitems defined in a class named DefinitionAdapter.
I also have a seperate class that implements OnClickListener.

In the class DefinitionAdapter I set the OnClickListener to the ListItems:

   public View getView(int position, View convertView, ViewGroup parent) {
        View v = convertView;
        if (v == null) {
            LayoutInflater vi = (LayoutInflater)getContext().getSystemService(
                    Context.LAYOUT_INFLATER_SERVICE);
            v = vi.inflate(R.layout.row, null);
        }
...

        v.setOnClickListener(new OnItemClickListener(position) );

        return v;
   }

My custom OnClickListener is supposed to start another activity.

public class OnItemClickListener implements OnClickListener extends Activity {


    private int position;

    public OnItemClickListener(int p) {

        position = p;   
    }

    @Override
    public void onClick(View v) {

        Intent intent = new Intent(this, ShowDefinition.class);
        startActivity(intent);

    }

}

I am not sure that I am doing that right. I added my new activity to the manifest, as well as the activity i extended the listener with:

<activity android:name="ShowDefinition" android:label="@string/app_name">
</activity>
<activity android:name="OnItemClickListener" android:label="@string/app_name">
</activity>    

Nonetheless, if I click on an Item in my List, the application always breaks with a NullPointerException. I think I am using the intent wrong… any Ideas?

In regard to Nikita Beloglazov’s comment:

It breaks when I create the Intent:

Intent intent = new Intent(this, ShowDefinition.class);

Here’s the stacktrace:

05-23 22:56:46.629: ERROR/AndroidRuntime(258): Uncaught handler: thread main exiting due to uncaught exception
05-23 22:56:46.659: ERROR/AndroidRuntime(258): java.lang.NullPointerException
05-23 22:56:46.659: ERROR/AndroidRuntime(258):     at android.content.ContextWrapper.getPackageName(ContextWrapper.java:120)
05-23 22:56:46.659: ERROR/AndroidRuntime(258):     at android.content.ComponentName.<init>(ComponentName.java:75)
05-23 22:56:46.659: ERROR/AndroidRuntime(258):     at android.content.Intent.<init>(Intent.java:2551)
05-23 22:56:46.659: ERROR/AndroidRuntime(258):     at com.andiandy.juradefinitions.OnItemClickListener.onClick(OnItemClickListener.java:22)
05-23 22:56:46.659: ERROR/AndroidRuntime(258):     at android.view.View.performClick(View.java:2364)
05-23 22:56:46.659: ERROR/AndroidRuntime(258):     at android.view.View.onTouchEvent(View.java:4179)
05-23 22:56:46.659: ERROR/AndroidRuntime(258):     at android.view.View.dispatchTouchEvent(View.java:3709)
05-23 22:56:46.659: ERROR/AndroidRuntime(258):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:852)
05-23 22:56:46.659: ERROR/AndroidRuntime(258):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
05-23 22:56:46.659: ERROR/AndroidRuntime(258):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
05-23 22:56:46.659: ERROR/AndroidRuntime(258):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
05-23 22:56:46.659: ERROR/AndroidRuntime(258):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
05-23 22:56:46.659: ERROR/AndroidRuntime(258):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
05-23 22:56:46.659: ERROR/AndroidRuntime(258):     at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
05-23 22:56:46.659: ERROR/AndroidRuntime(258):     at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
05-23 22:56:46.659: ERROR/AndroidRuntime(258):     at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
05-23 22:56:46.659: ERROR/AndroidRuntime(258):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
05-23 22:56:46.659: ERROR/AndroidRuntime(258):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
05-23 22:56:46.659: ERROR/AndroidRuntime(258):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-23 22:56:46.659: ERROR/AndroidRuntime(258):     at android.os.Looper.loop(Looper.java:123)
05-23 22:56:46.659: ERROR/AndroidRuntime(258):     at android.app.ActivityThread.main(ActivityThread.java:4363)
05-23 22:56:46.659: ERROR/AndroidRuntime(258):     at java.lang.reflect.Method.invokeNative(Native Method)
05-23 22:56:46.659: ERROR/AndroidRuntime(258):     at java.lang.reflect.Method.invoke(Method.java:521)
05-23 22:56:46.659: ERROR/AndroidRuntime(258):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
05-23 22:56:46.659: ERROR/AndroidRuntime(258):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
05-23 22:56:46.659: ERROR/AndroidRuntime(258):     at dalvik.system.NativeStart.main(Native Method)
  • 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-22T16:28:53+00:00Added an answer on May 22, 2026 at 4:28 pm

    Your OnItemClickListener should not extend Activity. Instead, you should arrange for the OnItemClickListener to have access to your ListActivity instance. Any view that is already part of the activity (like the ListView) has access to the ListActivity instance via getContext(). Then implement onClick like this:

    @Override
    public void onClick(View v) {
        Intent intent = new Intent(context, ShowDefinition.class);
        context.startActivity(intent);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a main class which extends Activity which should spawn a ListActivity and
I have following goal: From a list in main activity that extends ListActivity, I
I have 3 classes in my example: Class A, the main activity. Class A
My current application has one Activity, the main one which extends ListActivity (listview of
I have implemented custom title bar feature using the following class CustomWindow . Other
I have a two layouts files in my app. Also I have Activity extends
For tracking user activity, I am using a Windows Hook for the main application
I have a widget that supposed to call an Activity of the main app
Say if I have a locationManager(LM) object in activity A, which is my main
The code below give generate the ListView public class MyList extends ListActivity { static

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.