开发者

I'm using JSP with NetBeans and I'm getting the following error

开发者 https://www.devze.com 2023-02-10 13:29 出处:网络
Note: C:\\Users\\Greg\\Documents\\NetBeansProjects\\abalon3\\build\\generated\\src\\org\\apache\\jsp\\user2_jsp.java uses unchecked or unsafe operations.

Note:

C:\Users\Greg\Documents\NetBeansProjects\abalon3\build\generated\src\org\apache\jsp\user2_jsp.java uses unchecked or unsafe operations.
Note: Recompile w开发者_开发百科ith -Xlint:unchecked for details.

Code:

<%
  String like=" ";
  Vector<String> vcd = new Vector<String>();
  Vector<String> vbo = new Vector<String>();
  vcd=CheckUser.search_latest_cd();
  int jc=vcd.size();
  vbo=CheckUser.search_latest_books();
  int jb=vbo.size();
  int i=0;

%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>

<table border="1" cellspacing="10"
bgcolor=#99FFFF>
<tr>
<th>Author</th>
<th>Title</th>
<th>Summary</th>
<th>Genre</th>
<th>year</th>
<th>Price</th>
<th>ID</th>
</tr>
<%if(vbo.size()>0){for( i=jb;i<jb;i-=7){%>
<tr><td><%out.print(vbo.get(i-6));%></td><td><%out.print(vbo.get(i-5));%></td>
<td><%out.print(vbo.get(i-4));%></td><td><%out.print(vbo.get(i-3));%></td>
<td><%out.print(vbo.get(i-2));%></td><td><%out.print(vbo.get(i-1));%></td>
<td><%out.print(vbo.get(i));}}%></td></tr>
</table>

can anyone tell me where's the problem?


Try doing what the message says:

Recompile with -Xlint:unchecked for details.


Do vcd=CheckUser.search_latest_cd(); and vbo=CheckUser.search_latest_books(); return Vector<String>?

The cause for unchecked or unsafe operations is generally that the compiler cannot check the generictype. Read here for more detials.

Also, Java Vector is deprecated in the later version of JVM. You should consider using List and ArrayList

Another note, you do not need to create an object which never be used. Here is your code:

Vector<String> vcd = new Vector<String>();
vcd=CheckUser.search_latest_cd();

You can set the object directly to vcd:

Vector<String> vcd = CheckUser.search_latest_cd();

or

Vector<String> vcd = null;
vcd=CheckUser.search_latest_cd();

Creating new Vector object which is never be used is a waste of time.


And last but not least, what you're seeing is not an error but a warning from the compiler (though some compilers can be set up to handle warnings as errors, this isn't the default behavior of the Sun Java compiler).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号