令牌上的语法错误“product1."VariableDeclaratorId 预期在此令牌之后 [英] Syntax error on token(s) "product1. "VariableDeclaratorId expected after this token

查看:27
本文介绍了令牌上的语法错误“product1."VariableDeclaratorId 预期在此令牌之后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

真诚的

推荐答案

声明

productList.add(product1); 

应该在代码块中,例如方法、构造函数或实例初始值设定项而不是类块

should be in a code block such as a method, constructor or instance initializer rather than the class block

这篇关于令牌上的语法错误“product1.&quot;VariableDeclaratorId 预期在此令牌之后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆