我正在尝试使用userNameLabel.getText()
和passwordLabel.getText()
这个不起作用,只能获得NullPointerException
:
// setting authentication
String userpass = **userNameLabel.getText()** + ":" + **passwordLabel.getText()**;
String basicAuth = "Basic " + javax.xml.bind.DatatypeConverter.printBase64Binary(userpass.getBytes());
con.setRequestProperty("Authorization", basicAuth);
这个工作正常,没有任何变量只是硬编码用户名和pw:
// setting authentication
String userpass = **"myusername"** + ":" + **"mypassword"**;
String basicAuth = "Basic " + javax.xml.bind.DatatypeConverter.printBase64Binary(userpass.getBytes());
con.setRequestProperty("Authorization", basicAuth);
我也用Strings测试过:
String u = userNameLabel.getText(); and just edited the lines above.
为什么这不起作用的任何想法?
BR 安德烈亚斯