Pages

Upgrading Eclipse 4.3 Kepler to 4.4 Luna

Eclipse 4.4 Luna repositories:
In case you’re using Eclipse for Android development, the ADT repo hasn’t changed:

'Unhandled event loop exception' java.lang.StackOverflowError

When I use Eclipse Kepler for Android development, add a new button and right click on a button to change the button's text by clicking on Edit Text...


Then click on New String... I got the following error: Unhandled event loop exception java.lang.StackOverflowError.


Same error doesn't happen with Eclipse Luna or Juno.

"Running Android Lint" has encountered a problem

When I start the Eclipse Juno for Android SDK, the following dialog  with 'Running Android Lint' has encountered a problem. Failed. java.lang.NullPointerException Error message occurred.


Workaround this problem: Window -> Preferences -> Android -> Lint Error Checking. Then uncheck the check box: When saving files, check for errors.

How to solve "Failed to load the JNI shared library..." error

First, ensure that your version of Eclipse and JDK match, either both 64-bit or both 32-bit (you can't mix-and-match 32-bit with 64-bit).

Second, the -vm argument in eclipse.ini should point to the java executable. See http://wiki.eclipse.org/Eclipse.ini for examples.

How to find your Android device's MAC address


To locate the MAC(Media Access Control) Address of your Android phone or Android tablet, follow these steps:

On the Home screen, tap the Menu key and go to Settings.

Scroll down and tap About Tablet then tap Status and then scroll down to view WiFi Mac address.

Observer pattern in Java

Just as object-oriented programming encourages code reuse, design patterns encourage design reuse. Indeed, design patterns allow you to reuse clean, time-tested designs. However, design patterns have come under an increasing amount of criticism lately. Critics point out that inexperienced developers can easily fall into the pattern trap.

The pattern trap blinds inexperienced developers. As such, instead of solving a solution in the best way possible, the end goal for novice developers centers on implementation of as many design patterns as possible. To some, using a design pattern seems to guarantee a good design. By that logic, if you use a lot of design patterns, you'll have a great design! Often times this belief leads to designs that just don't make sense -- even though the design might incorporate multiple patterns. Unfortunately, a design pattern does not guarantee good design.


In order to properly use a design pattern in your design, you must uphold three criteria:

  1. Understand your problem
  2. Understand the pattern
  3. Understand how the pattern solves your problem

You need to know criterion number 1 first and foremost. How can you apply a pattern if you do not fully know what problem you are trying to solve?


You also need to know the second criterion: You must fully understand the patterns you are interested in applying. How can you apply a pattern if you do not understand it? More importantly, how can you even consider a pattern if you do not understand what it does?


Finally, if you cannot articulate how the pattern will solve your problem (why it is appropriate), forget it. Don't fall into the pattern trap and simply use a pattern so you can say you used it.


I'm not saying that the reader is necessarily falling into this trap. However, by the wording of the question, many developers may get the wrong impression about patterns. From the question, I understand that the reader probably knows the problem and understands the Observer pattern. He or she simply needs to see the pattern implemented in Java.


Before giving a Java example, it may help other readers to first give a brief description of the Observer pattern.


Simply, the Observer pattern allows one object (the observer) to watch another (the subject). The Observer pattern allows the subject and observer to form a publish-subscribe relationship. Through the Observer pattern, observers can register to receive events from the subject. When the subject needs to inform its observers of an event, it simply sends the event to each observer.


For example, you might have a spreadsheet that has an underlying data model. Whenever the data model changes, the spreadsheet will need to update the spreadsheet screen and an embedded graph. In this example, the subject is the data model and the observers are the screen and graph. When the observers receive notification that the model has changes, they can update themselves.


The benefit: it decouples the observer from the subject. The subject doesn't need to know anything special about its observers. Instead, the subject simply allows observers to subscribe. When the subject generates an event, it simply passes it to each of its observers.


Consider the following Java example:

public interface Subject {
      public void addObserver( Observer o );
      public void removeObserver( Observer o );
}
In the code above, the Subject interface defines the methods that a Subject must implement in order for Observers to add and remove themselves from the Subject.
public interface Observer {      public void update( Subject o );}
The Observer interface (above) lists the methods that an Observer must implement so that a Subject can send an update notification to the Observer.

Let's consider a simple implementation of Subject -- an IntegerDataBag:
import java.util.ArrayList;
import java.util.Iterator;
public class IntegerDataBag implements Subject {
      private ArrayList list = new ArrayList();
      private ArrayList observers = new ArrayList();
      public void add( Integer i ) {
            list.add( i );
            notifyObservers();
      }
      public Iterator iterator() {
            return list.iterator();
      }
      public Integer remove( int index ) {
            if( index < list.size() ) {
                  Integer i = (Integer) list.remove( index );
                  notifyObservers();
                  return i;
            }
            return null;
      }
      public void addObserver( Observer o ) {
            observers.add( o );
      }
      public void removeObserver( Observer o ) {
            observers.remove( o );
      }
      private void notifyObservers() {
            // loop through and notify each observer
            Iterator i = observers.iterator();
            while( i.hasNext() ) {
                  Observer o = ( Observer ) i.next();
                  o.update( this );
            }
      }
}
 IntegerDataBag holds onto Integer instances. The IntegerDataBag also allows Observers to add and remove themselves.

Consider these two implementations of Observer -- IntegerAdder and IntegerPrinter:
import java.util.Iterator;
public class IntegerAdder implements Observer {
      private IntegerDataBag bag;
      public IntegerAdder( IntegerDataBag bag ) {
            this.bag = bag;              
            bag.addObserver( this );
      }
      public void update( Subject o ) {
            if( o == bag ) {
                  System.out.println( "The contents of the IntegerDataBag have changed." );
                  int counter = 0;
                  Iterator i = bag.iterator();
                  while( i.hasNext() ) {
                        Integer integer = ( Integer ) i.next();
                        counter+=integer.intValue();
                  }
                  System.out.println( "The new sum of the integers is: " + counter );
            }
      }
}
import java.util.Iterator;
public class IntegerPrinter implements Observer {
      private IntegerDataBag bag;
      public IntegerPrinter( IntegerDataBag bag ) {
            this.bag = bag;              
            bag.addObserver( this );
      }
      public void update( Subject o ) {
            if( o == bag ) {
                  System.out.println( "The contents of the IntegerDataBag have changed." );
                  System.out.println( "The new contents of the IntegerDataBag contains:" );
                  Iterator i = bag.iterator();
                  while( i.hasNext() ) {
                        System.out.println( i.next() );
                  }
            }
      }
}
IntegerAdder and IntegerPrinter add themselves to the integer bag as observers. When an IntegerAdder receives an update, it sums up the Integer values held in the bag and displays them. Likewise, when IntegerPrinter receives an update, it prints out the Integers held in the bag.

Here is a simple main() that exercises these classes:
public class Driver {
      public static void main( String [] args ) {
            Integer i1 = new Integer( 1 ); Integer i2 = new Integer( 2 );
            Integer i3 = new Integer( 3 ); Integer i4 = new Integer( 4 );
            Integer i5 = new Integer( 5 ); Integer i6 = new Integer( 6 );
            Integer i7 = new Integer( 7 ); Integer i8 = new Integer( 8 );
            Integer i9 = new Integer( 9 );
            IntegerDataBag bag = new IntegerDataBag();
            bag.add( i1 ); bag.add( i2 ); bag.add( i3 ); bag.add( i4 );
            bag.add( i5 ); bag.add( i6 ); bag.add( i7 ); bag.add( i8 );
            IntegerAdder adder = new IntegerAdder( bag );
            IntegerPrinter printer = new IntegerPrinter( bag );
            // adder and printer add themselves to the bag
            System.out.println( "About to add another integer to the bag:" );
            bag.add( i9 );
            System.out.println("");
            System.out.println("About to remove an integer from the bag:");
            bag.remove( 0 );
      }
}
 IntegerDataBag/IntegerAdder/IntegerPrinter is a simple example of the Observer pattern. Within Java itself there are a number of examples of the Observer pattern: the AWT/Swing event model, as well as the java.util.Observer and java.util.Observable interfaces serve as examples.

Greek Symbols

Α α
Β β
Γ γ
Δ δ
Ε ϵ ε
Ϝ ϝ
Ζ ζ
Η η
Θ θ ϑ
Ι ι
Κ κ ϰ
Λ λ
Μ μ
Ν ν
Ξ ξ
Ο ο
Π π ϖ
Ρ ρ ϱ
Σ σ ς
Τ τ
Υ υ
Φ ϕ φ
Χ χ
Ψ ψ
Ω ω

Roman number chart

I
1
XXIX
29
LXXIV
74
D = 500
II
2
XXX
30
LXXV
75
III
3
XXXI
31
LXXVI
76
M=1000
IV
4
XXXV
35
LXXVII
77
V
5
XXXVI
36
LXXVIII
78
VI
6
XXXVII
37
LXXIX
79
VII
7
XXXVIII
38
LXXX
80
VIII
8
XXXIX
39
LXXXI
81


IX
9
XL
40
LXXXII
82
EX.

X
10
XLI
41
LXXXIII
83
DI
501
XI
11
XLIX
49
LXXXIV
84
DL
550
XII
12
L
50
LXXXV
85
DXXX
530
XIII
13
LI
51
LXXXVI
86
DCCVII
707
XIV
14
LIX
59
LXXXVII
87
DCCCXC
890
XV
15
LX
60
LXXXVIII
88
MD
1500
XVI
16
LXI
61
LXXXIX
89
MDCCC
1800
XVII
17
LXII
62
XC
90
CM
900
XVIII
18
LXIII
63
XCI
91


XIX
19
LXIV
64
XCII
92


XX
20
LXV
65
XCIII
93


XXI
21
LXVI
66
XCIV
94


XXII
22
LXVII
67
XCV
95


XXIII
23
LXVIII
68
XCVI
96


XXIV
24
LXIX
69
XCVII
97


XXV
25
LXX
70
XCVIII
98


XXVI
26
LXXI
71
XCIX
99


XXVII
27
LXXII
72
C
100


XXVIII
28
LXXIII
73