Installing GenyMotion on your ubuntu 14


Android App
– Added exception handling and error checking for request and response
– Updated the Drive->Requirements->Detailed Requirements, added Section 13 for future exception handling rules
– Installed GenyMotion Freemium, added all 4.x devices

We can test the app on the virtualbox, we dont need to invest on devices, I think 🙂

For installing GenyMotion

Install the Emulators 4.4 (only)
After you load the emulator you will Google Play is not installed, for that the following links are useful.
Works –
Does not work –

Fitting different sized images in GridView


There are 2 challenges here,
1) Fitting them so they look all made to fit
2) Using less memory as we do bitmap stuff

Bitmaps can bring challenges when you need to work with them across screens. Keeping the code neat and clear is also very important, for this you want to keep the layouts and fitting stuff in the xml, and the bitmap resizing, fitting, reading and memory handling in the code. Less code is good right ?

So I use a GridView and a layout to define the cell contents.

GridView will use attributes numColumns, gravity (once they fit, play with padding, margins, horizontalspacing and verticalspacing).

For the cell contents I use RelativeLayout (height = 0, weight = 1). ImageView within it uses scaleType=fitXY (play with the others once you have them all fitting) and layout_centerInParent.

In your getView of your GridAdapter, you need to set the width of your image at runtime. For this you need to get the screen width, and set the width of your image.

int w = getWindowManager().getDefaultDisplay().getWidth() ;
cellImage.setLayoutParams(new RelativeLayout.LayoutParams(
w/numOfColumnsInYourGridView, w/numOfColumnsInYourGridView));

This should do your fitting. Problem 1 solved.

Now reading the images will cause a lot of memory utilization (use DDMS Heap, to check it out), and a lot of GC. For this you should downsample your bitmaps as you read them.

private Bitmap getDownSampling(String resourceName) {
int maxSize = 125; // make 125 the upper limit on the bitmap size
Bitmap myBitmap ;
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inJustDecodeBounds = true; // Only get the bitmap size, not the
// bitmap itself
try {
getAssets().open("logos/" + resourceName), new Rect(10,
10, 10, 10), opts);
} catch (IOException e) {
int w = opts.outHeight, h = opts.outHeight;
int maxDim = (w > h) ? w : h; // Get the bigger dimension
int inSample = maxDim / maxSize;

opts = new BitmapFactory.Options();
opts.inSampleSize = inSample;

try {
myBitmap = BitmapFactory.decodeStream(
getAssets().open("logos/" + resourceName), new Rect(10,
10, 10, 10), opts);
} catch (IOException e) {
return null ;
return myBitmap;

This should use as little memory as needed.

org.hibernate.MappingException: Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister


Self Advertisement
—–Start of Advertisement——-
BUILD CAR POOL SOLUTIONS ON ANY DEVICE TO RUN ANYWHERE ( Introducing mCruiseOn, the java library /json api’s that you can use to build a car pool solution. Be the next,, mCruiseOn is your one stop API on EC2.
——End of Advertisement——-

I just enabled log4j, and stopped printing stacktrace on exceptions. So the errors I started to get were very cryptic. Printing stacktrace is important even after you have log4j consuming the exception object.
Once I uncommented e.printStackTrace(), I got more meaningful exception stacktraces which helped identify the root cause.
In my case
– Did not have the setMethod for a new primary key defined, in the class refered by the hbm file.
– Had java.util.Integer instead of java.lang.Integer
– for a variable acPreference I had getACPreference, instead I should have had getAcPreference

Include Log4j to my java project in eclipse


Well, like any programmer, I started with System.out.println’s for my logging and debugging needs. But only after I wrote myself a set of test cases. As you assumed right I ran out of thought process to organize my log’s very soon. As I was debugging stuff, I realized that my logs not only need to be categorized they need to be “intended”. When I “intended” I meant that sometime in future I want to be able to say something like “show me logs of all threading happening on my server”. So I know who is using my threads, when and is some client eating up my threadpool ? I also want to be able to drive down to the client level to figure out who exactly is eating it up.

The that is “important” for me, not urgent as yet. As any good time management advice will tell you, to focus on your urgent and important. So currently I need to be able to just organize my logs into the regular 4 levels, fatal, error, info and debug. So here goes. I choose Log4j for many reasons
– Tried and tested
– A lot of help on the net for log4j
– Best Practices are already identified, documented and followed (
* Logger Design
* Should be greppable
* Separate files for separate areas of interest
* Device/Connection/StreamManager threads
* Stream Management
* Request Issues
* Database Issues
* Memcached Issues
* TimeStamps with timezones from server and client and down to nanoseconds (yyyy-MM-dd/HH:mm:ss.SSS/zzz) Java does not support nanoseconds
* Identity (who tried to do what)
* Single Line (no multiple line’s. Except, exceptions
* When did user last login ?
* Error reported to user “must” be logged (exact Error)
* Every Class to have
* public static final Logger log = Logger.getLogger(MyClass.class) ;

I did encounter some trouble starting up. So this blog will help those who want to startup too. The the above advice, I also did the following
– In my main method I did
– Added under the same level as src directory on my eclipse project
– My contents are
log4j.rootLogger=DEBUG, CA
log4j.appender.CA.layout.ConversionPattern=%-4r [%t] %-5p %c %x – %m%n


#Attribute is one of the following:
#0 -> Reset All Attributes (return to normal mode)
#1 -> Bright (Usually turns on BOLD)
#2 -> Dim
#3 -> Underline
#5 -> link
#7 -> Reverse
#8 -> Hidden
#Foreground is one of the following:
#30 -> Black
#31 -> Red
#32 -> Green
#33 -> Yellow
#34 -> Blue
#35 -> Magenta
#36 -> Cyan
#37 -> White
#Background is one of the following:
#40 -> Black
#41 -> Red
#42 -> Green
#43 -> Yellow
#44 -> Blue
#45 -> Magenta
#46 -> Cyan
#47 -> White;31;35;36;32;34

I am still trying to get colors in my log, but that does not work. When I get it up and running, I’ll edit this post with more. If you have a solution on this, please comment.

WARN net.spy.memcached.transcoders.SerializingTranscoder: Caught IOException decoding bytes of data


I started to get a weird exception; no valid constructor

The stack trace was very weird, it hinted at a launch stack, and a exception from a table other than what I was sending data to. Infact after doing some debugging, step by step, this exception happened on a get on a SomeOther_Hibernate_Table.

Crazy root cause.. 🙂
Old code
List tableRow = null ;
if (isCacheable) {
tableRow value = cache.get(key) ;
return tableRow
String rowQuery = “Select * from ” + tableName + ” where ” + column + “=” + “\”” + key + “\””;
Query rowResult = currentSession().createSQLQuery(rowQuery);
tableRow = rowResult.list();

The cache returns a Object, but hibernate.createSQLQuery returns a List. So to keep things clean, the fix below.
Object value = cache.get(key) ;
if (isCacheable) {
if (value != null) {
tableRow = new ArrayList() ;
return tableRow;
String rowQuery = “Select * from ” + tableName + ” where ” + column + “=” + “\”” + key + “\””;
Query rowResult = currentSession().createSQLQuery(rowQuery);
tableRow = rowResult.list();

Hibernate Class cast expection when reading items from createSQLQuery().list


Got some good advice from
String tableQuery = “Select * from ” + tableName ;
Query tableResult = null;
List table = null;
tableResult = currentSession().createSQLQuery(tableQuery);
table = tableResult.list();

I modified the code to
String tableQuery = “Select {t.*} from ” + tableName + ” t”;
Query tableResult = null;
List table = null;
tableResult = currentSession().createSQLQuery(tableQuery).addEntity(“t”, tableClass);
table = tableResult.list();