import java.util.Vector;
public class PlayersList {
Vector a;
PlayersList()
{
}
void add()
{
a.addElement("玉石");
a.addElement("云母");
a.addElement("金矿");
a.addElement("白金");
}
void insert()
{
a.insertElementAt("钻石",0);
a.insertElementAt("翡翠",5);
}
void display()
{
int count=0;
while(count
System.out.print(a.elementAt(count));
count++;
if(count
System.out.print(",");
}
}
System.out.print(a.size());
}
void searech()
{
String bbb="玛瑙";
if(a.contains(bbb))
{
System.out.print("在索引"+a.indexOf(bbb)+"有"+bbb);
}
}
void remove()
{
a.removeElement("玉石");
int count=0;
while(count
System.out.print(a.elementAt(count));
System.out.print(",");
}
}
public static void main(String[] args)
{
PlayersList p=new PlayersList();
p.add();
p.display();
p.insert();
p.display();
p.searech();
p.remove();
}
}
错误:~~~~~~~~~~~~~~~~~~~~~~
Exception in thread "main" java.lang.NullPointerException
at stsnow333.PlayersList.add(PlayersList.java:12)
at stsnow333.PlayersList.main(PlayersList.java:59)