Thursday, June 25, 2015

Java: Unsupported major.minor version 51.0

When you get an error:

Unsupported major.minor version X

This means that you are trying to compile your Java program with version lower that the code is written for; for example you develop with Java 1.7, deploy on the server where they have Java 1.6:

Unsupported major.minor version 51.0

The fix is:

  • to change your code to use lower Java, which is sometimes impossible because of 3rd party library that you are using
  • upgrade the other computer to modern Java, which is sometimes impossible because of a brick-head gatekeeper
  • vent on the blog and start cutting out the code 

Java versions:
  • J2SE 8 = 52
  • J2SE 7 = 51 
  • J2SE 6.0 = 50 
  • J2SE 5.0 = 49 
  • JDK 1.4 = 48 
  • JDK 1.3 = 47 
  • JDK 1.2 = 46 
  • JDK 1.1 = 45

Monday, June 22, 2015

RoboGuice - Android development made simple and fun

"Simple and Fun!" Now, they make quite a promise!

read up:

Maven repo:


OK, so most of all RoboGuice is about DEPENDENCY INJECTION


TextView label;

@InjectResource(R.string.app_name) // strings, drawables
String applicationName;

@Inject // system service
LayoutInflater layoutInflater;

LocationManager locationManager;

@Inject // POJO
Book book;

Creating Activities

public class FightForcesOfEvilActivity extends RoboActivity {

TextView expletiveText;

Creating Android Modules

public class MyModule extends AbstractModule {
protected void configure() { }


public static class AsyncPunch extends RoboAsyncTask {

// Astroboy is a @Singleton public class Astroboy {
@Inject Astroboy astroboy;

// new instance of java.util.Random, since we haven't specified any binding instructions
@Inject Random random;

SHH key

$ git clone
Cloning into 'roboguice'...

Permission denied (publickey).

$ ls -al ~/.ssh
total 120
-rw-------   1 uki  staff   1675 Oct 31  2012 id_rsa


$ pbcopy < ~/.ssh/ 

PASTE your SSH key exactly as copied (i.e. in GitHub settings)

$ git clone roboguice
Cloning into 'roboguice'...
remote: Counting objects: 18463, done.

Receiving objects:  15%

Tuesday, June 16, 2015

MacBook Pro (late 2011) graphics crashing

With the update to Yosemite (maybe unrelated) my Mac started to crash, at first it was rare, but right now it is consistent, the common situations when it is crashing:

  • connecting external monitor via HDMI
  • connecting external monitor via VGA
  • screen sharing using JoinMe 
  • bad days in general
The MacBook Pro (starting with early 2011) have 2 GPU (graphic cards), one integrated, low power, and one additional (discrete) that is used for high power situations.

I installed the utility called gfxCardStatus that allows me to switch between integrated and discrete graphic cards.

From their website:

gfxCardStatus v2.3 and above actively prevents you from switching to Integrated Only mode when any apps are in the Dependencies list (or if you have an external display plugged in). This is because if you were to do this, your discrete GPU would actually stay powered on, even though you've switched to the integrated GPU.

So I guess no more external display for me until Apple fixes the problem, or I but new MacBook Pro (hopefully with touch screen this time).

Reseting System Management Controller (SMC)

Thursday, June 11, 2015

Java: Closable

When working with multiple resources that need to be closed after we are done using, I particularly like the approach of using Closable Interface:

try {
    // open input streams and use them  
catch (IOException e) {
finally {

private void attemptClose(Closeable object) {
    if (object != null) {
        try {
        catch (IOException ignore) {

Apple Photos opening every time phone USB is connected

I work developing Android so I plug and unplug different devices all day long. Apple Mac Photos app is opening every time phone USB is connected, which is frustrating and sometimes out of place at work.

To turn off that behavior next time the Photos app opens UNSELECT THIS CHECKBOX:

"Open Photos for this device"

Android: TextView in ScrollView continous scrolling

Sometimes when continuously outputting text to TextView, you would like it to scroll down:

textView.addTextChangedListener(new TextWatcher() {
    @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) {

    @Override public void onTextChanged(CharSequence s, int start, int before, int count) {
        // scroll down whenever log text updated to display latest info on the screen        
        Runnable() {
            @Override public void run() {

    @Override public void afterTextChanged(Editable s) {

Monday, June 8, 2015

Android: AsyncTask delegate

Let say we have an Activity that wants to receive a messages from AsyncTask.

We create an Interface AsyncResponse

public interface AsyncResponse {
   void publishLog(String logContent);

We create our AsyncTask:

public class FileReaderTask 
 extends AsyncTask < Void, Void, List < AbstractX > > {
// delegate should be set in the Activity   
public AsyncResponse delegate = null;
String xyz = "";

// ...

@Overrideprotected void onPreExecute() {

@Overrideprotected void onPostExecute(List x) {

Now we can tie together the AsyncTask and Activity:

public class FileReaderActivity extends Activity implements AsyncResponse {

   private static final String TAG = FileReaderActivity.class.getCanonicalName();
   FileReaderTask asyncTask = new FileReaderTask();

   private TextView logText;

   /**    * Called when the activity is first created.    */  

 @Override   public void onCreate(Bundle savedInstanceState) {
      logText = (TextView) findViewById(;

      // tell Async Task that this Activity will listen      

asyncTask.delegate = this;

   /**    * This method will receive log from Async Task.    * @param logContent    */   

@Override   public void publishLog(String logContent) {

Android: finding SD Card

Since the implementation of SD card is different on various devices use following method:

private static final String SDCARDFILE 
+ "/somefolder/somefile.ext";

git: updating all repos using Bash

I have a lot (hundreds) of repositories I want to keep updated on daily basis, here is a handy script I use:

# saving current working directory

echo "reading each repo directory in $cwd"
for repo in *
echo '#################################################'
# change to give repo directory
cd $repo
# print repo url
    git config --get remote.origin.url
    git fetch
    git status
    # go back to directory you started with
    cd $cwd