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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:26:40+00:00 2026-06-04T15:26:40+00:00

I have an option menu in Android. Now it has got 5 options. When

  • 0

I have an option menu in Android. Now it has got 5 options. When I push one button ther comes up an toast, I push another and it starts an activity. That works all fine. Now I want to add another option. When I choose that option on the emulator I want it to change a text, change the image resource of an imageview, and set the visibility of some textviews to View.GONE in another xml and then start the activity whose layout is that xml file. I do the following:

    ...Previous menu options
    case R.id.sample:
    TextView tv1 = (TextView) findViewById(R.id.tv1);
    tv1.setText("This is the new text");
    tv1.setVisibility(View.GONE);
    ImageView iv = (ImageView) findViewById(R.id.iv1);
    iv.setImageResource(R.drawable.image);
    return true;
    following menu options...

When I run it on the emulator and I click this option in the option menu it says:”The application example (process com.android.example) has stopped unexpectedly. Please try again.” I already did a project clean, but it doesn’t help either. The logcat says:

05-25 19:25:19.357: E/AndroidRuntime(283): FATAL EXCEPTION: main
05-25 19:25:19.357: E/AndroidRuntime(283): java.lang.NullPointerException
05-25 19:25:19.357: E/AndroidRuntime(283):  at com.android.example.SampleOption.onOptionsItemSelected(Sample.java:349)
05-25 19:25:19.357: E/AndroidRuntime(283):  at android.app.Activity.onMenuItemSelected(Activity.java:2195)
05-25 19:25:19.357: E/AndroidRuntime(283):  at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:730)
05-25 19:25:19.357: E/AndroidRuntime(283):  at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:143)
05-25 19:25:19.357: E/AndroidRuntime(283):  at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:855)
05-25 19:25:19.357: E/AndroidRuntime(283):  at com.android.internal.view.menu.IconMenuView.invokeItem(IconMenuView.java:532)
05-25 19:25:19.357: E/AndroidRuntime(283):  at com.android.internal.view.menu.IconMenuItemView.performClick(IconMenuItemView.java:122)
05-25 19:25:19.357: E/AndroidRuntime(283):  at android.view.View$PerformClick.run(View.java:8816)
05-25 19:25:19.357: E/AndroidRuntime(283):  at android.os.Handler.handleCallback(Handler.java:587)
05-25 19:25:19.357: E/AndroidRuntime(283):  at android.os.Handler.dispatchMessage(Handler.java:92)
05-25 19:25:19.357: E/AndroidRuntime(283):  at android.os.Looper.loop(Looper.java:123)
05-25 19:25:19.357: E/AndroidRuntime(283):  at android.app.ActivityThread.main(ActivityThread.java:4627)
05-25 19:25:19.357: E/AndroidRuntime(283):  at java.lang.reflect.Method.invokeNative(Native Method)
05-25 19:25:19.357: E/AndroidRuntime(283):  at java.lang.reflect.Method.invoke(Method.java:521)
05-25 19:25:19.357: E/AndroidRuntime(283):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-25 19:25:19.357: E/AndroidRuntime(283):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-25 19:25:19.357: E/AndroidRuntime(283):  at dalvik.system.NativeStart.main(Native Method)
05-25 19:25:23.127: I/Process(283): Sending signal. PID: 283 SIG: 9

Does anybody know what I’m doing wrong?

Forward thanks.

  • 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-04T15:26:42+00:00Added an answer on June 4, 2026 at 3:26 pm

    …and set the visibility of some textviews to View.GONE in another xml and then start the activity whose layout is that xml file.

    You can’t do this. Searching for the TextView tv1 in the other Activity‘s(simply using findViewById will search for that TextView in the current Activity‘s layout) layout will not find the TextView and this will result on tv1 being null. When you’ll try to set the text on it it will throw the NullPointerException.

    If I understood what are you trying to do, then pass a boolean value in the Intent that you use to start the new Activity and in that Activity‘s onCreate method check the value of that boolean value from the Intent and then change the visibility of the desired Views.

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

Sidebar

Related Questions

I am developing android application in which i have to open option menu from
I have a popup menu that has a few items in it. Option 1
I have option menu on my activity. I am displaying another activity on click
i have an option to mute in my menu options like this: <?xml version=1.0
How do I change the options menu at run-time in android 2.3.3? I have
I have an options_menu.xml file like this: <?xml version=1.0 encoding=utf-8?> <menu xmlns:android=http://schemas.android.com/apk/res/android> <item android:id=@+id/search
I have a html select list menu,when user select an option he/she is redirected
I have some code that first selects an option value in a dropdown menu
i have created an options menu for my database class. Upon launching the options
I have setup my site with 5 pages which are my menu options. When

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.