Java "message": "Syntax error on token \";\", { expected after this token"

sekif :
public class Produtos 
{
    String object1 = "GPU";
    String object2 = "Processador";
    String object3 = "SSD";
}

class GPUsNvidia 
{
    boolean setNvidiaGaming = false;
    boolean setNvidiaProcess = false;

    String [] placas = { "rtx", "tesla" }; //Token error here

    for (int i = 0; i < placas.length; i++) 
    {
        if (placas[i].equals("rtx")) 
        { 
            setNvidiaGaming = true; 
        }
        if (placas[i].equals("tesla")) 
        { 
            setNvidiaProcess= true; 
        }
    }

    if (setNvidiaGaming == true) 
    {
        final String [] subObject1 = { "2060", "2070", "2080" };
    }
}

Where is the error? I'm a novice in Java. The full error is

{
    "resource": "/C:/Users/User/Documents/java_lojavirtual/Produtos.java",
    "owner": "_generated_diagnostic_collection_name_#1",
    "code": "1610612967",
    "severity": 8,
    "message": "Syntax error on token \";\", { expected after this token",
    "source": "Java",
    "startLineNumber": 13,
    "startColumn": 42,
    "endLineNumber": 13,
    "endColumn": 43
}
Mureinik :

You can't just have blocks of code floating around inside classes. They need to be enclosed in a method, constructor or initializer.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=409882&siteId=1