首先我定义了一个类
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以上是报错内容
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以上是报错内容
解决方案 »
- java重写javascript的正则表达式类(原创分享)
- 在jtable中怎样实现类似excel的单元格的边框效果?
- 查询问题
- 求教一个简单的代码!
- jtable同一列如何加入不同的控件
- 下载了个Java3D API,安装到了JBuilderX\jdk下面去,但是运行自带的demo的时候,为什么确都是加载applet失败?
- ---如何从字符串中将某一特定的字符去掉(正则表达式)-----
- SOCKET的奇怪问题,回答者有分,急!
- 组件如何放到窗体中?(请勿见笑)
- socket, server在把client发来的数据原样发回client时丢了一个字节是怎么回事?
- 请 高手帮忙 急
- 关于ORACLE中数据库链接库的操作
(((TwoElem)context.elementAt(i)).apptime)++; //注意这里,报错
existstatus=true;
break;
}
String类型变量不能用"=="来比较.
context.elementAt(i)要强制转换类型:(TwoElem)context.elementAt(i)
2. ((context.elementAt(i)).apptime)++;
这个类型也要强制转换