Skip to content Skip to sidebar Skip to footer

Classcastexception: Android.app.application

The class which causes error is given below: package com.extrasmart; import android.app.Activity; import android.os.Bundle; import android.view.View; //import android.view.View; i

Solution 1:

ExtraSmartApplicationapplication= (ExtraSmartApplication) getApplication(); 

Add:

<application android:icon="@drawable/icon" 
    android:label="@string/app_name" 
    android:name="ExtraSmartApplication">

in your Android manifest.xml file.

Solution 2:

It would be better if u can share some code snippets...

Anyways, as far as ClassCastException is concerned, it means you are declaring a variable of some type and assigning it to another type you have defined in a layout xml file...

for example, in the xml you may have had:

<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="wrap_content"android:layout_height="wrap_content"><Buttonandroid:layout_height="wrap_content"android:id="@+id/btn1"android:layout_width="wrap_content"></Button></LinearLayout>

but while connecting the component to code:

ImageViewimg1= (ImageView)context.findViewById(R.id.btn1);

This will fire a ClassCastException bcoz you are casting a Button to an ImageView variable which is as u understand not possible!

If this doesnt solve your problem then it'll be better if u post some code snippets after figuring out which code snippet causes the error!

Post a Comment for "Classcastexception: Android.app.application"