我有这些变量:
private String name = "name";
private String password = "password";
private String authString = name + ":" + password;
private byte[] authEncBytes = Base64.encodeBase64(authString.getBytes());
private String authStringEnc = new String(authEncBytes);
在我的Java程序中,我有以下代码:
HttpURLConnection.setRequestProperty("Authorization", "Basic " + authStringEnc);
这给了我以下错误:
Cannot make a static reference to the non-static field authStringEnc
如果我然后将变量更改为静态,则会出现以下错误:
Cannot make a static reference to the non-static method setRequestProperty(String, String) from the type URLConnection
如何解决此问题?