Hi!
I need to use reflection and annotations in run-time. I am beginner
with android and i can not run an aplication. Maybe the source is
wrong but I thinks that it is right. When a run the emulator says me
that occur a java.lang.ExceptionInInitializerError exception.
My question is the next, how i can resolve this problem?.
My process of run the application is:
1.- Compile code.
2.- Run retrotranslator.
3.- Run android application from eclipse.
I show my example code:
package org.proof;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
public class HelloWorld extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle){
super.onCreate(icicle);
TextView tv=new TextView(this);
String strResult;
AnnotationAuthor aAuthor=new AnnotationAuthor();
aAuthor.setStrString("Hi");
aAuthor.setStrString(" my friends!");
Field attr[]=aAuthor.getClass().getDeclaredFields();
for(int i=0; i<attr.length;i++){
Annotation a[]=attr[i].getAnnotations();
for(int j=0;j<a.length;j++){
strResult=a[j]+" "+((Author)a[j]).name();
try{
String name=attr[i].getName();
name=String.valueOf(name.charAt(0)).toUpperCase()
+name.substring(1);
Method getter=aAuthor.getClass().getMethod("get"+name);
String value=getter.invoke(aAuthor,new
Object[0]).toString();
System.out.println("Field value: "+value);
}catch(Exception e){
e.printStackTrace();
}
tv.setText(strResult);
setContentView(tv);
}
}
}
}
Thanks for all.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
Announcing the new M5 SDK!
http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---