gpt4 book ai didi

java - Gdx.net : NPE in libgdx code with RoboVM

转载 作者:行者123 更新时间:2023-11-28 18:32:47 25 4
gpt4 key购买 nike

我在使用 Android/IOs 应用程序时遇到问题:库代码(libgdx?)抛出 NPE,但不支持在 RoboVM 中进行调试。在 Android 中运行时,它按预期工作并到达 handleHttpResponse() 方法。在 IO 中运行时,它会到达 failed(Throwable t) 方法,其中 t 是 NullPointerException。我已经创建了一个示例应用程序来显示问题,也许这是我的错,所以这里是代码:

public class Npe extends ApplicationAdapter {
SpriteBatch batch;
Texture img;

@Override
public void create () {
batch = new SpriteBatch();
img = new Texture("badlogic.jpg");
loadHttps("https://www.google.it");
}

@Override
public void render () {
Gdx.gl.glClearColor(1, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
batch.draw(img, 0, 0);
batch.end();
}

private static void loadHttps(String url) {
HttpRequest httpGet = new HttpRequest(HttpMethods.GET);

httpGet.setUrl(url);

Gdx.net.sendHttpRequest(httpGet, new HttpResponseListener() {
@Override
public void handleHttpResponse(HttpResponse httpResponse) {
String res = httpResponse.getResultAsString();
System.err.println("res = \"" + res + "\"");
}

@Override
public void failed(Throwable t) {
System.err.println("On IOs we reach this point");
t.printStackTrace(); // and t is a NPE
}

@Override
public void cancelled()
{
}
});
}
}

和我的 robovm.xml:

<config>
<executableName>${app.executable}</executableName>
<mainClass>${app.mainclass}</mainClass>
<os>ios</os>
<arch>thumbv7</arch>
<target>ios</target>
<iosInfoPList>Info.plist.xml</iosInfoPList>
<resources>
<resource>
<directory>../android/assets</directory>
<includes>
<include>**</include>
</includes>
<skipPngCrush>true</skipPngCrush>
</resource>
<resource>
<directory>data</directory>
</resource>
</resources>
<forceLinkClasses>

<pattern>org.apache.harmony.xnet.provider.jsse.OpenSSLSocketFactoryImpl</pattern>

<pattern>com.android.org.conscrypt.JSSEProvider</pattern>
<pattern>com.android.org.conscrypt.OpenSSLProvider</pattern>
<pattern>com.android.org.conscrypt.OpenSSLSocketFactoryImpl</pattern>
<pattern>com.android.okhttp.HttpsHandler</pattern>

<pattern>com.badlogic.gdx.scenes.scene2d.ui.*</pattern>
<pattern>org.apache.harmony.xnet.provider.jsse.OpenSSLProvider</pattern>
<pattern>org.apache.harmony.security.provider.cert.DRLCertFactory</pattern>
<pattern>com.android.org.bouncycastle.jce.provider.BouncyCastleProvider</pattern>
<pattern>org.apache.harmony.security.provider.crypto.CryptoProvider</pattern>
<pattern>org.apache.harmony.xnet.provider.jsse.JSSEProvider</pattern>
<pattern>com.android.org.bouncycastle.jce.provider.JDKKeyStore</pattern>
<pattern>org.apache.harmony.security.provider.cert.X509CertFactoryImpl</pattern>
<pattern>com.android.org.bouncycastle.jce.provider.PKIXCertPathValidatorSpi</pattern>
<pattern>org.apache.harmony.xnet.provider.jsse.OpenSSLMessageDigestJDK$MD5</pattern>
</forceLinkClasses>
<libs>
<lib>build/libs/ios/libgdx-box2d.a</lib>
<lib>build/libs/ios/libgdx-bullet.a</lib>
<lib>build/libs/ios/libgdx-freetype.a</lib>
<lib>build/libs/ios/libgdx.a</lib>
<lib>build/libs/ios/libObjectAL.a</lib>
</libs>
<frameworks>
<framework>UIKit</framework>
<framework>OpenGLES</framework>
<framework>QuartzCore</framework>
<framework>CoreGraphics</framework>
<framework>OpenAL</framework>
<framework>AudioToolbox</framework>
<framework>AVFoundation</framework>
</frameworks>
</config>

最佳答案

假设您使用的是最新的 0.0.14 版本的 RoboVM,我相信您的问题是您没有强制链接正确的类以支持 HTTPS。请尝试更改您的<forceLinkClasses>部分看起来像这样:

<forceLinkClasses>
<pattern>com.badlogic.gdx.scenes.scene2d.ui.*</pattern>

<!-- For http: support in URLConnection -->
<pattern>com.android.okhttp.HttpHandler</pattern>

<!-- For https: support in URLConnection -->
<pattern>com.android.okhttp.HttpsHandler</pattern>
<!-- OpenSSL is preferred over BouncyCastle. This pulls in full OpenSSL support. -->
<pattern>com.android.org.conscrypt.**</pattern>
<!-- We still need KeyStore.BKS and CertPathValidator.PKIX from BouncyCastle -->
<pattern>com.android.org.bouncycastle.jce.provider.BouncyCastleProvider</pattern>
<pattern>com.android.org.bouncycastle.jcajce.provider.keystore.BC$Mappings</pattern>
<pattern>com.android.org.bouncycastle.jcajce.provider.keystore.bc.BcKeyStoreSpi</pattern>
<pattern>com.android.org.bouncycastle.jcajce.provider.keystore.bc.BcKeyStoreSpi$Std</pattern>
<pattern>com.android.org.bouncycastle.jce.provider.PKIXCertPathValidatorSpi</pattern>
<!-- Use AndroidDigestFactoryOpenSSL as AndroidDigestFactory implementation -->
<pattern>com.android.org.bouncycastle.crypto.digests.AndroidDigestFactoryOpenSSL</pattern>
</forceLinkClasses>

如果这不起作用,请尝试添加 <pattern>**</pattern>给你的<forceLinkClasses> .该模式将引入类路径中的所有内容。如果这能让您的应用正常工作,您至少知道它是在一个或多个缺失的类上导致了问题。

关于java - Gdx.net : NPE in libgdx code with RoboVM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24949749/

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