Ok here´s the thing. Im working on my degree´s final project with android studio. One of my duties is to create an Arraylist
whose max size has to be a number that the user introduces! i guess it looks simple but im stuck in some point, and i suspect is size value´s conversion between String
and Int
.
Specifically, im trying to take user´s number from and editText
, convert to String getText().toString()
then i use this to convert to int Integer.parseInt()
but when i run it in device, app crashes instantly. I´ve tryed already with valueOf
too, also changing int
for Integer
(im sorry, i dont rlly know the difference, i studied this all by my own from 0) and still get the instant close. Ive searched a lot here but i couldnt see a solution for something so specifically, so if someone could help me a bit, i would really appreciate that. Here is my code! hope it helps!
package com.example.listwithrecyclerview;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
Integer num;
String Snum;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
EditText ET1 = findViewById(R.id.editText);
Snum = ET1.getText().toString();
num = Integer.parseInt(Snum);
//also if i replace Snum by a number like:"23" in this last line, it works, so i guess it could
//be the way i put that variable inside the parseInt().
}
public void SendList (View view){
Intent A = new Intent(this, List.class);
A.putExtra("size", num);
startActivity(A);
}
}
Also if you know of a good library that can make stadistics math operations like typical deviations, arithmetic means, etc... Would be perfect for my final project.
Thank you so much !