views:

35

answers:

1

hello guys,

before asking question let me tell you about my class hierarchy. i have a Main class with has onCreate() method. in that method i have made the MapFile class' object.and called its readFile() and readIndex() methods. in readIndex() method i call another class named MapTile where i read the images tiles from my binary file and there i have to display my image.

now question is how can i display image without putting my code into onCreate(Bundle savedInstanceStare) method.i am trying this way but on first line it gives me null pointer exception.

ImageView image = (ImageView) findViewById(android.R.id.icon);           
Bitmap bMap = BitmapFactory.decodeByteArray(imageTile, 0, imageTile.length);
image.setImageBitmap(bMap);

thanks in Advance.

A: 

I think your issue is not the byteArray but the findViewById. As you say that the NPE is on the first line. There are rules around this method you have to options to call it :

Either you use it to query a View you have already in the layout you call in setContentView
Or you use it on a View contained in a layout you inflated manually with a layout inflater

If you try to use it in your activity to call a View from any other layout than the one in setContentView that you have not inflated yourself, it will return you null.

Sephy
can you please give me some example....i could not understand.
sajjoo
remove the line ImageView image = (ImageView) findViewById(android.R.id.icon); and replace it by ImageView image = new ImageView(this); and after setting the imageBitmap, add the ImageView to your layout
Sephy
ohh thanks alot sephy
sajjoo