我在使用 Android/IOs 应用程序时遇到问题:库代码 (libgdx?) 会引发 NPE,但不支持在 RoboVM 中进行调试。在 Android 中运行时,它按预期工作并达到handleHttpResponse()
方法。在 IO 中运行时,它会到达 failed(Throwable t) 方法,其中 t 为 a 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>