自己定义了一个Application,
protected WeimiApplication app;
然后在BaseActivity初始化
app = (WeimiApplication) getApplication();
当然,运行报错 Caused by: java.lang.ClassCastException: android.app.Application cannot be cast com.WeimiApplication
奇怪,明明是相对应的,为什么强转不了?
结果发现:在AndroidManifest.xml文件下,
<application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme">
没有 对name属性进行命名;修改如下:加上这句就OK了。
android:name=".WeimiApplication"