首先我定义了一个类
class TwoElem{
String name;
int apptime; TwoElem(){} TwoElem(String name, int apptime){
this.name=name;
this.apptime=apptime;
}
}我定义的第二个类中想要包含一个Vector,Vector 中的每一项都是一个TwoElem实例
class Context{
Vector context=new Vector();
Context(){} void insert(String name){
if(context.size()==0) context.addElement(new TwoElem(name,1));
else{
boolean existstatus=false;
for(int i=0;i<context.size();i++){
if(name==(context.elementAt(i)).name){ //注意这里报错
((context.elementAt(i)).apptime)++; //注意这里,报错
existstatus=true;
break;
}
}
if(!existstatus){
context.addElement(new TwoElem(name,1));
}
}
}
}
我不知道为什么,java中定义了这些类似的嵌套类以后,怎么对嵌套类的实例进行修改和调用阿阿???
在我的程序中我想简单的用(context.elementAt(i)).name <其中context是一个包含了TwoElem的Vector> 实现对Vector中一个项的成员变量的修改。有什么地方不对吗??
最开始我是用iterator来做的,但是发现iterator根本就不能对它遍历的项进行修改。请高手指教,该如何实现,如果用iterator实现,又该如何做??
class TwoElem{
String name;
int apptime; TwoElem(){} TwoElem(String name, int apptime){
this.name=name;
this.apptime=apptime;
}
}我定义的第二个类中想要包含一个Vector,Vector 中的每一项都是一个TwoElem实例
class Context{
Vector context=new Vector();
Context(){} void insert(String name){
if(context.size()==0) context.addElement(new TwoElem(name,1));
else{
boolean existstatus=false;
for(int i=0;i<context.size();i++){
if(name==(context.elementAt(i)).name){ //注意这里报错
((context.elementAt(i)).apptime)++; //注意这里,报错
existstatus=true;
break;
}
}
if(!existstatus){
context.addElement(new TwoElem(name,1));
}
}
}
}
我不知道为什么,java中定义了这些类似的嵌套类以后,怎么对嵌套类的实例进行修改和调用阿阿???
在我的程序中我想简单的用(context.elementAt(i)).name <其中context是一个包含了TwoElem的Vector> 实现对Vector中一个项的成员变量的修改。有什么地方不对吗??
最开始我是用iterator来做的,但是发现iterator根本就不能对它遍历的项进行修改。请高手指教,该如何实现,如果用iterator实现,又该如何做??
FPTree.java:59: cannot find symbol
symbol : variable name
location: class java.lang.Object
if(name==(context.elementAt(i)).name){
^
FPTree.java:60: cannot find symbol
symbol : variable apptime
location: class java.lang.Object
((context.elementAt(i)).apptime)++;
^
FPTree.java:60: illegal start of type
((context.elementAt(i)).apptime)++;
^
Note: FPTree.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
3 errors以上是报错内容