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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:55:25+00:00 2026-05-20T10:55:25+00:00

My application was running fine until i added the following code to add an

  • 0

My application was running fine until i added the following code to add an options Menu to my main Activity:

@Override
public boolean onCreateOptionsMenu(Menu menu) {

        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.wantlist_menu, menu);
        return true;
}

The Menu Resource looks as follows:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:enabled="true" android:visible="true" android:id="@+id/clearImageCashe"   android:title="@string/clearImageCache"></item>
</menu>

Everything is compiling but i get the following NullpointerException:

03-03 19:11:09.001: ERROR/AndroidRuntime(341): java.lang.RuntimeException: Unable to   start activity      ComponentInfo{de.kosmowski.discogs.wants/de.kosmowski.discogs.wants.activities.wantlist}:       java.lang.NullPointerException
03-03 19:11:09.001: ERROR/AndroidRuntime(341):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
03-03 19:11:09.001: ERROR/AndroidRuntime(341):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
03-03 19:11:09.001: ERROR/AndroidRuntime(341):     at android.app.ActivityThread.access$2200(ActivityThread.java:119)
03-03 19:11:09.001: ERROR/AndroidRuntime(341):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
03-03 19:11:09.001: ERROR/AndroidRuntime(341):     at android.os.Handler.dispatchMessage(Handler.java:99)
03-03 19:11:09.001: ERROR/AndroidRuntime(341):     at android.os.Looper.loop(Looper.java:123)
03-03 19:11:09.001: ERROR/AndroidRuntime(341):     at android.app.ActivityThread.main(ActivityThread.java:4363)
03-03 19:11:09.001: ERROR/AndroidRuntime(341):     at java.lang.reflect.Method.invokeNative(Native Method)
03-03 19:11:09.001: ERROR/AndroidRuntime(341):     at java.lang.reflect.Method.invoke(Method.java:521)
03-03 19:11:09.001: ERROR/AndroidRuntime(341):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
03-03 19:11:09.001: ERROR/AndroidRuntime(341):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
03-03 19:11:09.001: ERROR/AndroidRuntime(341):     at dalvik.system.NativeStart.main(Native Method)
03-03 19:11:09.001: ERROR/AndroidRuntime(341): Caused by: java.lang.NullPointerException
03-03 19:11:09.001: ERROR/AndroidRuntime(341):     at de.kosmowski.discogs.wants.activities.wantlist.onCreate(wantlist.java:49)
03-03 19:11:09.001: ERROR/AndroidRuntime(341):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-03 19:11:09.001: ERROR/AndroidRuntime(341):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
03-03 19:11:09.001: ERROR/AndroidRuntime(341):     ... 11 more

It says there would be a NullPointer Exception at

Caused by: java.lang.NullPointerException
03-03 19:11:09.001: ERROR/AndroidRuntime(341):     at de.kosmowski.discogs.wants.activities.wantlist.onCreate(wantlist.java:49)

But the Code at this line just worked fine before and if i comment it out, the same error appears at some lines below. That makes no sense to me.

I just can’t figure out what is going on here.

Last but not least the complete activity class (without imports):

public class wantlist extends Activity implements OnClickListener {
/** Called when the activity is first created. */

ArrayList<Want> wants = new ArrayList<Want>();

@Override
public void onCreate(Bundle savedInstanceState) {        

    wants.add(new Want("Want1"));
    wants.add(new Want("Want2"));
    wants.add(new Want("Want3"));
    wants.add(new Want("Want4"));
    wants.add(new Want("Want5"));

    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);

    ListView lv = (ListView) findViewById(R.id.WantList); 
    ImageButton b = (ImageButton) findViewById(R.id.searchbutton);
    b.setOnClickListener(this); //NullPointerException here


    lv.setAdapter(new WantAdapter(this,
            R.layout.lplistitem, wants));
    lv.setTextFilterEnabled(true);

}

public void onClick(View v) {
    onSearchRequested();

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {

        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.wantlist_menu, menu);
        return true;
}

}

Just to be sure here’s the main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<RelativeLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<ImageButton android:gravity="right" android:layout_alignParentRight="true"   android:src="@drawable/searchbutton" android:text="@string/search" android:id="@+id/searchbutton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:visibility="visible"></ImageButton>
</RelativeLayout>

<ListView android:layout_height="wrap_content" android:layout_width="fill_parent" android:id="@+id/WantList"></ListView>
</LinearLayout>

thanks in advance.

  • 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-20T10:55:26+00:00Added an answer on May 20, 2026 at 10:55 am

    Deleting the class R.java and letting Eclipse regenerate it solved it!

    I think for any reason R.java was confused about some of the ids.

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

Sidebar

Related Questions

Following is one of my application activity xml.Its running fine but the problem was
My Sinatra application was running fine on Dreamhost until a few days ago (I'm
I have a Rails application running on Rails 2.3.9. It runs fine with ruby
I have Rails 3 application (running Rails RC1), and I have the following controller:
I'm running an application on heroku - it appears to function just fine and
I have a rails application running on a Linux server. I would like to
I have an application running in tomcat that has a bunch of configuration files
I have a web application running on a Gentoo-based LAMP stack. My customers buy
I have a windows application running at the backend. I have functions in this
I have an application running only on Windows and a batch file that launches

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.