错误:不兼容的类型

时间:2017-11-02 20:09:27

标签: java arrays string incompatibletypeerror

public void init() {
    Container cp = getContentPane();
    cp.setLayout(null);
    cp.setBounds(0, 0, 769, 556);
    cp.setBackground(Color.ORANGE); 
    // Begin componenten

    String arrayWoord[]=new String[10];
    arrayWoord[0] = letterVeld1;
    arrayWoord[1] = letterVeld2;
    arrayWoord[2] = letterVeld3;
    arrayWoord[3] = letterVeld4;
    arrayWoord[4] = letterVeld5;
    arrayWoord[5] = letterVeld6;
    arrayWoord[6] = letterVeld7;
    arrayWoord[7] = letterVeld8;
    arrayWoord[8] = letterVeld9;
    arrayWoord[9] = letterVeld10;

Java多次出现以下错误:

Compileer C:\java\Javaeditor\Java\Project\GalgjeApplet\GalgjeApplet.java met 
Java-Compiler
GalgjeApplet.java:77:21: error: incompatible types
arrayWoord[0] = letterVeld1;    
                ^
  required: String    
  found:    JTextField    

1 个答案:

答案 0 :(得分:0)

JTextFieldString不是一回事。您可能希望从文本字段中获取值arrayWoord[0] = letterVeld1.getText()

此外,您应该将letterVeld存储在一个数组中,然后执行for (int i = 0; i < 10; i++) arrayWoord[i] = letterVelds[i].getText()