Syntax error on token(s) “product1. ”VariableDeclaratorId expected after this token

风格不统一 提交于 2019-12-02 20:15:25

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!