greendroid cast problem
1.
03-21 05:51:12.248: E/AndroidRuntime(1096): FATAL EXCEPTION: main
03-21 05:51:12.248: E/AndroidRuntime(1096): java.lang.RuntimeException: Unable to instantiate application com.example.contextawaredemo2.MainActivity: java.lang.ClassCastException: com.example.contextawaredemo2.MainActivity cannot be cast to android.app.Application
03-21 05:51:12.248: E/AndroidRuntime(1096): at android.app.LoadedApk.makeApplication(LoadedApk.java:504)
03-21 05:51:12.248: E/AndroidRuntime(1096): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4364)
03-21 05:51:12.248: E/AndroidRuntime(1096): at android.app.ActivityThread.access$1300(ActivityThread.java:141)
03-21 05:51:12.248: E/AndroidRuntime(1096): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1294)
03-21 05:51:12.248: E/AndroidRuntime(1096): at android.os.Handler.dispatchMessage(Handler.java:99)
03-21 05:51:12.248: E/AndroidRuntime(1096): at android.os.Looper.loop(Looper.java:137)
03-21 05:51:12.248: E/AndroidRuntime(1096): at android.app.ActivityThread.main(ActivityThread.java:5041)
03-21 05:51:12.248: E/AndroidRuntime(1096): at java.lang.reflect.Method.invokeNative(Native Method)
03-21 05:51:12.248: E/AndroidRuntime(1096): at java.lang.reflect.Method.invoke(Method.java:511)
03-21 05:51:12.248: E/AndroidRuntime(1096): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
03-21 05:51:12.248: E/AndroidRuntime(1096): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
03-21 05:51:12.248: E/AndroidRuntime(1096): at dalvik.system.NativeStart.main(Native Method)
03-21 05:51:12.248: E/AndroidRuntime(1096): Caused by: java.lang.ClassCastException: com.example.contextawaredemo2.MainActivity cannot be cast to android.app.Application
03-21 05:51:12.248: E/AndroidRuntime(1096): at android.app.Instrumentation.newApplication(Instrumentation.java:983)
03-21 05:51:12.248: E/AndroidRuntime(1096): at android.app.Instrumentation.newApplication(Instrumentation.java:968)
03-21 05:51:12.248: E/AndroidRuntime(1096): at android.app.LoadedApk.makeApplication(LoadedApk.java:499)
03-21 05:51:12.248: E/AndroidRuntime(1096): ... 11 more
在manifest 中不能粗心的这样写啊
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:name=".MainActivity">
需要再建一个application类 extends GDApplication
override various methods in order to style your application
1 public class MyApplication extends GDApplication{ 2 @Override 3 public Class<?> getHomeActivityClass() { 4 return MainActivity.class; 5 } 6 7 @Override 8 public Intent getMainApplicationIntent() { 9 return new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.app_url))); 10 } 11 12 }
android:name=".MyApplication">
2.
03-21 06:32:57.596: E/AndroidRuntime(1791): FATAL EXCEPTION: main
03-21 06:32:57.596: E/AndroidRuntime(1791): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.contextawaredemo2/com.example.contextawaredemo2.MainActivity}: android.view.InflateException: Binary XML file line #32: Error inflating class greendroid.widget.ActionBar
03-21 06:32:57.596: E/AndroidRuntime(1791): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
03-21 06:32:57.596: E/AndroidRuntime(1791): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
03-21 06:32:57.596: E/AndroidRuntime(1791): at android.app.ActivityThread.access$600(ActivityThread.java:141)
03-21 06:32:57.596: E/AndroidRuntime(1791): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
03-21 06:32:57.596: E/AndroidRuntime(1791): at android.os.Handler.dispatchMessage(Handler.java:99)
03-21 06:32:57.596: E/AndroidRuntime(1791): at android.os.Looper.loop(Looper.java:137)
03-21 06:32:57.596: E/AndroidRuntime(1791): at android.app.ActivityThread.main(ActivityThread.java:5041)
03-21 06:32:57.596: E/AndroidRuntime(1791): at java.lang.reflect.Method.invokeNative(Native Method)
03-21 06:32:57.596: E/AndroidRuntime(1791): at java.lang.reflect.Method.invoke(Method.java:511)
03-21 06:32:57.596: E/AndroidRuntime(1791): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
03-21 06:32:57.596: E/AndroidRuntime(1791): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
03-21 06:32:57.596: E/AndroidRuntime(1791): at dalvik.system.NativeStart.main(Native Method)
03-21 06:32:57.596: E/AndroidRuntime(1791): Caused by: android.view.InflateException: Binary XML file line #32: Error inflating class greendroid.widget.ActionBar
03-21 06:32:57.596: E/AndroidRuntime(1791): at android.view.LayoutInflater.createView(LayoutInflater.java:613)
03-21 06:32:57.596: E/AndroidRuntime(1791): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
03-21 06:32:57.596: E/AndroidRuntime(1791): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
03-21 06:32:57.596: E/AndroidRuntime(1791): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
03-21 06:32:57.596: E/AndroidRuntime(1791): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
03-21 06:32:57.596: E/AndroidRuntime(1791): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
03-21 06:32:57.596: E/AndroidRuntime(1791): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
03-21 06:32:57.596: E/AndroidRuntime(1791): at android.app.Activity.setContentView(Activity.java:1881)
03-21 06:32:57.596: E/AndroidRuntime(1791): at greendroid.app.GDActivity.ensureLayout(GDActivity.java:187)
03-21 06:32:57.596: E/AndroidRuntime(1791): at greendroid.app.GDListActivity.setListAdapter(GDListActivity.java:129)
03-21 06:32:57.596: E/AndroidRuntime(1791): at com.example.contextawaredemo2.MainActivity.onCreate(MainActivity.java:34)
03-21 06:32:57.596: E/AndroidRuntime(1791): at android.app.Activity.performCreate(Activity.java:5104)
03-21 06:32:57.596: E/AndroidRuntime(1791): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
03-21 06:32:57.596: E/AndroidRuntime(1791): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
03-21 06:32:57.596: E/AndroidRuntime(1791): ... 11 more
03-21 06:32:57.596: E/AndroidRuntime(1791): Caused by: java.lang.reflect.InvocationTargetException
03-21 06:32:57.596: E/AndroidRuntime(1791): at java.lang.reflect.Constructor.constructNative(Native Method)
03-21 06:32:57.596: E/AndroidRuntime(1791): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
03-21 06:32:57.596: E/AndroidRuntime(1791): at android.view.LayoutInflater.createView(LayoutInflater.java:587)
03-21 06:32:57.596: E/AndroidRuntime(1791): ... 24 more
03-21 06:32:57.596: E/AndroidRuntime(1791): Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x2/d=0x7f01002a a=-1}
03-21 06:32:57.596: E/AndroidRuntime(1791): at android.content.res.Resources.loadDrawable(Resources.java:1927)
03-21 06:32:57.596: E/AndroidRuntime(1791): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
03-21 06:32:57.596: E/AndroidRuntime(1791): at android.view.View.<init>(View.java:3330)
03-21 06:32:57.596: E/AndroidRuntime(1791): at android.view.ViewGroup.<init>(ViewGroup.java:431)
03-21 06:32:57.596: E/AndroidRuntime(1791): at android.widget.LinearLayout.<init>(LinearLayout.java:176)
03-21 06:32:57.596: E/AndroidRuntime(1791): at android.widget.LinearLayout.<init>(LinearLayout.java:172)
03-21 06:32:57.596: E/AndroidRuntime(1791): at greendroid.widget.ActionBar.<init>(ActionBar.java:134)
03-21 06:32:57.596: E/AndroidRuntime(1791): at greendroid.widget.ActionBar.<init>(ActionBar.java:130)
03-21 06:32:57.596: E/AndroidRuntime(1791): ... 27 more
You finally need to make your project use the GreenDroid base theme. In your AndroidManifest.xml, go to the application tag and add android:theme="@style/Theme.GreenDroid" as a new attribute.
需要定义theme