问题
I met this type of error when creating a new class. Below was my code:
package com.example.opener.test;
import java.util.ArrayList;
import Product.Product;
public class ProductMgrStubs {
/* Attribute */
byte[] image1 = new byte[]{6,7,5,6,5};
Product product1 = new Product("Product 1", image1, "Product 1", 0);
ArrayList<Product> productList = new ArrayList<Product>();
productList.add(product1); /* The error message popped out from here */
}
Could anyone help me figure out what actually happened and some suggestions to fix this? I really appreciate your help
Sincerely
回答1:
The statement
productList.add(product1);
should be in a code block such as a method, constructor or instance initializer rather than the class block
来源:https://stackoverflow.com/questions/26824236/syntax-error-on-tokens-product1-variabledeclaratorid-expected-after-this-to