Hi all,
I am new to Android and Java (though have plenty of Javascript
experience). I am learning the language, the OS, and the programming
environment all at once, so I know I am missing simple stuff here. I
have an extremely basic program that takes the year, month, and day,
makes a few calculations based on that, and uses it to determine which
strings print in unique combinations based on the date. I used Droid
Draw to create an extremely simple interface. There are no obvious
errors on the page and the app appears to run but immediately crashes
on the emulator.
Here is my source:
package com.Borg.energy;
import java.util.Calendar;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class energize extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView daylbl;
TextView monthlbl;
TextView text1;
TextView text2;
TextView yearlbl;
int mo = 0;
int yr = 0;
int dy = 0;
int da = 0;
int Stem = 0;
int Branch = 0;
String stemtype = "";
String branchtype = "";
String yeartype = "";
String yearinfo = "";
text1 = (TextView)this.findViewById(R.id.text1);
text2 = (TextView)this.findViewById(R.id.text2);
final Calendar Cal = Calendar.getInstance();
mo = 7; //Cal.get(Calendar.MONTH);
yr = 2010; //Cal.get(Calendar.YEAR) - 1900;
dy = 16; //Cal.get(Calendar.DATE);
daylbl = (TextView)this.findViewById(R.id.daylbl);
monthlbl = (TextView)this.findViewById(R.id.monthlbl);
yearlbl = (TextView)this.findViewById(R.id.yearlbl);
daylbl.setText(dy);
monthlbl.setText(mo);
yearlbl.setText(yr);
if(yr == 2002) {
Stem = 6;
Branch = 6;
}
if (yr == 2003) { Stem = 1; Branch = 11; }
if (yr == 2004) { Stem = 6; Branch = 4; }
if (yr == 2005) { Stem = 2; Branch = 10; }
if (yr == 2006) { Stem = 7; Branch = 3; }
if (yr == 2007) { Stem = 2; Branch = 8; }
if (yr == 2008) { Stem = 7; Branch = 1; }
if (yr == 2009) { Stem = 3; Branch = 7; }
if (yr == 2010) { Stem = 8; Branch = 12; }
if (yr == 2011) { Stem = 3; Branch = 5; }
if (yr == 2012) { Stem = 8; Branch = 10; }
if (yr == 2013) { Stem = 4; Branch = 4; }
if (yr == 2014) { Stem = 9; Branch = 9; }
if (yr == 2015) { Stem = 4; Branch = 2; }
if (yr == 2016) { Stem = 9; Branch = 7; }
if (yr == 2017) { Stem = 5; Branch = 1; }
if (yr == 2018) { Stem = 10; Branch = 6; }
if (yr == 2019) { Stem = 5; Branch = 11; }
if (yr == 2020) { Stem = 10; Branch = 4; }
if (yr == 2021) { Stem = 6; Branch = 10; }
if (yr == 2022) { Stem = 1; Branch = 3; }
if (yr == 2023) { Stem = 6; Branch = 8; }
if (yr == 2024) { Stem = 1; Branch = 1; }
if (yr == 2025) { Stem = 7; Branch = 7; }
if (yr == 2026) { Stem = 2; Branch = 12; }
if (yr == 2027) { Stem = 7; Branch = 5; }
if (yr == 2028) { Stem = 3; Branch = 11; }
if (yr == 2029) { Stem = 8; Branch = 4; }
if (yr == 2030) { Stem = 3; Branch = 9; }
if (yr == 2031) { Stem = 8; Branch = 2; }
if (mo == 1) { Stem = Stem - 1; Branch = Branch - 1; }
if (mo == 2) { Stem = Stem - 0; Branch = Branch + 6; }
if (mo == 3) { Stem = Stem - 2; Branch = Branch + 10; }
if (mo == 4) { Stem = Stem - 1; Branch = Branch + 5; }
if (mo == 5) { Stem = Stem - 1; Branch = Branch - 1; }
if (mo == 6) { Stem = Stem - 0; Branch = Branch + 6; }
if (mo == 7) { Stem = Stem - 0; Branch = Branch - 0; }
if (mo == 8) { Stem = Stem + 1; Branch = Branch + 7; }
if (mo == 9) { Stem = Stem + 2; Branch = Branch + 2; }
if (mo == 10) { Stem = Stem + 2; Branch = Branch + 8; }
if (mo == 11) { Stem = Stem + 3; Branch = Branch + 3; }
if (mo == 12) { Stem = Stem + 3; Branch = Branch + 9; }
if ((yr == 2000) || (yr == 2004) || (yr == 2008) || (yr ==
2012) || (yr == 2016) || (yr == 2020) || (yr == 2024) || (yr ==
2028)) {
Stem = Stem + 1; Branch = Branch + 1;
if (mo >= 3) { Stem = Stem + 1; Branch = Branch + 1; }
} else {
Stem = Stem + 1; Branch = Branch + 1;
}
dy = dy - 1;
Stem = Stem + dy;
Branch = Branch + dy;
do {
Stem = Stem - 10;
} while (Stem >= 11);
do {
Branch = Branch - 12;
} while (Branch >=13);
if (Stem == 1) { stemtype = "Wood Yang"; }
if (Stem == 2) { stemtype = "Wood Yin"; }
if (Stem == 3) { stemtype = "Fire Yang"; }
if (Stem == 4) { stemtype = "Fire Yin"; }
if (Stem == 5) { stemtype = "Earth Yang"; }
if (Stem == 6) { stemtype = "Earth Yin"; }
if (Stem == 7) { stemtype = "Metal Yang"; }
if (Stem == 8) { stemtype = "Metal Yin"; }
if (Stem == 9) { stemtype = "Water Yang"; }
if (Stem == 10) { stemtype = "Water Yin"; }
if (Branch == 1) { branchtype = "Water"; }
if (Branch == 2) { branchtype = "Earth"; }
if (Branch == 3) { branchtype = "Wood"; }
if (Branch == 4) { branchtype = "Wood"; }
if (Branch == 5) { branchtype = "Earth"; }
if (Branch == 6) { branchtype = "Fire"; }
if (Branch == 7) { branchtype = "Fire"; }
if (Branch == 8) { branchtype = "Earth"; }
if (Branch == 9) { branchtype = "Metal"; }
if (Branch == 10) { branchtype = "Metal"; }
if (Branch == 11) { branchtype = "Earth"; }
if (Branch == 12) { branchtype = "Water"; }
text1.setText(stemtype + " " + branchtype);
if (yr == 2002 && mo > 1) { yeartype = "Fire Yin; Water"; }
if ((yr == 2003) && (mo == 1)) { yeartype = "Fire Yin; Water"; }
if ((yr == 2003) && ((mo > 2) || ((mo == 2) && (da >= 1))))
{ yeartype = "Earth Yang: Water";}
if ((yr == 2004) && ((mo == 1) && (da < 22))) { yeartype = "Earth
Yang: Water"; }
if ((yr == 2004) && ((mo > 1) || ((mo == 1) && (da >= 22))))
{ yeartype = "Metal Yin: Wood"; }
if ((yr == 2005) && ((mo == 1) || ((mo == 2) && (da < 9))))
{ yeartype = "Metal Yin: Wood"; }
if ((yr == 2005 && ((mo > 2) || ((mo == 2 && da >= 9)))))
{ yeartype = "Metal Yin: Wood";}
if ((yr == 2006 && ((mo == 1) && (da < 29)))) { yeartype = "Metal
Yin: Wood"; }
if ((yr == 2006 && ((mo > 1) || ((mo == 1) && (da >= 29)))))
{ yeartype = "Earth Yang: Fire"; }
if ((yr == 2007 && ((mo == 1) || ((mo == 2) && (da < 18)))))
{ yeartype = "Earth Yang: Fire"; }
if ((yr == 2007 && ((mo > 2) || ((mo == 2) && (da >= 18)))))
{ yeartype = "Water Yin: Fire"; }
if ((yr == 2008 && ((mo == 1) || ((mo == 2) && (da < 7)))))
{ yeartype = "Water Yin: Fire"; }
if ((yr == 2008 && ((mo > 2) || ((mo == 2) && (da >= 7)))))
{ yeartype = "Water Yang: Earth"; }
if ((yr == 2009 && ((mo == 1) && (da < 26)))) { yeartype = "Water
Yang: Earth"; }
if ((yr == 2009 && ((mo > 1) || ((mo == 1) && (da >= 26)))))
{ yeartype = "Earth Yang: Earth"; }
if ((yr == 2010 && ((mo == 1) || (mo == 2) && (da < 10))))
{ yeartype = "Earth Yang: Earth"; }
if ((yr == 2010 && ((mo > 2) || ((mo == 2) && (da >= 10)))))
{ yeartype = "Wood Yin: Metal"; }
if ((yr == 2011 && ((mo == 1) || ((mo == 2) && (da < 3)))))
{ yeartype = "Wood Yin: Metal"; }
if ((yr == 2011 && ((mo > 2) || ((mo == 2) && (da >= 3)))))
{ yeartype = "Wood Yang: Metal"; }
if ((yr == 2012 && ((mo == 1) && (da < 23)))) { yeartype = "Wood
Yang: Metal"; }
if ((yr == 2012 && ((mo > 1) || ((mo == 1) && (da >= 23)))))
{ yeartype = "Earth Yin: Water"; }
if ((yr == 2013 && ((mo == 1) || ((mo == 2) && (da < 10)))))
{ yeartype = "Earth Yin: Water"; }
if ((yr == 2013 && ((mo > 2) || ((mo == 2) && (da >= 10)))))
{ yeartype = "Fire Yin: Water"; }
if ((yr == 2014 && ((mo == 1) && (da < 31)))) { yeartype = "Fire
Yin: Water"; }
if ((yr == 2014 && ((mo > 1) || ((mo == 1) && (da >= 31)))))
{ yeartype = "Fire Yang: Wood"; }
if ((yr == 2015 && ((mo == 1) || (mo == 2) && (da < 19))))
{ yeartype = "Fire Yang: Wood"; }
if ((yr == 2015 && ((mo > 2) || ((mo == 2) && (da >= 19)))))
{ yeartype = "Earth Yin: Wood"; }
if ((yr == 2016 && ((mo == 1) || ((mo == 2) && (da < 9)))))
{ yeartype = "Earth Yin: Wood"; }
if ((yr == 2016 && ((mo > 2) || ((mo == 2) && (da >= 9)))))
{ yeartype = "Metal Yang: Fire"; }
if ((yr == 2017 && ((mo == 1) && (da < 28)))) { yeartype = "Metal
Yang: Fire"; }
if ((yr == 2017 && ((mo > 1) || ((mo == 1) && (da >= 28)))))
{ yeartype = "Metal Yang: Fire"; }
if ((yr == 2018 && ((mo == 1) || ((mo == 2) && (da < 16)))))
{ yeartype = "Metal Yang: Fire"; }
if ((yr == 2018 && ((mo > 1) || ((mo == 1) && (da >= 22)))))
{ yeartype = "Earth Yin: Earth"; }
if ((yr == 2019 && ((mo == 1) || ((mo == 2) && (da < 5)))))
{ yeartype = "Earth Yin: Earth"; }
if ((yr == 2019 && ((mo > 2) || ((mo == 2) && (da >= 5)))))
{ yeartype = "Water Yang: Earth"; }
if ((yr == 2020 && ((mo == 1) && (da < 25)))) { yeartype = "Water
Yang: Earth"; }
if ((yr == 2020 && ((mo > 1) || ((mo == 1) && (da >= 25)))))
{ yeartype = "Water Yin: Metal"; }
text2.setText(yearinfo);
}
Here's my error log:
07-16 22:31:20.192: ERROR/AndroidRuntime(418): ERROR: thread attach
failed
07-16 22:31:22.952: ERROR/AndroidRuntime(426): ERROR: thread attach
failed
07-16 22:31:24.452: ERROR/AndroidRuntime(433): Uncaught handler:
thread main exiting due to uncaught exception
07-16 22:31:24.482: ERROR/AndroidRuntime(433):
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.Borg.energy/com.Borg.energy.energize}:
android.content.res.Resources$NotFoundException: String resource ID
#0x10
07-16 22:31:24.482: ERROR/AndroidRuntime(433): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
2496)
07-16 22:31:24.482: ERROR/AndroidRuntime(433): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:
2512)
07-16 22:31:24.482: ERROR/AndroidRuntime(433): at
android.app.ActivityThread.access$2200(ActivityThread.java:119)
07-16 22:31:24.482: ERROR/AndroidRuntime(433): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
07-16 22:31:24.482: ERROR/AndroidRuntime(433): at
android.os.Handler.dispatchMessage(Handler.java:99)
07-16 22:31:24.482: ERROR/AndroidRuntime(433): at
android.os.Looper.loop(Looper.java:123)
07-16 22:31:24.482: ERROR/AndroidRuntime(433): at
android.app.ActivityThread.main(ActivityThread.java:4363)
07-16 22:31:24.482: ERROR/AndroidRuntime(433): at
java.lang.reflect.Method.invokeNative(Native Method)
07-16 22:31:24.482: ERROR/AndroidRuntime(433): at
java.lang.reflect.Method.invoke(Method.java:521)
07-16 22:31:24.482: ERROR/AndroidRuntime(433): at
com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:860)
07-16 22:31:24.482: ERROR/AndroidRuntime(433): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
07-16 22:31:24.482: ERROR/AndroidRuntime(433): at
dalvik.system.NativeStart.main(Native Method)
07-16 22:31:24.482: ERROR/AndroidRuntime(433): Caused by:
android.content.res.Resources$NotFoundException: String resource ID
#0x10
07-16 22:31:24.482: ERROR/AndroidRuntime(433): at
android.content.res.Resources.getText(Resources.java:200)
07-16 22:31:24.482: ERROR/AndroidRuntime(433): at
android.widget.TextView.setText(TextView.java:2813)
07-16 22:31:24.482: ERROR/AndroidRuntime(433): at
com.Borg.energy.energize.onCreate(energize.java:47)
07-16 22:31:24.482: ERROR/AndroidRuntime(433): at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:
1047)
07-16 22:31:24.482: ERROR/AndroidRuntime(433): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
2459)
07-16 22:31:24.482: ERROR/AndroidRuntime(433): ... 11 more
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en