Emre Can AYDIN
Newbie
Hello everyone i try to get items from txt file using array list and i want to split this array list to strings and show them in system.I have succeeded get items from txt file to an array list,but when i try to split the array list and try to show them in a loop my application gets error.
here is my txt file:
here is my code:
here is my output:
here is my txt file:
Code:
Ileri,1,1
Sol,1,1
Sag,1,1
Geri,1,1
here is my code:
Code:
start_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
///data/data/com.example.emrecan.myapplication/files/komutlar.txt
String yon;
String saniye1;
String tekrar;
int i=0,j=0;
ArrayList<String> listS=new ArrayList<String>();
try {
Scanner s=new Scanner(new File("/data/data/com.example.emrecan.myapplication/files/komutlar.txt"));
while(s.hasNextLine())
{
listS.add(s.nextLine());
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
System.out.println(listS);
//The program is working properly here.Problems start after this line.
String array=listS.toString();
String [] row=array.split(",");
while(i<(row.length-2))
{
yon=row[i];
saniye1=row[i+1];
tekrar=row[i+2];
int diziboyutu=row.length;
int tekrar1;
long sure1;
sure1=Long.parseLong(saniye1);
tekrar1=Integer.parseInt(tekrar);
sure1=sure1*1000;
System.out.println(yon);
System.out.println(saniye1);
System.out.println(tekrar);
System.out.println(sure1);
System.out.println(tekrar1);
System.out.println(diziboyutu);
i=i+3;
}
}
});
here is my output:
Code:
I/System.out: [Ileri,1,1, Sol,1,1, Sag,1,1, Geri,1,1]
[Ileri
I/System.out: 1
1
1000
1
12
Sol
1
1
1000
1
12
Sag
1
1
1000
1
12
//the program does not stop until here.
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.emrecan.myapplication, PID: 24123
java.lang.NumberFormatException: For input string: "1]" //i think this the problem but i can't find solution.
at java.lang.Integer.parseInt(Integer.java:521)
at java.lang.Integer.parseInt(Integer.java:556)
at com.example.emrecan.myapplication.MainActivity$7.onClick(MainActivity.java:322)
at android.view.View.performClick(View.java:5610)
at android.view.View$PerformClick.run(View.java:22265)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
Application terminated.