"testvector.java": Error #: 303 : 'this' cannot be referenced from a static context
) package testvector;
import java.util.Vector;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class testvector {
public testvector() {
}
public static void main(String[] args) {
testvector testvector1 = new testvector();
int i = 0;
Vector userList = new Vector(10,5);
for(i=0; i<17; i++)
{
String username = "user"+i;
String password = "password"+i;
User user = new User (username, password); //错误定位在这里,
//可这里实在是没有错啊???
userList.add(user);
}
System.out.println("number of users"+userList.size());
for(i=0; i<17; i++)
System.out.println("user name at "+i+":"+((User)userList.elementAt(i)).getName());
//此处的向下强制类型转换要注意
}
class User
{
String username;
String password;
public User(String name, String passwd)
{
username = name;
password = passwd;
}
public String getName()
{
return username;
}
}
}