[Java for Android App Development] jzaeyhfcbio:
Hi everybody,

I'm new to android coding, so I'm just making same small tests with the API.

Right now I have a problem using setPixels, it makes my app crash when I use it.

Here is the beginning of the onCreate :

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.activity_fullscreen);

ImageView image = (ImageView) findViewById(R.id.sly);

Bitmap bMap = BitmapFactory.decodeResource(getResources(), R.drawable.pic793849);
final int bMapWidth = bMap.getWidth();
final int bMapHeight = bMap.getHeight();

int[] pixels = new int[bMapHeight*bMapWidth];
bMap.getPixels(pixels, 0, bMapWidth, 0, 0, bMapWidth, bMapHeight);

for(int i=0 ; i<bMapHeight; i++)
{
for(int j=0 ; j<bMapWidth; j++)
{
//pixels[ i + (j*bMapHeight)] ^= 77;
}

}

bMap.setPixels(pixels, 0, bMapWidth, 0, 0, bMapWidth, bMapHeight);

//	image.setImageBitmap(bMap);

final View controlsView = findViewById(R.id.fullscreen_content_controls);
final View contentView = findViewById(R.id.fullscreen_content);

If I comment the setPixels line, the app runs fine, if I uncomment it, it crashed right away.

I don't get what I'm doing wrong, the bMap is allocated, the pixels too, I'm not out of bounds... any help would be appreciated !

here is the logCat :

06-12 10:25:19.770: W/ActivityThread(1074): Application com.example.moos is waiting for the debugger on port 8100...

06-12 10:25:19.810: I/System.out(1074): Sending WAIT chunk

06-12 10:25:20.280: I/dalvikvm(1074): Debugger is active

06-12 10:25:20.470: I/System.out(1074): Debugger has connected

06-12 10:25:20.480: I/System.out(1074): waiting for debugger to settle...

06-12 10:25:20.690: I/System.out(1074): waiting for debugger to settle...

06-12 10:25:20.890: I/System.out(1074): waiting for debugger to settle...

06-12 10:25:21.090: I/System.out(1074): waiting for debugger to settle...

06-12 10:25:21.290: I/System.out(1074): waiting for debugger to settle...

06-12 10:25:21.500: I/System.out(1074): waiting for debugger to settle...

06-12 10:25:21.700: I/System.out(1074): waiting for debugger to settle...

06-12 10:25:21.900: I/System.out(1074): waiting for debugger to settle...

06-12 10:25:22.100: I/System.out(1074): debugger has settled (1363)

06-12 10:25:23.490: D/dalvikvm(1074): GC_FOR_ALLOC freed 37K, 4% free 3339K/3448K, paused 34ms, total 37ms

06-12 10:25:23.570: D/dalvikvm(1074): GC_FOR_ALLOC freed 36K, 4% free 3648K/3800K, paused 22ms, total 23ms

06-12 10:25:23.670: D/AndroidRuntime(1074): Shutting down VM

06-12 10:25:23.670: W/dalvikvm(1074): threadid=1: thread exiting with uncaught exception (group=0xb2aceba8)

06-12 10:25:23.760: E/AndroidRuntime(1074): FATAL EXCEPTION: main

06-12 10:25:23.760: E/AndroidRuntime(1074): Process: com.example.moos, PID: 1074

06-12 10:25:23.760: E/AndroidRuntime(1074): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.moos/com.example.moos.FullscreenActivity}: java.lang.IllegalStateException

06-12 10:25:23.760: E/AndroidRuntime(1074):	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)

06-12 10:25:23.760: E/AndroidRuntime(1074):	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)

06-12 10:25:23.760: E/AndroidRuntime(1074):	at android.app.ActivityThread.access$800(ActivityThread.java:135)

06-12 10:25:23.760: E/AndroidRuntime(1074):	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)

06-12 10:25:23.760: E/AndroidRuntime(1074):	at android.os.Handler.dispatchMessage(Handler.java:102)

06-12 10:25:23.760: E/AndroidRuntime(1074):	at android.os.Looper.loop(Looper.java:136)

06-12 10:25:23.760: E/AndroidRuntime(1074):	at android.app.ActivityThread.main(ActivityThread.java:5017)

06-12 10:25:23.760: E/AndroidRuntime(1074):	at java.lang.reflect.Method.invokeNative(Native Method)

06-12 10:25:23.760: E/AndroidRuntime(1074):	at java.lang.reflect.Method.invoke(Method.java:515)

06-12 10:25:23.760: E/AndroidRuntime(1074):	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)

06-12 10:25:23.760: E/AndroidRuntime(1074):	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)

06-12 10:25:23.760: E/AndroidRuntime(1074):	at dalvik.system.NativeStart.main(Native Method)

06-12 10:25:23.760: E/AndroidRuntime(1074): Caused by: java.lang.IllegalStateException

06-12 10:25:23.760: E/AndroidRuntime(1074):	at android.graphics.Bitmap.setPixels(Bitmap.java:1427)

06-12 10:25:23.760: E/AndroidRuntime(1074):	at com.example.moos.FullscreenActivity.onCreate(FullscreenActivity.java:114)

06-12 10:25:23.760: E/AndroidRuntime(1074):	at android.app.Activity.performCreate(Activity.java:5231)

06-12 10:25:23.760: E/AndroidRuntime(1074):	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)

06-12 10:25:23.760: E/AndroidRuntime(1074):	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)

06-12 10:25:23.760: E/AndroidRuntime(1074):	... 11 more

Thanks in avance...