Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Class cast Exception in Android string.xml

I am developing an Android-App that uses the Facebook-SDKv3, so I created an entry in the strings.xml:

<resources>
  <string name="facebook_app_id">"12345678910"</string>
</resources>

and added the following to the Manifest:

<application>
  ...
  <meta-data android:name="com.facebook.sdk.ApplicationId" android:resource="@string/facebook_app_id" />
</application>

I always get this Exception:

02-06 16:35:01.231: W/Bundle(8316): Key com.facebook.sdk.ApplicationId expected String but value was a java.lang.Integer. The default value was returned.
02-06 16:35:01.231: W/Bundle(8316): Attempt to cast generated internal exception:
02-06 16:35:01.231: W/Bundle(8316): java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
02-06 16:35:01.231: W/Bundle(8316): at android.os.Bundle.getString(Bundle.java:1061)
02-06 16:35:01.231: W/Bundle(8316): at com.facebook.internal.Utility.getMetadataApplicationId(Utility.java:159)

I already tried to put the Numbers in "" but this did not solve the Problem, hope somebody can help me.

like image 535
bembii Avatar asked Feb 06 '13 15:02

bembii


People also ask

What is ClassCastException in Java?

The java.lang.ClassCastException is one of the unchecked exception in Java. It can occur in our program when we tried to convert an object of one class type into an object of another class type. When will be ClassCastException is thrown When we try to cast an object of Parent class to its Child class type, this exception will be thrown.

Can't cast integer to string in Java?

For example, an Integer object cannot be cast to a String object. This exception extends the RuntimeException class and thus belongs to those exceptions that can be thrown during the operation of the Java Virtual Machine (JVM).

Why do we get exceptions when casting between two classes?

When we try to cast an object of Parent class to its Child class type, this exception will be thrown. When we try to cast an object of one class into another class type that has not extended the other class or they don't have any relationship between them.

What is ClassCastException in thread “main”?

Exception in thread “main” java.lang.ClassCastException: class java.math.BigDecimal cannot be cast to class java.lang.String (java.math.BigDecimal and java.lang.String are in module java.base of loader ‘bootstrap’) We can fix the exception printing by means of converting the code in the below format:


1 Answers

Change it from android:resource to android:value

like image 97
NG. Avatar answered Sep 21 '22 04:09

NG.