Exception in thread “” java.lang.IllegalMonitorStateException

0

Simple fix, you seem to have missed putting your “notify” and “wait” in a synchronized (the relevant object) block. Now, you may ask what is the relevant object. If the wait is waiting to get information that will help this object (with is a thread) run, then you should synchronize on “this”. If you are waiting for a linked list to get some information, then you should synchronize on that linked list object.

Do it right!!

Runtime Exception Stub! using BitmapFactory and BitmapOptions testcase

0

Wasted a lot of time on this. Basically I was running the below as a junit test instead of a android junit test. I modified the test case to “extend AndroidTestCase”, added stuff into the manifest
in

in

And it worked. For reference I have added the exceptions and code.

Code Example 1

try {
inputStream = (InputStream)new URL(url).openStream() ;
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
inputStream = null ;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
inputStream = null ;
}

if (inputStream == null) throw new NullPointerException() ;
mapPiece = BitmapFactory.decodeStream(new FlushedInputStream(inputStream)) ;//, null, factoryOptions);

Throws

java.lang.RuntimeException: Stub!
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:33)

Code Example 2

try {
inputStream = (InputStream)new URL(url).openStream() ;
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
inputStream = null ;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
inputStream = null ;
}

if (inputStream == null) throw new NullPointerException() ;
BitmapFactory.Options factoryOptions = new BitmapFactory.Options();
factoryOptions.inPurgeable = true;
factoryOptions.inSampleSize = 2;
mapPiece = BitmapFactory.decodeStream(new FlushedInputStream(inputStream), null, factoryOptions);

Throws

java.lang.RuntimeException: Stub!
at android.graphics.BitmapFactory$Options.(BitmapFactory.java:6)

AndroidTestCase basics

0

A quick blog on its basics. Its a bit crazy to read the developer.android.com site for this. So, you create a AndroidTestCase when you want to test a android application from test cases. So you have a screen with some data, buttons. Your test case will fill in the data, and press the buttons. Infact you can also call methods of your classes.

Now you ask, where will the test case get the application context for that app. Simple, when you set up a project with a class that extends AndroidTestCase, you also need to put in the following to your manifest. The test case launches and loads your applications and you can get a reference to your app context from super.getContext(). Cool ?? I think so..