Question

I am working on an andngine game in which i am trying to show profile pic of level winner using facebok graph api i am using following code

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();
}

initially this code was working fine but from past two day's i am getting Null Pointer Exception when winner image is fetched from facebook ,my log is as following

03-31 19:22:27.325: E/AndroidRuntime(18531): FATAL EXCEPTION: GLThread 1359 03-31 19:22:27.325: E/AndroidRuntime(18531): org.andengine.util.exception.NullBitmapException: Caused by: '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): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1516) 03-31 19:22:27.325: E/AndroidRuntime(18531): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)

Hoping for quick reply from someone ,Thanks..

Was it helpful?

Solution

Auto redirection works automatically when original and redirected protocols are same.

So, try to load images from https instead of http : "https://graph.facebook.com/USER_ID/picture"; since actual image's url is "https://fbcdn-profile-a.akamaihd.net/...."

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top