Alex Oxilg Alex Oxilg - 3 months ago 20
Android Question

Android Java static identifier or type expected

I got following lines of code:

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


After static I get a red marker (error) which tells me


identifier or type expected


how can I solve this

Answer

Why do you have a static block in there? That's supposed to be under a class, not inside a for loop.

Remove that and your syntax error should disappear:

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