Today we have a global variable appcontext, but the following error has occurred, 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 converts it into a custom appcontext. As follows:
AppContext = (appContext) getapplication ();
The result is that the type conversion error is reported at run time.
It was a long time before I found out. The custom global application must be registered in the Androidmanifest.xml declaration:
<application
Android:name= ". AppContext "
android:icon= "@drawable/ic_launcher"
Android:label= "@string/app_name"
Android:theme= "@style/apptheme" >
Android custom application global variable cannot type conversion problem