Android Java 需要静态标识符或类型

Android Java static identifier or type expected

我得到了以下代码行:

for (int i = 0; i < articles.length(); i++) {
  static {
    addItem(new JsonParserItem("1", R.drawable.p1, "asd", "Steve Jobs", "Focusing is about saying No."));
  }
}

静态后我得到一个红色标记(错误)告诉我

identifier or type expected

我该如何解决这个问题

为什么那里有一个静态块? 那应该在 class 下,而不是在 for 循环内。

删除它,你的语法错误就会消失:

   for (int i = 0; i < articles.length(); i++) {
       addItem(new JsonParserItem("1", R.drawable.p1, "asd", "Steve Jobs", "Focusing is about saying No."));
   }

静态不应该在方法内部。有关如何在 Java 中使用 Static 的更多信息,请参阅以下问题:What does the 'static' keyword do in a class?