Error in simple array… How to fix [duplicate]

落爺英雄遲暮 提交于 2020-01-07 09:23:03

问题


This gives me an error of:

Cannot define dimension expressions when an array initializer is provided.

How to fix it?

static String names[] = new String[8]{
 "Global Mining Technologies",
 "Advanced Mine Group",
 "Hi-Tech Mining Industrial",
 "Victory Mining Co.",
 "Miners of Land Inc.",
 "Space-Age Mining Industries",
 "EasyMine Co.",
 "C.R.A.F.T Mining"};

回答1:


It's exactly as the error mentions. Either you specify dimensions and don't initialize inline, or you don't specify dimension and are allowed to initialize elements.

Use this idiom instead:

static String names[] = {
 "Global Mining Technologies",
 "Advanced Mine Group",
 "Hi-Tech Mining Industrial",
 "Victory Mining Co.",
 "Miners of Land Inc.",
 "Space-Age Mining Industries",
 "EasyMine Co.",
 "C.R.A.F.T Mining"};


来源:https://stackoverflow.com/questions/33503396/error-in-simple-array-how-to-fix

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