|
蓝森林 http://www.lslnet.com 2006年6月6日 10:18
!!请教各位一个有关使用向量引起的安全问题!!
当我在程序中使用下面这条语句(屏蔽掉这条语句时则完全正常)
temp.addElement(String.valueOf(number));
时出现相关的出错提示信息。
Note: G:\JAVA\SelectPanel.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
请问使用向量时要注意些什么。 |
!!请教各位一个有关使用向量引起的安全问题!!
看看这里
http://forum.java.sun.com/thread.jspa?threadID=645542&tstart=135
用jdk 1.5吗?换用ArrayList试试,我猜的 |
!!请教各位一个有关使用向量引起的安全问题!!
多谢了,我用的JDK版本是1.5的,请问是这个的原因吗? |
!!请教各位一个有关使用向量引起的安全问题!!
这只是friendly warning,如果要求不高可以忽略,要彻底解决这样的问题,要用Generic方法定义
Vector<String>; temp = new Vector<String>;(); |
!!请教各位一个有关使用向量引起的安全问题!!
哦,在此多谢了!!我是个新手,不懂。你叫我改用ArrayList代替Vector,但效果一样会出现那个安全异常问题。 |
!!请教各位一个有关使用向量引起的安全问题!!
| !!请教各位一个有关使用向量引起的安全问题!!
Vector<String>; AllData = new Vector<String>;();
try
{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
sqlcon=DriverManager.getConnection("jdbc:odbc:minm","","");
sql=sqlcon.createStatement();
rs=sql.executeQuery(str_sql);
AllDataNum=0;
while(rs.next())
{
Vector<String>; temp = new Vector<String>;();
temp.addElement(String.valueOf(number));
for(int m=1;m<10;m++)
{temp.addElement(rs.getString(m));}
AllData.addElement(temp); //问题出在这里,好像不能向向量中插入数据
number++;
AllDataNum++;
}
rs.close();
sql.close();
sqlcon.close();
}
catch(ClassNotFoundException e1)
{System.out.println("错误e1(SelectInfo类内的drawData方法中(第一个连接处)) ");}
catch(SQLException e2){System.out.println("错误e2 (SelectInfo类内的drawData方法中(第二个连接处)) ");}
出现错误了:G:\JAVA\selectText.java:227: addElement(java.lang.String) in java.util.Vector<java.lang.String>; cannot be applied to (java.util.Vector<java.lang.String>;)
AllData.addElement(temp);
请问是什么原因啊!!多谢先!! |
!!请教各位一个有关使用向量引起的安全问题!!
AllData应该这样声明吧
Vector<Vector>; AllData = new Vector<Vector>;();
<>;里面是根据vector里存放的类型设置的 |
!!请教各位一个有关使用向量引起的安全问题!!
多谢!!理解这语句的用法了,真的很感谢!! |
| |