当前位置: 代码迷 >> Java相关 >> 创建数组报错,求教!
  详细解决方案

创建数组报错,求教!

热度:244   发布时间:2012-10-12 02:05:01.0
创建数组报错,求教!
自己跟着教材写了一段数组的代码,和书上的一模一样,可就是一直报错。
代码如下:

程序代码:
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)


请问到底错在哪里?
搜索更多相关的解决方案: 教材  

----------------解决方案--------------------------------------------------------
PS  我用的是mac上的eclipse
----------------解决方案--------------------------------------------------------
  相关解决方案