Sunday, 21 August 2011

Why do we need non-static inner class in java


Non static inner classes can reach to its enclosing class elements because they are dynamic elements of their enclosing classes. You can do that.

class A {
     public void method(){}
     public class B {
     method(); // cannot do this if you define B as 'public static class B'
     }
}

And in this case (non-static inner class). If you d like to create an instance of you inner class (B) in some other class, you should instantiate it like below.

class C {
     public C(){
     A.B b = new A().new B(); // B has the same characteristic like other non-static class elements
     }
}

On the other hand if you aren't going to reach to the enclosing class elements from the inner class, you can define your inner class as static class. In this case you don't need to create an instance of enclosing class to create an instance of the inner class.


class C {
     public C(){
     A.B b = new A.B(); // this is a valid instantiation of a B's instance.
     }
}

Wednesday, 3 August 2011

textview cannot be resolved to a type

There is that weird stuff in android. I have list_item.xml which is below

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/text1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center_vertical"
android:paddingLeft="6dip"
android:minHeight="?android:attr/listPreferredItemHeight"
></TextView>

and ArrayAdapter(view:View,textviewId:Int,items:String[]) wants a textview into 2nd parameter I was passing R.id.text1 as parameter but I needed to pass the layout (R.layout.list_item) instead of that textview. So why do you retrun 'textview cannot be resolved to a type' error to me? An example to confusing exceptions.

Saturday, 28 May 2011

Add custom repository to maven and add a library (dependency) from this repository

If you add a dependency to your project's pom.xml file, everytime when you try to build your project maven tries to connect to maven's default libraries (http://repo1.maven.com ...) and returns with a error message which says it could not find source in maven default repositories. So: lets see how can you add your custom repositories to maven and dependencies to your projects.

Scenario: there is that myLib-200.jar with a groupId which is 'aliolcicode' under the http://repo.aliolci.com

1. You have to add that custom repository to your maven settings to inform maven that 'I use my custom repositories next to maven repositories'. To do this. open your maven settings file (click here to see how) and add these lines below, between 'mirrors' tags
in XML above the important part is the url part the others are definition of your custom repository.
<mirror>
<id>aliolci</id>
<name>aliolci code repository</name>
<url>http://repo.aliolci.com</url>
<mirrorof>*</mirrorof>
</mirror>
2. Add your dependency to your project. There is nothing special about this. Just add your dependency as usual into your projects pom.xml.
<dependencies>
<dependency>
<groupid>aliolcicode</groupid>
<artifactid>myLib</artifactid>
<version>200</version>
</dependency>
</dependencies>
That's it. Enjoy!

Saturday, 21 May 2011

Intellij IDEA is freezing during Maven project (pom.xml file) reimporting

There is a stupid bug for the maven projects at the intellij which is a conflict of pom.xml and and Intellij project files (.iml, .ipr, .iws). To solve this conflict, just delete these all IntelliJ project files. Then open and reimport project just over the pom.xml. IntelliJ will create all project files from the begining.

Thursday, 5 May 2011

Maven settings.xml location at Ubuntu and Windows Systems

settings.xml file is used for configuring maven builder about profiles, repositories etc. At windows systems this file can be found at;

{Maven Installed Location}\conf\settings.xml
such as: C:\Program Files (x86)\Apache Software Foundation\apache-maven-3.0.3\conf

At Ubuntu systems it can be found under

/etc/maven2/settings.xml

Sunday, 1 May 2011

Ubuntu 11.04 set a new environment variable (persistently)

Custom environment variables are stored in /etc/environment file.

sudo gedit /etc/environment

If you open this file you will see the PATH variable's value. If you would like to set a new one just move to new line and set your variable in {variable_name}="{variable_value}" format. Such as JAVA_HOME="/usr/lib/jvm/java-6-sun/bin"

DONT FORGET TO OPEN FILE AS SUPER USER and restart your computer after you saved the changes.

To see the list of environment variables:
bash$ export

Wednesday, 16 February 2011

Android Activity life cycle

An important schema to understand the Android activity events


Details can be seen at the android developer website: http://developer.android.com/reference/android/app/Activity.html