我的MainActivity菜单中有一个项目,我在其中调用另一个名为HomeActivity的活动:
public class HomeActivity extends Activity{ private static final String TAG = "cpuSpy"; private cpuSpyApp _app = null; // the vIEws private linearLayout _uiStatesVIEw = null; private TextVIEw _uiAdditionalStates = null; private TextVIEw _uiTotalStateTime = null; private TextVIEw _uiheaderAdditionalStates = null; private TextVIEw _uiheaderTotalStateTime = null; private TextVIEw _uiStatesWarning = null; private TextVIEw _uiKernelString = null; /** whether or not we're updating the data in the background */ private boolean _updatingData = false; /** Initialize the Activity */ @OverrIDe public voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // inflate the vIEw, stash the app context, and get all UI elements setContentVIEw(R.layout.home_layout); _app = (cpuSpyApp)getApplication(); // set Title to version string //setTitle(getResources().getText(R.string.app_name) + " v" + //getResources().getText(R.string.version_name)); // see if we're updating data during a config change (rotate screen) if (savedInstanceState != null) { _updatingData = savedInstanceState.getBoolean("updatingData"); } }-------
在这一行:
_app = (cpuSpyApp)getApplication(); findVIEws();
我正在调用另一个cpuSpyApp类,它在几行代码中解释:
public class cpuSpyApp extends Application { private static final String KERNEL_VERSION_PATH = "/proc/version"; private static final String TAG = "cpuSpyApp"; private static final String PREF_name = "cpuSpyPreferences"; private static final String PREF_OFFSETS = "offsets"; /** the long-living object used to monitor the system frequency states */ private cpuStateMonitor _monitor = new cpuStateMonitor(); private String _kernelVersion = ""; /** * On application start, load the saved offsets and stash the * current kernel version string */ @OverrIDe public voID onCreate(){ loadOffsets(); updateKernelVersion(); }
当我单击菜单中的某个项目时,会发生应用程序崩溃,并且logcat会在下面显示错误
Caused by: java.lang.classCastException: androID.app.Application cannot be cast to....
我该如何解决这个问题?
解决方法:
在AndroIDmanifest .xml中
<application androID:name="your.Packagename.cpuSpyApp"
总结 以上是内存溢出为你收集整理的java – 如何修复`android.app.Application无法转换为’错误全部内容,希望文章能够帮你解决java – 如何修复`android.app.Application无法转换为’错误所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)