Tuesday, November 27, 2012

No enclosing instance of type First is accessible.

Error :  "No enclosing instance of type First is accessible. Must qualify the allocation with an enclosing instance of type First "

Solution: You cannot instantiate a non-static inner class from a static context like main.

Sunday, November 25, 2012

ListView with Objects

Let's say you have just parsed some JSON data and you want to display them to a ListView.
For Simplicity sake I will assign all the properties of each item to only one TextView so we won't need to create a custom ArrayAdapter.

Assume that's our JSON data :

[  {"id":"1","title":"Homeland"},{"id":"2","title":"Breaking Bad"}{"id":"3","title":"Dexter"},{"id":"4","title":"Californication"}  ]

There's a JSON Array and that's everything in between [, ] and there are four  JSON Objects all of them with id and title properties.

First of all we are gonna create a class for our Objects :

public class TvShow() {
int id;
String title;
     public TvShow( int id, String title) {
        this.id = id;
    this.title = title;
     public int getID() {
    return id;
        public String getTitle() {
    return title;
    public String toString(){
String toReturn = "ID = "+id + " Title= " +title ;
    return  toReturn;
Note that we need to Override the toString method for the Object TvShow so that every TextView in the list will display strings.

Initialize an ArrayList of  <TvShow> Obejcts :

     ArrayList<TvShow> alist = new ArrayList<TvShow>();

 So finally we store our data to a JSONArray object :

   JSONArray jArray = new JSONArray(result); //result is the String response we got from our web service

and get the length of the array. int len = jArray.length();

All we need to do now is a for statement to run the array for each item.

   for (int i = 0; i < len; i++) {
JSONObject jObj = jArray.getJSONObject(i);
            int _id = jObj.getInt("id");
String _title = jObj.getString("title");
                            JSONData jData = new JSONData(_id, _title);
   } catch (Exception e) {
// TODO: handle exception
return alist;

Now we have our ArrayList alist with TvShow Object's data.

            ArrayList<TvShow> results = GetResults(); //assuming the GetResults returns the alist from above

In our XML file we create a ListView and grab its id to the ListView item :

        ListView lv= (ListView)findViewById(R.id.list );

Next we need to define our Adapter :
            ArrayAdapter<TvShow> arrayAdapter = new ArrayAdapter<TvShow>(this, android.R.layout.simple_list_item_1 , results );
The constructor is : 

public ArrayAdapter (Context context, int textViewResourceId, T[] objects)

The last thing we need to do is to assign the adapter to the ListView :

Now our ListView assings to an Object for every TextView item in the list.

Wednesday, October 17, 2012

Duplicate Lines Eclipse shorcut

Ubuntu 12.04 has a problem with Ctrl + Alt + Down arrow key  since this compination  it is used to change Workspaces.

You can just disable it from compiz so you can still change workspaces with right/left arrow and also can use it in Eclipse to duplicate lines.

The procedure is :

System->Preferences-> ConpizConfigSettingsManager
Click "Advanced Search"
Type "down" in the filter box.
Click on "Desktop wall"
Disable "Move Down".

Thursday, September 20, 2012

200, Stream not found, NetStream.Play.StreamNotFound, clip: '[Clip]

Most probable you have "ad block" add-on. Some videos have ads before they start and this add-on blocks them.
Try to disable it.

Thank you

Tuesday, May 15, 2012

Unable to instantiate activity in android

Most times this error has to do with the Manifest.xml file.

My advice is first to check  the Main Activity name if is the same with the Activity you use in your code:
<activity android:name=".MainActivity" />

And then check if your package got the same name as you named it when you create the Project.
You can find "package" property inside :
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="" >

It's a common mistake if you import your project code from another project or you change the main activity name.

Tuesday, May 8, 2012

Add project to working set - eclipse

right click on the working set you want and then click on Properties.

Select the project and Add it to the Working set content.

Thursday, May 3, 2012

Remove Title Bar on Android

Remember when you wrote the first "Hello World" app ?

Hello World or whatever you named it appears in the title bar of Android.

Go to the manifest file. Find the <application> tag and change it to this :


we have added the code in bold... it does the work for us. Now just run again your app.

Sunday, March 25, 2012

java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation

Well that's a common error if u are messing around with google maps api.

go to Project > Properties > Java Build Path > Libraries and ensure that there is no android.jar or maps.jar directly included. You should only have Google Apis with at leastmaps.jar and android.jar as leaves.

As u can see in the image there are two maps.jar . You have to delete the first one and just leave the leaves of Google APIs

java.io.IOException: Unable to open sync connection

Mess a lot with the code and now the error i get is :

java.io.IOException: Unable to open sync connection!

as u can check @ stackoverflow the answer is to enable/disable the usb-debugging

Some other tips that may can help u is to reboot your device, unplug it from the PC and plug it again.

Tuesday, March 20, 2012

E/MapActivity(2964): Couldn't get connection factory client

It has something to do with Android Google Maps.

I guess its not the API KEY, since im not having any problems and my app works just fine.

Seems it still is a bug no matter what SDK version you use.

Also from Stackoverflow is provided a workaround check the link here