Today, we have a global variable appcontext, but it always appears, such as the following error, the original inheritance application in the manifest file declaration.
Java.lang.RuntimeException:Unable to start Activity componentinfo{com.langteng.shiliao/ Com.langteng.shiliao.activity.MainActivity}: Java.lang.ClassCastException:android.app.Application cannot is cast to Com.langteng.shiliao.until.AppContext
public class AppContext extends application {
public static final int nettype_wifi = 0x01;
public static final int nettype_cmwap = 0x02;
public static final int nettype_cmnet = 0x03;
public static final int page_size = 20;//default paging size
private static final int cache_time = 10*60000;//Cache Expiration Time
.................................
It then obtains a variable of type application by Getapplication () in the activity and transforms it into its own defined appcontext. For example, the following:
AppContext = (appContext) getapplication ();
The result is that the type conversion error is reported at execution time.
Later on the internet for a long time to find their own definition of the global application must be in the Androidmanifest.xml Register statement:
<application
Android:name= ". AppContext "
android:icon= "@drawable/ic_launcher"
Android:label= "@string/app_name"
Android:theme= "@style/apptheme" >
Android self-defined application global variable cannot type conversion problem