Powered By:
Android Advice
 

Solution to java.io.FileNotFoundException when performing an Oauth Request

Problem
When doing an Oauth request the following error is thrown “java.io.FileNotFoundException”

Cause
The request is not signed.

Solution
Sign the request first, before actually performing the request. You can either do this manually following the OAuth guidelines or use a simple 3rd signing library recommended by Oauth e.g. Signpost (https://code.google.com/p/oauth-signpost/)

Posted in Java Problem-Cause-Solution Programming by stevenmarkford. No Comments

Enums for Older Java Versions

Enums only became available in J2SE 5.0

If one wants to achieve enum type behavior in Java prior to version 5.0 then one would have to use a type-safe enum pattern. Which would go something like this:

Step 1 – Create the Base Enum Class

public abstract class Enum
{
	private final String name;
	private final int ordinal;

    protected Enum(String name, int ordinal)
	{
	    this.name = name;
	    this.ordinal = ordinal;
	}

	public String toString()
	{
	    return this.name;
	}

	public int getOrdinal()
	{
	    return this.ordinal;
	}
        
        // add other enum helper functions here
}

Step 2 – Extend the Enum Base Class for All Custom Enums

public class MyEnum extends Enum
{
	public static final SortType Fixed = new SortType("SomeThing", 0);
	public static final SortType Alphabetical = new SortType("SomeOtherThing", 1);

    protected MyEnum(String name, int ordinal)
	{
		super(name, ordinal);
	}
}
Posted in Programming by stevenmarkford. No Comments

Android – How to get a File into Memory

To get a file in the Android file system into memory is really easy. Example:

import android.os.Environment;
import java.io.File;

File theFirstOne = Environment.getExternalStorageDirectory().listFiles()[0];

if(theFirstOne.isDirectory())
{
 //this is a directory
}
else
{
//this is a file
}
Posted in Android Programming by stevenmarkford. No Comments