+ 1

Android studio question: cannot resolve "nextLine() method.

I am trying to use a java program I wrote in android studio. The program ran in java but android studio doesn't recognize the nextLine () method in the for loop to parse my input into 3 ints. Any tips would be appreciated. import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; import java.util.Scanner; import java.util.ArrayList; import java.util.List; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button addBtn = (Button) findViewById(R.id.addBtn); addBtn.setOnClickListener (new View.OnClickListener() { @Override public void onClick(View v) { EditText rawinput = (EditText) findViewById(R.id.rawinput); TextView result = (TextView) findViewById(R.id.result); List<Integer> arraynumbers = new ArrayList<>(); // creates an ArrayList called arraynumbers made of integers for(String num: rawinput.nextLine().split("-")) {// for loop to take the numbers between "-" in rawinput arraynumbers.add(Integer.parseInt(num)); // and add them to the ArrayList "arraynumbers" as Integers } // converts pair # to ccpt if(arraynumbers.size() == 1) { // if there is only one int in arraynumbers then do this stuff int a = (arraynumbers.get(0)); // user input of arraynumbers assigned to variable "a" int px = (a % 150); // uses "a" +math to return pair number in bank & assign to variable "px" double sx = (px - .5) / 6; // uses "px" +math to return slot # in double format &

24th Sep 2017, 3:27 AM
87yj
87yj - avatar
3 Antworten
+ 3
You're treating a EditText like it is a Stream that returns a String. Instead use getText() which returns an Editable object that you can then get the string value from. rawinput.getText().toString().split("-") https://developer.android.com/reference/android/widget/EditText.html https://developer.android.com/reference/android/text/Editable.html
24th Sep 2017, 3:34 AM
ChaoticDawg
ChaoticDawg - avatar
+ 1
Thank you very much. That is what I was not seeing. I'm learning a lot trying to convert the program over to android studio, instead of just running it from my command line on the code playground. The links you gave showed exactly what I was missing. The program runs now and shows up on the phone!!!
24th Sep 2017, 4:08 AM
87yj
87yj - avatar
0
I appoligize for the long comment lines. It looks great on the wide screen :)
24th Sep 2017, 3:28 AM
87yj
87yj - avatar