Sample Android application using Netbeans on UBUNTU
Step 1. Download Android SDK from
http://developer.android.com/sdk/1.1_r1/index.html
Unzip distribution.
Step 2. Setting Netbeans plugin for Android :
You can get details installing plugin for Android at
http://kenai.com/projects/nbandroid/pages/Install
Step 3.
Netbeans menu
Tools -- Java Platform
Click Add Platform button
Select Google Android Open Handheld platform.
Set Android SDK directory as Platform folder. (downloaded and unzipped in step 1)
Click next and set name as "Android".
Click finish.
Step 4. Create new Android Project
File -- Project --
Android -- Android Application
Set project Name as HelloAndroid for example.
click finish
Step 5.
Open Source packages
org.me.helloandroid.MainActivity.java file.
there is oncreate method as follows
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
// ToDo add your GUI initialization code here
}
Change it by adding few lines of code to display "Hello Android".
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
// ToDo add your GUI initialization code here
TextView tv = new TextView(this);
tv.setText("Hello, Android");
setContentView(tv);
}
Step 6.
Run Application.
You will get "Hello Android" text on Android Emulator screen.
If You get Following Exception while running application :
trouble processing:
invalid constant pool index 0000
...while parsing attributes[1]
...while parsing Code attribute at offset 0000013e
...while parsing attributes[0]
...while parsing methods[0]
...while parsing org/me/helloandroid/R$layout.class
...while processing org/me/helloandroid/R$layout.class
Check java -version on console and set it as java-6
Here are steps how to set this:
on console window type : sudo update-alternatives --config java
It will give installed versions and option to set java version.
If java 6 is not in list use following link to install and set as default version
https://help.ubuntu.com/community/Java
Tuesday, March 31, 2009
Wednesday, March 18, 2009
Sort Objects of ArrayList
We use ArrayList many times to store list of Objects.
How to Sort records of ArrayList of objects using Collections.sort method based on particular field.
Suppose we have Class Employee as :
public class Employee {
private String empName;
private String empDept;
private double salary;
public String getEmpDept() {
return empDept;
}
public void setEmpDept(String empDept) {
this.empDept = empDept;
}
public String getEmpName() {
return empName;
}
public void setEmpName(String empName) {
this.empName = empName;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
}
main method to demonstrate sorting of ArrayList which contains few Employees.
eg:
public static void main(String[] args) {
ArrayList empList = new ArrayList();
Employee e1 = new Employee();
e1.setEmpName("Abcd");
e1.setEmpDept("ACCT");
Employee e2 = new Employee();
e2.setEmpName("Ssss");
e2.setEmpDept("HRD");
Employee e3 = new Employee();
e3.setEmpName("rrrr");
e3.setEmpDept("MKTG");
Employee e4 = new Employee();
e4.setEmpName("bbbb");
e4.setEmpDept("ACCT");
Employee e5 = new Employee();
e5.setEmpName("mmmm");
e5.setEmpDept("DEVP");
empList.add(e1);
empList.add(e2);
empList.add(e3);
empList.add(e4);
empList.add(e5);
System.out.println("Before Sorting:");
for (Employee employee : empList) {
System.out.println("Employee :"+employee.getEmpName());
}
Collections.sort(empList, new Comparator(){
public int compare(Object obj1, Object obj2) {
Employee emp1 = (Employee) obj1;
Employee emp2 = (Employee) obj2;
return emp1.getEmpName().compareToIgnoreCase(emp2.getEmpName());
}
});
System.out.println("");
System.out.println("After Sorting:");
for (Employee employee : empList) {
System.out.println("Employee :"+employee.getEmpName());
}
}
Output is:
Before Sorting:
Employee :Abcd
Employee :Ssss
Employee :rrrr
Employee :bbbb
Employee :mmmm
After Sorting:
Employee :Abcd
Employee :bbbb
Employee :mmmm
Employee :rrrr
Employee :Ssss
How to Sort records of ArrayList of objects using Collections.sort method based on particular field.
Suppose we have Class Employee as :
public class Employee {
private String empName;
private String empDept;
private double salary;
public String getEmpDept() {
return empDept;
}
public void setEmpDept(String empDept) {
this.empDept = empDept;
}
public String getEmpName() {
return empName;
}
public void setEmpName(String empName) {
this.empName = empName;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
}
main method to demonstrate sorting of ArrayList which contains few Employees.
eg:
public static void main(String[] args) {
ArrayList
Employee e1 = new Employee();
e1.setEmpName("Abcd");
e1.setEmpDept("ACCT");
Employee e2 = new Employee();
e2.setEmpName("Ssss");
e2.setEmpDept("HRD");
Employee e3 = new Employee();
e3.setEmpName("rrrr");
e3.setEmpDept("MKTG");
Employee e4 = new Employee();
e4.setEmpName("bbbb");
e4.setEmpDept("ACCT");
Employee e5 = new Employee();
e5.setEmpName("mmmm");
e5.setEmpDept("DEVP");
empList.add(e1);
empList.add(e2);
empList.add(e3);
empList.add(e4);
empList.add(e5);
System.out.println("Before Sorting:");
for (Employee employee : empList) {
System.out.println("Employee :"+employee.getEmpName());
}
Collections.sort(empList, new Comparator(){
public int compare(Object obj1, Object obj2) {
Employee emp1 = (Employee) obj1;
Employee emp2 = (Employee) obj2;
return emp1.getEmpName().compareToIgnoreCase(emp2.getEmpName());
}
});
System.out.println("");
System.out.println("After Sorting:");
for (Employee employee : empList) {
System.out.println("Employee :"+employee.getEmpName());
}
}
Output is:
Before Sorting:
Employee :Abcd
Employee :Ssss
Employee :rrrr
Employee :bbbb
Employee :mmmm
After Sorting:
Employee :Abcd
Employee :bbbb
Employee :mmmm
Employee :rrrr
Employee :Ssss
Saturday, March 7, 2009
Happy Birthday Ketu
Wish you many happy returns of the day dear K2.
Miss you.
Always keep Smiling.
Miss you.
Always keep Smiling.
Subscribe to:
Posts (Atom)