令牌上的语法错误“product1。”此令牌后面的VariableDeclaratorId

时间:2014-11-09 02:11:05

标签: java android variables arraylist declaration

创建新类时遇到了这种类型的错误。下面是我的代码:

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 */


   }

任何人都可以帮我弄清楚实际发生了什么以及一些解决这个问题的建议吗?我非常感谢你的帮助

此致

1 个答案:

答案 0 :(得分:2)

声明

productList.add(product1); 

应该在代码块中,例如方法,构造函数或实例初始化程序,而不是类块