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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:00:08+00:00 2026-06-12T09:00:08+00:00

Here is my code for the onOptionsItemSelected callback. I’m having issues with the item

  • 0

Here is my code for the onOptionsItemSelected callback. I’m having issues with the item with the id R.id.up:

@Override
public boolean onOptionsItemSelected(MenuItem item)
{
    switch (item.getItemId())
    {
    case R.id.can:
        can = false;
        sel = false;
        FileName.setEnabled(false);
        FileName.setText("");
        String[] values = new String[] {"Open", "Save (As)", "New"};
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, values);
        setListAdapter(adapter);
        return true;
    case R.id.sel:
        can = false;
        sel = false;
        SelDir = CurDir;
        if (SelDir != null)
        {
        try
        {
            file = new File(SelDir, (FileName.getText().toString() + ".txt"));
            w = new FileWriter(file);
            writer = new BufferedWriter(w);
            writer.write(TextEditor.getText().toString());
            writer.close();
        }
        catch (Exception e)
        {
            Toast.makeText(this, "Error:\n" + e.getMessage().toString(), Toast.LENGTH_LONG).show();
        }
        }
        else
        {
            Toast.makeText(this, "Error:\n" + "Please Select A Directory", Toast.LENGTH_LONG).show();
        }
        values = new String[] {"Open", "Save (As)", "New"};
        adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, values);
        setListAdapter(adapter);
        String temp = FileName.getText().toString() + ".txt";
        FileName.setText(SelDir + "/" + temp);
        FileName.setEnabled(false);
        SelDir = null;
        return true;
    case R.id.up:
        if (CurDir != homeDir)
        {
            CurDir = CurDir.substring(0, CurDir.lastIndexOf("/") - 1);
            dir = new File(CurDir);
            values = dir.list(filter);
            adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, values);
            setListAdapter(adapter);
        }
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

When I press the item R.id.up my app force closes. The other two items work fine. I could not find the problem with my code.

EDIT:
The logcat with the exception:

10-03 11:57:45.952: E/AndroidRuntime(18460): FATAL EXCEPTION: main
10-03 11:57:45.952: E/AndroidRuntime(18460): java.lang.NullPointerException
10-03 11:57:45.952: E/AndroidRuntime(18460):    at java.util.Arrays$ArrayList.<init>(Arrays.java:47)
10-03 11:57:45.952: E/AndroidRuntime(18460):    at java.util.Arrays.asList(Arrays.java:169)
10-03 11:57:45.952: E/AndroidRuntime(18460):    at android.widget.ArrayAdapter.<init>(ArrayAdapter.java:125)
10-03 11:57:45.952: E/AndroidRuntime(18460):    at com.IPP.EZPadd.EZPaddActivity.onOptionsItemSelected(EZPaddActivity.java:102)
10-03 11:57:45.952: E/AndroidRuntime(18460):    at android.app.Activity.onMenuItemSelected(Activity.java:2205)
10-03 11:57:45.952: E/AndroidRuntime(18460):    at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:823)
10-03 11:57:45.952: E/AndroidRuntime(18460):    at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:143)
10-03 11:57:45.952: E/AndroidRuntime(18460):    at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:855)
10-03 11:57:45.952: E/AndroidRuntime(18460):    at com.android.internal.view.menu.IconMenuView.invokeItem(IconMenuView.java:532)
10-03 11:57:45.952: E/AndroidRuntime(18460):    at com.android.internal.view.menu.IconMenuItemView.performClick(IconMenuItemView.java:122)
10-03 11:57:45.952: E/AndroidRuntime(18460):    at android.view.View$PerformClick.run(View.java:9081)
10-03 11:57:45.952: E/AndroidRuntime(18460):    at android.os.Handler.handleCallback(Handler.java:587)
10-03 11:57:45.952: E/AndroidRuntime(18460):    at android.os.Handler.dispatchMessage(Handler.java:92)
10-03 11:57:45.952: E/AndroidRuntime(18460):    at android.os.Looper.loop(Looper.java:130)
10-03 11:57:45.952: E/AndroidRuntime(18460):    at android.app.ActivityThread.main(ActivityThread.java:3686)
10-03 11:57:45.952: E/AndroidRuntime(18460):    at java.lang.reflect.Method.invokeNative(Native Method)
10-03 11:57:45.952: E/AndroidRuntime(18460):    at java.lang.reflect.Method.invoke(Method.java:507)
10-03 11:57:45.952: E/AndroidRuntime(18460):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
10-03 11:57:45.952: E/AndroidRuntime(18460):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
10-03 11:57:45.952: E/AndroidRuntime(18460):    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-06-12T09:00:10+00:00Added an answer on June 12, 2026 at 9:00 am

    I changed:

    CurDir = CurDir.substring(0, CurDir.lastIndexOf("/") - 1);
    

    to:

    CurDir = CurDir.substring(0, CurDir.lastIndexOf("/"));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the relevant code: @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) {
Here's a section of my code : @Override public boolean onOptionsItemSelected(MenuItem item) { switch
Here is my Code: @Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater();
Here a code to demonstrate an annoying problem: class A { public: A(): m_b(1),
Here is code example class A{ int i; public: A(int i) : i(i) {}
Here is my code: public class TasksList extends ListActivity { ... private static final
The script is on jsfiddle here : CODE What it does at the moment
Ok the error is showing up somewhere in this here code if($error==false) { $query
Here is code my jqgrid editing through form. $(#DataEnergy).jqGrid('navGrid', '#pagergrid', {}, //options {editdata: {
Here my code, I need to insert into mysql database I have mysql,php,android 1)

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.