我想拥有多个应用程序类只是为了清理我的代码。
所以我创建了4个类。
1.A通用类供以后参考:
public class GlobalVariables extends Application {
}
我的时间函数的时间类:
public class SetZmanim extends GlobalVariables { static double latitude, longitude, elevation; static String locationName; static TimeZone timeZone; static GeoLocation location; static ComplexZmanimCalendar czc; public void setZmanimAPI() { locationName = "Queens, NY"; latitude = 40.725058; //Lakewood, NJ longitude = -73.815653; //Lakewood, NJ elevation = 0; //optional elevation timeZone = TimeZone.getTimeZone("America/New_York"); location = new GeoLocation(locationName, latitude, longitude, elevation, timeZone); czc = new ComplexZmanimCalendar(location); }
}
和 4 的实现方式与 2 扩展原始类的方式相同
这是我的清单:
<application
android:name=".GlobalVariables"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
错误:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.edonfreiner.siddur/com.example.edonfreiner.siddur.MainActivity}: java.lang.ClassCastException: com.example.edonfreiner.siddur.GlobalVariables cannot be cast to com.example.edonfreiner.siddur.SetStyles
不合格部分:
SetStyles setStyles;
setStyles = ((SetStyles) this.getApplication());