标题:创建数组报错,求教!
只看楼主
hlhlf4
Rank: 1
等 级:新手上路
帖 子:7
专家分:2
注 册:2012-7-25
 问题点数:0 回复次数:1 
创建数组报错,求教!
自己跟着教材写了一段数组的代码,和书上的一模一样,可就是一直报错。
代码如下:

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


请问到底错在哪里?
搜索更多相关主题的帖子: 教材 
2012-10-12 02:05
hlhlf4
Rank: 1
等 级:新手上路
帖 子:7
专家分:2
注 册:2012-7-25
得分:0 
PS  我用的是mac上的eclipse
2012-10-12 18:49



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-382988-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.023256 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved