Hello everyone, I have such a complexity, it should save in arrayList , but it does not save due to the type mismatch, or what ... Please tell me what could be the matter?

  button1.addActionListener(new ActionListener() {@Override public void actionPerformed(ActionEvent e) { Model model = new Model(); model.setTovarList(textField1.getText()); // Ошибка try { dbHalper.writeModel(model); // добавили пользователя в базу данных } catch (Exception e1) public class Model { ArrayList < Saless > salessArrayList = new ArrayList < Saless > (); public ArrayList < Saless > getSalessArrayList() { return salessArrayList; } public void setSalessArrayList(ArrayList < Saless > salessArrayList) { this.salessArrayList = salessArrayList; } ArrayList < Tovar > tovarList = new ArrayList < Tovar > (); {} public ArrayList < Tovar > getTovarList() { return tovarList; } public void setTovarList(ArrayList < Tovar > tovarList) { this.tovarList = tovarList; } ArrayList < Saler > salerArrayList = new ArrayList < Saler > (); public ArrayList < Saler > getSalerArrayList() { return salerArrayList; } public void setSalerArrayList(ArrayList < Saler > salerArrayList) { this.salerArrayList = salerArrayList; } public Model() {} public Model(ArrayList < Saless > salessArrayList, ArrayList < Tovar > tovarList, ArrayList < Saler > salerArrayList) { this.salessArrayList = salessArrayList; this.tovarList = tovarList; this.salerArrayList = salerArrayList; } } public class Tovar { int price; public int getPrice() { return price; } public void setPrice(int price) { this.price = price; } public Tovar() {} public Tovar(int price) { this.price = price; } public void priceTovar() { price = price + 100; } } 

Information: 05/09/2015 9:20 - Compilation completed with 1 error and 0 warnings in 25 sec

Error: (32, 54) java: incompatible types: java.lang.String cannot be converted to java.util.ArrayList

C: \ Users \ Andrey \ IdeaProjects \ TSSDB \ src \ Form2.java

Information: java: Errors occurred while compiling module 'TSSDB'

Information: java: Some messages have been simplified; recompile with -

Xdiags: verbose to get full output

Information: Using javac 1.8.0_40 to compile java sources

  • Without error logs, we can not help you. - Yuriy SPb
  • @Timofey Bondarev I started learning recently, I have a superficial understanding of the "logs", here's an error that gives, thanks Error: (32, 54) java: incompatible types: java.lang.String cannot be converted to java.util.ArrayList <Tovar> - Andrey Gritsenko
  • You can add error information to the question. Ideally, the Model class code should be given - Timofei Bondarev
  • Added a class Model, Product, and error information ... I think the type mismatch, but I don’t understand how to bring it into the necessary type .. - Andrey Gritsenko

1 answer 1

 Error:(32, 54) java: incompatible types: java.lang.String cannot be converted to java.util.ArrayList 

This means that your String cannot convert to an ArrayList . And this is quite correct, because you have a string in the textField , and the model in the setTovarList method you should have ArrayList<Tovar> as a parameter. If you want to add a product to the model , then you must first create a Tovar object, then put it in ArrayList<Tovar> , and then write to the model