创建数组报错,求教!
自己跟着教材写了一段数组的代码,和书上的一模一样,可就是一直报错。代码如下:
程序代码:
import java.util.ArrayList; public class ArrayListTest { public static void main(String[] args) { NSMutableArray * anArray=[[NSMutableArray alloc] init]; [anArray addObject:@"Monday"]; [anArray addObject:@"Tuesday"]; [anArray addObject:@"Wednesday"]; [anArray addObject:@"Thursday"]; [anArray addObject:@"Friday"]; [anArray addObject:@"Saturday"]; [anArray addObject:@"Sunday"]; [anArray sortUsingSelector: @selector(caseInsensitiveCompare)]; int count; count = anArray.count; for (int y=0; y<count; y++){ NSLog(@"Day is %@", [anArray objectAtIndex: y]); } //Release the array [anArray release]; } }
报错如下:
程序代码:
Exception in thread "main" java.lang.Error: Unresolved compilation problems: Syntax error on token "*", invalid AssignmentOperator Syntax error on token "[", invalid Expression Syntax error on token(s), misplaced construct(s) Syntax error on token "]", [ expected after this token Syntax error on token "[", delete this token Syntax error on token(s), misplaced construct(s) Syntax error on tokens, Statement expected instead Syntax error on tokens, delete these tokens Syntax error on token(s), misplaced construct(s) Syntax error on token "@", delete this token Syntax error on token "anArray", ? expected after this token Syntax error on token ")", ++ expected Syntax error on token "[", delete this token Syntax error on token "]", delete this token at ArrayListTest.main(ArrayListTest.java:21)
请问到底错在哪里?