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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:10:54+00:00 2026-06-08T12:10:54+00:00

I keep getting an error for this application every time I press the menu

  • 0

I keep getting an error for this application every time I press the menu button –> History to start the History.java class. I’m fairly certain it has to do with the Bundle method for sending the two arrays from the TipBookActivity.java class to the History.java class.

Below is the TipBookActivity code:

public class TipBookActivity extends Activity {
/** Called when the activity is first created. */

TextView textTip,textHour,textWage;
EditText editHour,editTip;
float wage;
int precision = 100;
String sTip,sHour;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    textTip = (TextView) findViewById(R.id.tvTip);
    textHour = (TextView) findViewById(R.id.tvHour);
    textWage = (TextView) findViewById(R.id.tvWage);
    editTip = (EditText) findViewById(R.id.etTip);
    editHour = (EditText) findViewById(R.id.etHour);
    Button bSubmit = (Button) findViewById(R.id.bSubmit);
    final Bundle bTip = new Bundle();
    final Bundle bHour = new Bundle();
    final ArrayList<String> tipList = new ArrayList<String>();    
    final ArrayList<String> hourList = new ArrayList<String>();
    bSubmit.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            textHour.setText(editHour.getText().toString());
            textTip.setText(editTip.getText().toString());
            wage = Float.parseFloat(textTip.getText().toString()) / Float.parseFloat(textHour.getText().toString());
            String tip = String.format("$%.2f",wage);
            textWage.setText(String.valueOf(tip) + " an hour");     
            textHour.setText(editHour.getText() + " Hour(s)");
            textTip.setText("$" + editTip.getText());
            bTip.putStringArray(sTip,new String[] {editTip.getText().toString()});
            bHour.putStringArray(sHour,new String[] {editHour.getText().toString()});
            tipList.addAll(Arrays.asList(sTip));
            hourList.addAll(Arrays.asList(sHour));
            Intent i = new Intent(TipBookActivity.this,History.class);
            i.putExtras(bTip);
            i.putExtras(bHour);
        }       
    });
}

public boolean onCreateOptionsMenu(Menu menu){
    super.onCreateOptionsMenu(menu);
    MenuInflater mMain = getMenuInflater();
    mMain.inflate(R.menu.main_menu,menu);
    return true;
}

public boolean onOptionsItemSelected(MenuItem item){
    switch (item.getItemId()){
    case R.id.menuHistory:
         startActivity(new Intent("com.smarticle.tipbook.HISTORY"));            
         return true;
    case R.id.menuClear:
        //set up next tutorials
        Toast display = Toast.makeText(this, "Clear History feature coming soon.", Toast.LENGTH_SHORT);
        display.show();
        return true;
    }
    return false;
}
}

The History class code:

public class History extends Activity{

private ListView mainListViewTip;
private ListView mainListViewHour;
private ArrayAdapter<String>listAdapterTip;
private ArrayAdapter<String>listAdapterHour;
String sTip,sHour;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.history_main);
    Bundle bTip = this.getIntent().getExtras();
    Bundle bHour = this.getIntent().getExtras();
    String[] array1 = bTip.getStringArray(sTip);
    String[] array2 = bHour.getStringArray(sHour);
    ListView mainListViewTip = (ListView) findViewById(R.id.mainListViewTip);
    ListView mainListViewHour = (ListView) findViewById(R.id.mainListViewHour);
    ArrayList<String> tipList = new ArrayList<String>();
    ArrayList<String> hourList = new ArrayList<String>();
    tipList.addAll(Arrays.asList(sTip));
    hourList.addAll(Arrays.asList(sHour));
    listAdapterTip = new ArrayAdapter<String>(this,R.layout.simplerow,tipList);
    listAdapterHour = new ArrayAdapter<String>(this,R.layout.simplerow,hourList);
    mainListViewTip.setAdapter(listAdapterTip);
    mainListViewHour.setAdapter(listAdapterHour);
}

}

Any help on identifying the error cause would be greatly appreciated. The code works (in theory, I think), it just won’t work in practice. The general idea is to input two numbers into EditText fields, save them as strings, display them as TextViews, set them as an ArrayList, then bundle and send them to the other class to display in a ListView.

  • 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-08T12:10:55+00:00Added an answer on June 8, 2026 at 12:10 pm

    You are not initializing sTip and sHour Strings in both Activities. so initializing sTip and Shour Strings with any constant value as in both Activities:

    String sTip="sTip",sHour="sHour";
    

    and from TipBookActivity you are not passing intent to startActivity so first declare Intent i globally then start your Activity as:

       TextView textTip,textHour,textWage;
        EditText editHour,editTip;
        float wage;
        int precision = 100;
        String sTip,sHour;
        Intent i; // declare here
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
    textTip = (TextView) findViewById(R.id.tvTip);
        textHour = (TextView) findViewById(R.id.tvHour);
        textWage = (TextView) findViewById(R.id.tvWage);
        editTip = (EditText) findViewById(R.id.etTip);
        editHour = (EditText) findViewById(R.id.etHour);
        Button bSubmit = (Button) findViewById(R.id.bSubmit);
        final Bundle bTip = new Bundle();
        final Bundle bHour = new Bundle();
        final ArrayList<String> tipList = new ArrayList<String>();    
        final ArrayList<String> hourList = new ArrayList<String>();
        bSubmit.setOnClickListener(new View.OnClickListener() {
    
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                textHour.setText(editHour.getText().toString());
                textTip.setText(editTip.getText().toString());
                wage = Float.parseFloat(textTip.getText().toString()) / Float.parseFloat(textHour.getText().toString());
                String tip = String.format("$%.2f",wage);
                textWage.setText(String.valueOf(tip) + " an hour");     
                textHour.setText(editHour.getText() + " Hour(s)");
                textTip.setText("$" + editTip.getText());
                bTip.putStringArray(sTip,new String[] {editTip.getText().toString()});
                bHour.putStringArray(sHour,new String[] {editHour.getText().toString()});
                tipList.addAll(Arrays.asList(sTip));
                hourList.addAll(Arrays.asList(sHour));
                i = new Intent(TipBookActivity.this,History.class);
                i.putExtras(bTip);
                i.putExtras(bHour);
            }       
        });
    }
        public boolean onOptionsItemSelected(MenuItem item){
            switch (item.getItemId()){
            case R.id.menuHistory:
                 startActivity(i));        // start Activity here by passing intent    
                 return true;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I keep getting this error every time I try to emulate pra application on
I keep getting this weird error message every time I'm testing my app on
When using ANT to build my Java application I keep getting this error. I
I keep getting this error in my RCP application any time I try to
I keep getting this error with my Play 2.0 application: play.core.ActionInvoker$$anonfun$receive$1$$anon$1: Execution exception [[MatchError:
I keep getting this error in my application and can't figure out what it
I have a rails application and i keep getting this error /srv/projects/app/controllers/application_controller.rb:174: invalid multibyte
We keep getting this error randomly in our web application. System.Data.SqlClient.SqlException: A network-related or
On first load of my Silverlight application I keep getting this error: Could not
I keep getting this error when I deploy my application in the server machine

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.