令牌" product1上的语法错误. "此令牌后应有VarialableDeclaratorId [英] Syntax error on token(s) "product1. "VariableDeclaratorId expected after this token

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

问题描述

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

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

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

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