Home Why my app doesnt pass to the next activity
Reply: 0

Why my app doesnt pass to the next activity

user2785
1#
user2785 Published in August 15, 2018, 8:38 pm

This question already has an answer here:

  • What is a NumberFormatException and how can I fix it? 9 answers

im trying to pass from the main activity to the second activity and also pass a number and it doesn't work can someone show my what my mistake is

p.s can anyone tell me how to do i make a loop that stops for the user to press the button to add text in the EditText and then reset the EditText and wait for him again to insert another text until an array is filled

thank you!!

public class MainActivity extends AppCompatActivity {

public static int numOfSails;
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

try{
    Button nextButton = (Button) findViewById(R.id.next_button);
    EditText sailsNumET = (EditText) findViewById(R.id.sails_num);
    numOfSails = Integer.parseInt(sailsNumET.toString());
    nextButton.setOnClickListener(new View.OnClickListener(){
        @Override
        public void onClick(View view){
            Intent addingIntent = new Intent(MainActivity.this,AddingActivity.class);
            addingIntent.putExtra("nos",numOfSails);
            startActivity(addingIntent);

        }
    });


     }catch(NumberFormatException e){

  }
 }
}

and in the second activity this is the code

public class AddingActivity extends AppCompatActivity {
public ArrayList<Sail> sails = new ArrayList<Sail>();
public static int numOfSails;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.adding_main);
    final Button addButton = (Button) findViewById(R.id.add_button);
    final EditText minusInGallonsET = (EditText) findViewById(R.id.gallons_num);
    final TextView counterET = (TextView) findViewById(R.id.counter_id);
    Bundle bundle = getIntent().getExtras();
    this.numOfSails = bundle.getInt("nos",0);
    for (int i = 0 ; i< numOfSails; i++){
        sails.add(new Sail());
    }

    addButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            int counter = 0;
            for (Sail s : sails){
                s.setFuelInGallons(Integer.parseInt(minusInGallonsET.toString()));
                s.setSailNum(counter);
                counter++;
                counterET.setText(counter);
            }
               }
    });

 }
}
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.312136 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO