#when reading the file it just writes without splitting e into 2 columns

51 messages · Page 1 of 1 (latest)

mental elbow
#

try {
BufferedReader bufferedReader = new BufferedReader(new FileReader("urunIslemleri.txt"));
String line;
ObservableList<tablo> data2 = FXCollections.observableArrayList();

while ((line = bufferedReader.readLine()) != null) {
String[] values = line.split(",");
tablo teblo=new tablo(line, line, 0, 0);
data2.add(teblo);
}
        urunTablosu.getItems().addAll(data2);

        bufferedReader.close();
    } catch (IOException ex) {
        ex.printStackTrace();
    }
uncut tundraBOT
#

This post has been reserved for your question.

Hey @mental elbow! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

mental elbow
#

public class tablo {
private String urunIsmi;
private String kategori;
private int fiyat;
private int BayiID;
Constructor, getter and setter, toString()

mental elbow
#

halp

#

@slender hinge ❤️ helpp

slender hinge
#

whats the error?

#

also please put your code into code blocks

mental elbow
#

when reading the file it just writes without splitting e into 2 columns

mental elbow
slender hinge
mental elbow
slender hinge
#

` use this

mental elbow
#
    BufferedReader bufferedReader = new BufferedReader(new FileReader("urunIslemleri.txt"));
    String line;
    ObservableList<tablo> data2 = FXCollections.observableArrayList();

    while ((line = bufferedReader.readLine()) != null) {
    String[] values = line.split(",");
    tablo teblo=new tablo(line, line, 0, 0);
    data2.add(teblo);
    }
            urunTablosu.getItems().addAll(data2);

            bufferedReader.close();
        } catch (IOException ex) {
            ex.printStackTrace();
        } ````
slender hinge
#
try {
  BufferedReader bufferedReader = new BufferedReader(new FileReader("urunIslemleri.txt"));
  String line;
  ObservableList<tablo> data2 = FXCollections.observableArrayList();

  while ((line = bufferedReader.readLine()) != null) {
    String[] values = line.split(",");
    tablo teblo = new tablo(line, line, 0, 0);
    data2.add(teblo);
  }

  urunTablosu.getItems().addAll(data2);
  bufferedReader.close();
} catch (IOException ex) {
  ex.printStackTrace();
} 
#

what is the tablo class?

#

and why do you use an observablelist?

#

and what is urunTablosu

mental elbow
#
public class tablo {
    private String urunIsmi;
    private String kategori;
    private int fiyat;
    private int BayiID;

    @Override
    public String toString(){
        return urunIsmi+"/"+kategori+"/"+fiyat+"/"+BayiID;
    }
    public tablo(String urunIsmi, String kategori, int fiyat, int BayiID) {
        this.urunIsmi = urunIsmi;
        this.kategori = kategori;
        this.fiyat = fiyat;
        this.BayiID = BayiID;
    }

    public String getUrunIsmi() {
        return urunIsmi;
    }

    public void setUrunIsmi(String urunIsmi) {
        this.urunIsmi = urunIsmi;
    }

    public String getKategori() {
        return kategori;
    }

    public void setKategori(String kategori) {
        this.kategori = kategori;
    }

    public int getFiyat() {
        return fiyat;
    }

    public void setFiyat(int fiyat) {
        this.fiyat = fiyat;
    }

    public int getBayiID() {
        return BayiID;
    }

    public void setBayiID(int BayiID) {
        this.BayiID = BayiID;
    }
    

    
}```
mental elbow
slender hinge
#

its a field

#

what type does it have

mental elbow
#

I want to transfer the data in .txt to the table

slender hinge
#

you do urunTablosu.getItems()

#

what is the urunTablosu field

mental elbow
#

private TableView<tablo> urunTablosu;

slender hinge
#

does data2 have to be an ObservableList?

mental elbow
#

it could be something different

slender hinge
#

alright i found the issue

#
String[] values = line.split(",");
tablo teblo = new tablo(line, line, 0, 0);
#

you never use values

#

you just put the line into the table twice

#

you need to do value[0], value[1] etc

mental elbow
#
    tablo teblo=new tablo(values[1],values[2],values[3],values[4]);```
#

doesn't work

mental elbow
slender hinge
#

because for the 2 integers, you need to use Integer.parseInt(whatever)

#

and array indexs start at 0, not 1

mental elbow
#

like ```
tablo teblo=new tablo(values[1],values[2], Integer.parseInt(values[3]), Integer.parseInt(values[4]));

#

Caused by: java.lang.ArrayIndexOutOfBoundsException: Index 4 out of bounds for length 4

#

error 😦

slender hinge
#

again

#

array indexing starts at zero, not one

#

so you would start the first value using values[0] not values[1]

mental elbow
#

ohh

#

you are my super hero

#

❤️

#

I am thankful to you

#

I've been fighting this for 3 hours

slender hinge
#

no worries, always happy to help