你好,我有一个函数,它在 (.) 和字符串中的“Vl”之后取数字,所以我想在代码上调用这个函数,但他们告诉我这个错误
non-static method Ajuster(String) cannot be referenced from a static context
这是代码
public class Test {
public Integer Ajuster(String data) {
Integer vlan=0;
if (data.indexOf("Vl") >= 0) {
int pos = data.indexOf("Vl") + 2;
String vl = data.substring(pos, data.length());
vlan=Integer.parseInt(vl.trim());
} else {
int pos = data.lastIndexOf(".") + 1;
String vl = data.substring(pos, data.length());
try {
vlan=Integer.parseInt(vl.trim());
} catch (Exception e) {
e.printStackTrace();
}
}
return vlan;
}
public static void main(String[] args) {
Connection conn = null;
try {
conn = DriverManager.getConnection("jdbc:mysql://localhost/mohammedia", "root", "123456");
String sql = "SELECT * FROM router;";
Telnet_Interface telnet = new Telnet_Interface();
Telnet_Ressources telnet_R = new Telnet_Ressources();
Telnet_Interface telnet1 = new Telnet_Interface();
Telnet_Interface telnet2 = new Telnet_Interface();
PreparedStatement prest = conn.prepareStatement(sql);
ResultSet res=prest.executeQuery();
while(res.next()){
telnet1.Config(res.getString(1), "noc", "nocwana", res.getString(1));
telnet2.Config(res.getString(2), "noc", "nocwana", res.getString(2));
}
ArrayList myData=telnet.getMyData();
ArrayList myData1=telnet1.getMyData();
ArrayList myData2=telnet2.getMyData();
for(int i=0;i<myData1.size();i++)
{
String data1=myData1.get(i).toString();
Integer vl1=Ajuster(data1);
System.out.print(vl1);
}
}
}
所以问题在于这条线: Integer vl1=Ajuster(data1); 谢谢