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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:53:35+00:00 2026-05-24T12:53:35+00:00

I am trying to do the same as the question in here. Static options

  • 0

I am trying to do the same as the question in here.

Static options menu

However, following the 2nd option of the 1st answer gives me a null pointer exception. Basically it does not work. What am I missing. Below are my code files.

Thank you very much in advance.

AppSetup.java

    package com.connectionmanager.app;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class AppSetup extends Activity implements OnClickListener  
{
    private AcmMenu acmMenu;
    private Context appContext;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.app_setup);

        appContext = this.getApplicationContext();
        Log.v("Hello","Bringing up application setup Dialog box");

        //Set up buttons
        Button btnSave = (Button) findViewById(R.id.ButtonSave);
        Button btnContinue = (Button) findViewById(R.id.ButtonContinue);
        btnSave.setOnClickListener(this);
        btnContinue.setOnClickListener(this);

        this.resetLabels();
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) 
    {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            this.finish();
            Log.v("Hello","Back key pressed");
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) 
    {
        acmMenu = new AcmMenu(menu,this.getApplicationContext());
        acmMenu.inflate();
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) 
    {
        acmMenu.onSelectedItem(item,appContext );
        return true;
    }

    @Override
    public void onClick(View arg0) {
        // TODO Auto-generated method stub
        if(arg0.getId() == (R.id.ButtonSave))
        {
            // Save information and then finish.
            AppDatabase db = new AppDatabase(this.getApplicationContext());

            db.setHostname( ((EditText)findViewById(R.id.editText_hostname)).getText().toString());
            db.setRegistrationUrl(((EditText)findViewById(R.id.editText_registration)).getText().toString());
            db.setSsid(((EditText)findViewById(R.id.editText_ssid)).getText().toString());

            db.closeDb();

            this.resetLabels();
        }
        if(arg0.getId() == (R.id.ButtonContinue))
        {
            this.finish();
        }
    }

    private void resetLabels()
    {
        //Get and set existing values from the database.
        AppDatabase db = new AppDatabase(this.getApplicationContext());
        Log.v("Hello","Hostname from app:" +db.getHostname() );

        TextView hostname_current = (TextView)findViewById(R.id.lbl_hostname_current);
        hostname_current.setText("(Current: "+db.getHostname()+")");
        ((EditText)findViewById(R.id.editText_hostname)).setText(db.getHostname());

        TextView registration_current = (TextView)findViewById(R.id.lbl_registration_current);
        registration_current.setText("(Current: "+db.getRegistrationUrl()+")");
        ((EditText)findViewById(R.id.editText_registration)).setText(db.getRegistrationUrl());

        TextView chat_current = (TextView)findViewById(R.id.lbl_chat_current);
        //chat_current.setText("(Current: "+db.getRegistrationUrl()+")");
        //((EditText)findViewById(R.id.editText_chat)).setText(db.getRegistrationUrl());

        TextView ssid_current = (TextView)findViewById(R.id.lbl_ssid_current);
        ssid_current.setText("(Current: "+db.getSsid()+")");
        ((EditText)findViewById(R.id.editText_ssid)).setText(db.getSsid());

        db.closeDb();
    }
}

AcmMenu.java

package com.connectionmanager.app;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;

public class AcmMenu extends Activity{

    private Menu acmMenu;
    private static Context classContext;

    public AcmMenu(Menu menu, Context cont)
    {
        classContext = cont;
        acmMenu = menu;
    }

    public void inflate()
    {
        if (classContext == null)
        {
            Log.v("Hello","Context null");
        }
        else
        {
            MenuInflater inflater = new MenuInflater(classContext);
            inflater.inflate(R.menu.acm_menu, acmMenu);
        }

    }

    public void onSelectedItem(MenuItem item, Context con)
    {
        Log.v("Hello","Starting activity");
        Intent gotoHelpScreen = new Intent(con, Help.class);

        try
        {
            startActivity(new Intent(con, NewUserAccount.class));
        }
        catch (Exception e)
        {
            e.printStackTrace();
            Log.v("Hello","Exception: " + e.toString());
        }


        /*/ Handle item selection
        switch (item.getItemId()) 
        {
        case R.id.menu_wifi:
            toggleWifi();
            return true;
        case R.id.menu_account:
            gotoAccounts();
            return true;
        case R.id.menu_help:
            showHelp();
            return true;
        default:
            return super.onOptionsItemSelected(item);
        }*/
    }

    private void toggleWifi()
    {

    }

    private void gotoAccounts()
    {

    }

    private void showHelp()
    {

    }
}

Help.java

package com.connectionmanager.app;

import android.app.Activity;
import android.os.Bundle;

public class Help extends Activity {

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.help);

    }

}

Manifest file

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.connectionmanager.app"
      android:versionCode="1"
      android:versionName="1.0">

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />

    <application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true">
        <activity android:name=".CMapp"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".NewUserAccount" />
        <activity android:name=".FoundSavedUser" />
        <activity android:name=".AppSetup" />
        <activity android:name=".Help" />
    </application>
</manifest>

Stacktrace

 05-27 12:07:03.930: WARN/Server(7134): Addition of the standard header "cache-control" is not allowed. Please use the equivalent property in the Restlet API.
05-27 12:07:03.930: WARN/Server(7134): Addition of the standard header "expires" is not allowed. Please use the equivalent property in the Restlet API.
05-27 12:07:03.961: WARN/System.err(8135): java.lang.NullPointerException
05-27 12:07:03.961: WARN/System.err(8135):     at android.app.Activity.startActivityForResult(Activity.java:2890)
05-27 12:07:03.961: WARN/System.err(8135):     at android.app.Activity.startActivity(Activity.java:2996)
05-27 12:07:03.961: WARN/System.err(8135):     at com.connectionmanager.app.AcmMenu.onSelectedItem(AcmMenu.java:43)
05-27 12:07:03.961: WARN/System.err(8135):     at com.connectionmanager.app.AppSetup.onOptionsItemSelected(AppSetup.java:61)
05-27 12:07:03.961: WARN/System.err(8135):     at android.app.Activity.onMenuItemSelected(Activity.java:2234)
05-27 12:07:03.970: WARN/System.err(8135):     at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:747)
05-27 12:07:03.970: WARN/System.err(8135):     at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:160)
05-27 12:07:03.970: WARN/System.err(8135):     at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:886)
05-27 12:07:03.970: WARN/System.err(8135):     at com.android.internal.view.menu.IconMenuView.invokeItem(IconMenuView.java:545)
05-27 12:07:03.970: WARN/System.err(8135):     at com.android.internal.view.menu.IconMenuItemView.performClick(IconMenuItemView.java:122)
05-27 12:07:03.970: WARN/System.err(8135):     at android.view.View$PerformClick.run(View.java:8867)
05-27 12:07:03.970: WARN/System.err(8135):     at android.os.Handler.handleCallback(Handler.java:587)
05-27 12:07:03.970: WARN/System.err(8135):     at android.os.Handler.dispatchMessage(Handler.java:92)
05-27 12:07:03.970: WARN/System.err(8135):     at android.os.Looper.loop(Looper.java:143)
05-27 12:07:03.970: WARN/System.err(8135):     at android.app.ActivityThread.main(ActivityThread.java:5068)
05-27 12:07:03.970: WARN/System.err(8135):     at java.lang.reflect.Method.invokeNative(Native Method)
05-27 12:07:03.970: WARN/System.err(8135):     at java.lang.reflect.Method.invoke(Method.java:521)
05-27 12:07:03.970: WARN/System.err(8135):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
05-27 12:07:03.970: WARN/System.err(8135):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
05-27 12:07:03.970: WARN/System.err(8135):     at dalvik.system.NativeStart.main(Native Method)
05-27 12:07:03.980: VERBOSE/WindowManager(1292): Remove Window{4757e618 AtchDlg:com.connectionmanager.app/com.connectionmanager.app.AppSetup paused=false}: mSurface=Surface(name=AtchDlg:com.connectionmanager.app/com.connectionmanager.app.AppSetup, identity=1792) mExiting=false isAnimating=false app-animation=null inPendingTransaction=false mDisplayFrozen=false
05-27 12:07:03.990: ERROR/WindowManager(1292): return in removeWindowLocked
05-27 12:07:04.000: DEBUG/InputManagerService(1292): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@475c3990
  • 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-24T12:53:37+00:00Added an answer on May 24, 2026 at 12:53 pm

    Try something like this :

     public void onSelectedItem(MenuItem item, Context con){
            Intent intent = new Intent();
            intent.setClass(con, NewUserAccount.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            con.startActivity(intent);
            this.finish();      
         }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to achieve the same behavior as indicated in the following post.
I've posted the same question here and I've also got couple of good answers
I found the exact same question here . But it isn't working for me.
I finally decided to post a question here after some time spent trying to
I am trying to understand generics. Here's an example of one: public static bool
i'm trying to add some animated gif into static image (canvas), here's my start
I am trying to use same validation function for all my controls. But I
I trying to call 2 functions in the same page to submit jquery-ajax at
Basically I'm trying to accomplish the same thing that mailto:bgates@microsoft.com does in Internet Explorer
I am trying to save data into the same table several times from the

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.