org.xml.sax.SAXParseException: Content is not allowed in prolog

This is often caused by a white space before the XML declaration, but it could be any text, like a dash or any character. I say often caused by white space because people assume white space is always ignorable, but that’s not the case here. Another thing that often happens is a UTF-8 BOM (byte order mark), which is allowed … Read more

How to get the last value of an ArrayList

The following is part of the List interface (which ArrayList implements): E is the element type. If the list is empty, get throws an IndexOutOfBoundsException. You can find the whole API documentation here.

How to fix the Hibernate “object references an unsaved transient instance – save the transient instance before flushing” error

You should include cascade=”all” (if using xml) or cascade=CascadeType.ALL (if using annotations) on your collection mapping. This happens because you have a collection in your entity, and that collection has one or more items which are not present in the database. By specifying the above options you tell hibernate to save them to the database when saving their parent.

Float and double datatype in Java

The Wikipedia page on it is a good place to start. To sum up: float is represented in 32 bits, with 1 sign bit, 8 bits of exponent, and 23 bits of the significand (or what follows from a scientific-notation number: 2.33728*1012; 33728 is the significand). double is represented in 64 bits, with 1 sign bit, 11 bits of … Read more

Java “user.dir” property – what exactly does it mean?

It’s the directory where java was run from, where you started the JVM. Does not have to be within the user’s home directory. It can be anywhere where the user has permission to run java. So if you cd into /somedir, then run your program, user.dir will be /somedir. A different property, user.home, refers to the user directory. As in /Users/myuser or /home/myuser or C:\Users\myuser. See here for a list of … Read more

Display Animated GIF

Android actually can decode and display animated GIFs, using android.graphics.Movie class. This is not too much documented, but is in SDK Reference. Moreover, it is used in Samples in ApiDemos in BitmapDecode example with some animated flag.

Creating a maze solving algorithm in Java

You probably should module your program – as I can understand it, you are reading the maze from file and trying to solve it at the same time. A better approach will be to split the program into 2 distinct parts: read the input file and create a matrix with all the data solve the maze from … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)