gpt4 book ai didi

java - Linux 特定错误 IOException

转载 作者:太空宇宙 更新时间:2023-11-04 12:32:31 24 4
gpt4 key购买 nike

所以我正在制作一个 java 应用程序,它可以从特定的 Spotify 用户获取所有公共(public)播放列表,一切都很好,并且可以正常工作,直到我在基于 linux 的机器(raspbian java 版本 1.8)上运行我的项目时Windows 我得到了预期的输出但是当在 Linux 上运行时我得到了

来自 linux 的错误日志

java.io.IOException
at com.wrapper.spotify.SpotifyHttpManager.execute(SpotifyHttpManager.java:164)
at com.wrapper.spotify.SpotifyHttpManager.post(SpotifyHttpManager.java:81)
at com.wrapper.spotify.methods.AbstractRequest.postJson(AbstractRequest.java:38)
at com.wrapper.spotify.methods.authentication.ClientCredentialsGrantRequest.getAsync(ClientCredentialsGrantRequest.java:30)
at com.simon.spotify.Spotify.GetPublicPlayLists(Spotify.java:47)
at com.simon.Main$10.start(Main.java:375)
at com.simon.Main.getSpotifyPlayLists(Main.java:379)
at com.simon.keyevent.selectionHandler(keyevent.java:77)
at com.simon.keyevent.keyPressed(keyevent.java:52)
at java.awt.AWTEventMulticaster.keyPressed(AWTEventMulticaster.java:250)
at java.awt.Component.processKeyEvent(Component.java:6493)
at javax.swing.JComponent.processKeyEvent(JComponent.java:2832)
at java.awt.Component.processEvent(Component.java:6312)
at java.awt.Container.processEvent(Container.java:2236)
at java.awt.Component.dispatchEventImpl(Component.java:4891)
at java.awt.Container.dispatchEventImpl(Container.java:2294)
at java.awt.Component.dispatchEvent(Component.java:4713)
at java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1954)
at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(DefaultKeyboardFocusManager.java:806)
at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(DefaultKeyboardFocusManager.java:1074)
at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:945)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:771)
at java.awt.Component.dispatchEventImpl(Component.java:4762)
at java.awt.Container.dispatchEventImpl(Container.java:2294)
at java.awt.Window.dispatchEventImpl(Window.java:2750)
at java.awt.Component.dispatchEvent(Component.java:4713)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.awt.EventQueue$4.run(EventQueue.java:731)
at java.awt.EventQueue$4.run(EventQueue.java:729)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

这是包含 getSpotifyPlayLists 的类

public class Spotify {
public static String clientId = ""; // inser client public key
public static String clientSecret = ""; // insert client sercet key
public static String userid = "";// inser user name
public Spotify(String clientId,String clientSecret,String userid) {
this.clientId = clientId;
this.clientSecret = clientSecret;
this.userid = userid;
}

public static Api api;

public static void GetPublicPlayLists() {

System.out.println
(new Exception().getStackTrace()[0].getMethodName());
ArrayList<String> data = new ArrayList<>();


api = Api.builder()
.clientId(clientId)
.clientSecret(clientSecret)
.build();

/* Create a request object. */
final ClientCredentialsGrantRequest request = api.clientCredentialsGrant().build();

/* Use the request object to make the request, either asynchronously (getAsync) or synchronously (get) */
final SettableFuture<ClientCredentials> responseFuture = request.getAsync();

/* Add callbacks to handle success and failure */
Futures.addCallback(responseFuture, new FutureCallback<ClientCredentials>() {
@Override
public void onSuccess(ClientCredentials clientCredentials) {
/* The tokens were retrieved successfully! */
System.out.println("Successfully retrieved an access token! " + clientCredentials.getAccessToken());
System.out.println("The access token expires in " + clientCredentials.getExpiresIn() + " seconds");

/* Set access token on the Api object so that it's used going forward */
api.setAccessToken(clientCredentials.getAccessToken());

/* Please note that this flow does not return a refresh token.
* That's only for the Authorization code flow */

final UserPlaylistsRequest request = api.getPlaylistsForUser(userid).build();

try {
final Page<SimplePlaylist> playlistsPage = request.get();

for (SimplePlaylist playlist : playlistsPage.getItems()) {
System.out.println(playlist.getName() + " : "+ playlist.getId() + " : "+ playlist.getUri() + " : track count ="+ playlist.getTracks().getTotal());

/* item i = new item();
i.title = playlist.getName();
i.creator = playlist.getOwner().getId();
i.uri = playlist.getId();
data.add(i);
*/
}
} catch (Exception e) {
System.out.println("Something went wrong!" + e.getMessage());
}
}

@Override
public void onFailure(Throwable throwable) {
/* An error occurred while getting the access token. This is probably caused by the client id or
* client secret is invalid. */
System.out.println("Something went wrong! 2" );
throwable.printStackTrace();
throwable.printStackTrace(System.out);
}
});
return;
}

}

spotify.spotifyhttpManger.execute 类看起来像这样

  private String execute(HttpMethod method) throws WebApiException, IOException {
final HttpClient httpClient = new HttpClient(connectionManager);
try {
httpClient.executeMethod(method);

handleErrorStatusCode(method);
String responseBody = method.getResponseBodyAsString();

handleErrorResponseBody(responseBody);
return responseBody;

} catch (IOException e) {
throw new IOException();
} finally {
method.releaseConnection();
}
}

我不知道为什么会出现此错误或如何在 atm 上解决它?

最佳答案

所以我没能弄清楚问题出在哪里,但后来我重新安装了操作系统,它又能正常工作了

关于java - Linux 特定错误 IOException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42913659/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com