我正在开发一个andngine游戏,其中我试图使用facebok graph api显示级别获胜者的个人资料照片我正在使用以下代码
try {
Texture itexture= new BitmapTexture(engine.getTextureManager(), new IInputStreamOpener() {
@Override
public InputStream open() throws IOException {
// TODO Auto-generated method stub
URL url = new URL("http://graph.facebook.com/"+userId+"/picture?type=square");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
BufferedInputStream in = new BufferedInputStream(input);
return in;
}
});
itexture.load();
TextureRegion MyImageFromWeb=TextureRegionFactory.extractFromTexture(itexture);
Sprite img=new Sprite(550, 400,MyImageFromWeb, vbom);
attachChild(img);
attachChild(new Text(550, 450, resourcesManager.font, name, vbom));
} catch (IOException e) {
Debug.e(e);
} catch (FacebookError e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
最初这段代码工作正常,但是从过去两天开始,当我从facebook获取获胜者图片时,我得到Null Pointer Exception,我的日志如下:
03-31 19:22:27.325:E / AndroidRuntime(18531):致命异常:GLThread 1359 03-31 19:22:27.325:E / AndroidRuntime(18531):org.andengine.util.exception.NullBitmapException:引起:'org.andengine.opengl.texture.bitmap.BitmapTexture@413e72a8'。 03-31 19:22:27.325:E / AndroidRuntime(18531):at org.andengine.opengl.texture.bitmap.BitmapTexture.writeTextureToHardware(BitmapTexture.java:107) 03-31 19:22:27.325:E / AndroidRuntime(18531):at org.andengine.opengl.texture.Texture.loadToHardware(Texture.java:145) 03-31 19:22:27.325:E / AndroidRuntime(18531):at org.andengine.opengl.texture.TextureManager.updateTextures(TextureManager.java:268) 03-31 19:22:27.325:E / AndroidRuntime(18531):at org.andengine.engine.Engine.onDrawFrame(Engine.java:633) 03-31 19:22:27.325:E / AndroidRuntime(18531):at org.andengine.opengl.view.EngineRenderer.onDrawFrame(EngineRenderer.java:105) 03-31 19:22:27.325:E / AndroidRuntime(18531):在android.opengl.GLSurfaceView $ GLThread.guardedRun(GLSurfaceView.java:1516) 03-31 19:22:27.325:E / AndroidRuntime(18531):在android.opengl.GLSurfaceView $ GLThread.run(GLSurfaceView.java:1240)
希望得到某人的快速回复,谢谢..
答案 0 :(得分:1)
当原始协议和重定向协议相同时,自动重定向会自动生效。
因此,请尝试从 https 而非 http 加载图片:" https://graph.facebook.com/USER_ID/picture&#34 ;;因为实际图片的网址是" https://fbcdn-profile-a.akamaihd.net/ ...."