Kotlin IllegalStateException: Resource not found in classpath: kotlin/.kotlin_string_table - android

I'm trying to play around with Kotlin a bit in my Android app and am having trouble calling extension functions. The app crashes immediately with the following stack trace:
04-23 13:31:22.415 32606-32606/com.example.kotlin.test E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.kotlin.test, PID: 32606
java.lang.ExceptionInInitializerError
at org.jetbrains.kotlin.load.kotlin.reflect.RuntimeModuleData$Companion.create(RuntimeModuleData.kt:34)
at kotlin.reflect.jvm.internal.InternalPackage$moduleByClassLoader$cff17278.getOrCreateModule(moduleByClassLoader.kt:54)
at kotlin.reflect.jvm.internal.KClassImpl$descriptor$1.invoke(KClassImpl.kt:31)
at kotlin.reflect.jvm.internal.KClassImpl$descriptor$1.invoke(KClassImpl.kt:26)
at kotlin.reflect.jvm.internal.ReflectProperties$LazySoftVal.get(ReflectProperties.java:84)
at kotlin.reflect.jvm.internal.KClassImpl.getDescriptor(KClassImpl.kt)
at kotlin.reflect.jvm.internal.KClassImpl.getScope(KClassImpl.kt:43)
at kotlin.reflect.jvm.internal.KClassImpl.getProperties(KClassImpl.kt:84)
at kotlin.reflect.jvm.internal.KClassImpl.getProperties(KClassImpl.kt:72)
at kotlin.reflect.ReflectPackage$KClassExtensions$6beb0f9b.getDeclaredProperties(KClassExtensions.kt:25)
at kotlin.reflect.ReflectPackage.getDeclaredProperties(KClassExtensions.kt:1)
at com.example.test.kotlin.api.model.DatabaseObject$$TImpl.deflate(DatabaseObject.kt:40)
at com.example.test.kotlin.api.model.impl.Model.deflate(Model.kt)
at com.example.test.kotlin.api.model.impl.Model.<init>(Model.kt:28)
at com.example.test.kotlin.api.model.impl.TestModel.<init>(TestModel.kt:23)
at com.example.app.TestModelIndexFragment.onCreate(TestModelIndexFragment.java:122)
at android.support.v4.app.Fragment.performCreate(Fragment.java:1763)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:915)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1136)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:739)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1499)
at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:548)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1220)
at android.app.Activity.performStart(Activity.java:5949)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2292)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2389)
at android.app.ActivityThread.access$900(ActivityThread.java:147)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1296)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:898)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)
Caused by: java.lang.IllegalStateException: Built-in library initialization failed. Please ensure you have kotlin-runtime.jar in the classpath: java.lang.IllegalStateException: Resource not found in classpath: kotlin/.kotlin_string_table
at org.jetbrains.kotlin.builtins.KotlinBuiltIns.initialize(KotlinBuiltIns.java:75)
at org.jetbrains.kotlin.builtins.KotlinBuiltIns.getInstance(KotlinBuiltIns.java:93)
at org.jetbrains.kotlin.platform.JavaToKotlinClassMapBuilder.init(JavaToKotlinClassMapBuilder.java:35)
at org.jetbrains.kotlin.platform.JavaToKotlinClassMap.<init>(JavaToKotlinClassMap.java:44)
at org.jetbrains.kotlin.platform.JavaToKotlinClassMap.<clinit>(JavaToKotlinClassMap.java:35)
            at org.jetbrains.kotlin.load.kotlin.reflect.RuntimeModuleData$Companion.create(RuntimeModuleData.kt:34)
            at kotlin.reflect.jvm.internal.InternalPackage$moduleByClassLoader$cff17278.getOrCreateModule(moduleByClassLoader.kt:54)
            at kotlin.reflect.jvm.internal.KClassImpl$descriptor$1.invoke(KClassImpl.kt:31)
            at kotlin.reflect.jvm.internal.KClassImpl$descriptor$1.invoke(KClassImpl.kt:26)
            at kotlin.reflect.jvm.internal.ReflectProperties$LazySoftVal.get(ReflectProperties.java:84)
            at kotlin.reflect.jvm.internal.KClassImpl.getDescriptor(KClassImpl.kt)
            at kotlin.reflect.jvm.internal.KClassImpl.getScope(KClassImpl.kt:43)
            at kotlin.reflect.jvm.internal.KClassImpl.getProperties(KClassImpl.kt:84)
            at kotlin.reflect.jvm.internal.KClassImpl.getProperties(KClassImpl.kt:72)
            at kotlin.reflect.ReflectPackage$KClassExtensions$6beb0f9b.getDeclaredProperties(KClassExtensions.kt:25)
            at kotlin.reflect.ReflectPackage.getDeclaredProperties(KClassExtensions.kt:1)
            at com.example.test.kotlin.api.model.DatabaseObject$$TImpl.deflate(DatabaseObject.kt:40)
            at com.example.test.kotlin.api.model.impl.Model.deflate(Model.kt)
            at com.example.test.kotlin.api.model.impl.Model.<init>(Model.kt:28)
            at com.example.test.kotlin.api.model.impl.TestModel.<init>(TestModel.kt:23)
            at com.example.app.TestModelIndexFragment.onCreate(TestModelIndexFragment.java:122)
            at android.support.v4.app.Fragment.performCreate(Fragment.java:1763)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:915)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1136)
            at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:739)
            at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1499)
            at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:548)
            at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1220)
            at android.app.Activity.performStart(Activity.java:5949)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2292)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2389)
            at android.app.ActivityThread.access$900(ActivityThread.java:147)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1296)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5254)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:898)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)
Caused by: java.lang.IllegalStateException: Resource not found in classpath: kotlin/.kotlin_string_table
at org.jetbrains.kotlin.builtins.BuiltinsPackageFragment.getStream(BuiltinsPackageFragment.kt:86)
at org.jetbrains.kotlin.builtins.BuiltinsPackageFragment.<init>(BuiltinsPackageFragment.kt:55)
at org.jetbrains.kotlin.builtins.KotlinBuiltIns.<init>(KotlinBuiltIns.java:114)
at org.jetbrains.kotlin.builtins.KotlinBuiltIns.initialize(KotlinBuiltIns.java:70)
            at org.jetbrains.kotlin.builtins.KotlinBuiltIns.getInstance(KotlinBuiltIns.java:93)
            at org.jetbrains.kotlin.platform.JavaToKotlinClassMapBuilder.init(JavaToKotlinClassMapBuilder.java:35)
            at org.jetbrains.kotlin.platform.JavaToKotlinClassMap.<init>(JavaToKotlinClassMap.java:44)
            at org.jetbrains.kotlin.platform.JavaToKotlinClassMap.<clinit>(JavaToKotlinClassMap.java:35)
            at org.jetbrains.kotlin.load.kotlin.reflect.RuntimeModuleData$Companion.create(RuntimeModuleData.kt:34)
            at kotlin.reflect.jvm.internal.InternalPackage$moduleByClassLoader$cff17278.getOrCreateModule(moduleByClassLoader.kt:54)
            at kotlin.reflect.jvm.internal.KClassImpl$descriptor$1.invoke(KClassImpl.kt:31)
            at kotlin.reflect.jvm.internal.KClassImpl$descriptor$1.invoke(KClassImpl.kt:26)
            at kotlin.reflect.jvm.internal.ReflectProperties$LazySoftVal.get(ReflectProperties.java:84)
            at kotlin.reflect.jvm.internal.KClassImpl.getDescriptor(KClassImpl.kt)
            at kotlin.reflect.jvm.internal.KClassImpl.getScope(KClassImpl.kt:43)
            at kotlin.reflect.jvm.internal.KClassImpl.getProperties(KClassImpl.kt:84)
            at kotlin.reflect.jvm.internal.KClassImpl.getProperties(KClassImpl.kt:72)
            at kotlin.reflect.ReflectPackage$KClassExtensions$6beb0f9b.getDeclaredProperties(KClassExtensions.kt:25)
            at kotlin.reflect.ReflectPackage.getDeclaredProperties(KClassExtensions.kt:1)
            at com.example.test.kotlin.api.model.DatabaseObject$$TImpl.deflate(DatabaseObject.kt:40)
            at com.example.test.kotlin.api.model.impl.Model.deflate(Model.kt)
            at com.example.test.kotlin.api.model.impl.Model.<init>(Model.kt:28)
            at com.example.test.kotlin.api.model.impl.TestModel.<init>(TestModel.kt:23)
            at com.example.app.TestModelIndexFragment.onCreate(TestModelIndexFragment.java:122)
            at android.support.v4.app.Fragment.performCreate(Fragment.java:1763)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:915)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1136)
            at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:739)
            at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1499)
            at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:548)
            at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1220)
            at android.app.Activity.performStart(Activity.java:5949)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2292)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2389)
            at android.app.ActivityThread.access$900(ActivityThread.java:147)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1296)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5254)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:898)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)
My project is composed of two modules, test-kt and app, for the new Kotlin stuff and existing Java code respectively. test-kt/build.gradle has the following:
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 9
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main.kotlin.srcDirs += 'src/main/kotlin'
main.java.srcDirs += 'src/main/kotlin'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.0.0'
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
}
buildscript {
ext.kotlin_version = '0.11.91.2'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.android.tools.build:gradle:1.1.0'
}
}
repositories {
mavenCentral()
}
I've tried adding the Kotlin libs as dependencies within app as well with no luck. Is there something I'm missing?
EDIT: Upon further investigation, it looks like this only happens whenever I use property references (such as ::x) and not when I use extension methods. I definitely have included kotlin-reflect... any ideas?

I just encountered this as well when upgrading to Kotlin version 0.11.91.2. There is apparently an issue where the Android toolset does not pack a file prepended with a dot into resources. (note that the file the exception references, .kotlin_string_table, is prepended with a dot).
A fix has been written but not yet released. You can try using the snapshot release of Kotlin in order to take advantage of it, or otherwise just wait for the next update.

Related

Launching on 19 api gives an error res/drawable file missing

So I'm creating an app. And It gives me two following errors:
11-13 18:47:52.863 9717-9717/com.teamlukas.motivationapp E/VdcInflateDelegate﹕ Exception while inflating <vector>
org.xmlpull.v1.XmlPullParserException: Binary XML file line #17<vector> tag requires viewportWidth > 0
at android.support.graphics.drawable.VectorDrawableCompat.updateStateFromTypedArray(VectorDrawableCompat.java:717)
at android.support.graphics.drawable.VectorDrawableCompat.inflate(VectorDrawableCompat.java:654)
at android.support.graphics.drawable.VectorDrawableCompat.createFromXmlInner(VectorDrawableCompat.java:617)
at android.support.v7.widget.AppCompatDrawableManager$VdcInflateDelegate.createFromXmlInner(AppCompatDrawableManager.java:745)
at android.support.v7.widget.AppCompatDrawableManager.loadDrawableFromDelegates(AppCompatDrawableManager.java:365)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:195)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:188)
at android.support.v7.widget.AppCompatDrawableManager.checkVectorDrawableSetup(AppCompatDrawableManager.java:723)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:193)
at android.support.v7.widget.TintTypedArray.getDrawableIfKnown(TintTypedArray.java:81)
at android.support.v7.app.AppCompatDelegateImplBase.<init>(AppCompatDelegateImplBase.java:127)
at android.support.v7.app.AppCompatDelegateImplV9.<init>(AppCompatDelegateImplV9.java:147)
at android.support.v7.app.AppCompatDelegateImplV11.<init>(AppCompatDelegateImplV11.java:27)
at android.support.v7.app.AppCompatDelegateImplV14.<init>(AppCompatDelegateImplV14.java:53)
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:205)
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:185)
at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:525)
at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:74)
at com.teamlukas.motivationapp.MainActivity.onCreate(MainActivity.java:15)
at android.app.Activity.performCreate(Activity.java:5275)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2166)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2252)
at android.app.ActivityThread.access$800(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1200)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:606)
at dalvik.system.NativeStart.main(Native Method)
11-13 18:47:52.863 9717-9717/com.teamlukas.motivationapp D/AndroidRuntime﹕ Shutting down VM
11-13 18:47:52.863 9717-9717/com.teamlukas.motivationapp W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x41d10e48)
11-13 18:47:52.863 9717-9717/com.teamlukas.motivationapp E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.teamlukas.motivationapp, PID: 9717
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.teamlukas.motivationapp/com.teamlukas.motivationapp.MainActivity}: android.content.res.Resources$NotFoundException: File res/drawable/abc_vector_test.xml from drawable resource ID #0x7f020052
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2202)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2252)
at android.app.ActivityThread.access$800(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1200)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:606)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/abc_vector_test.xml from drawable resource ID #0x7f020052
at android.content.res.Resources.loadDrawable(Resources.java:2136)
at android.content.res.Resources.getDrawable(Resources.java:715)
at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:374)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:200)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:188)
at android.support.v7.widget.AppCompatDrawableManager.checkVectorDrawableSetup(AppCompatDrawableManager.java:723)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:193)
at android.support.v7.widget.TintTypedArray.getDrawableIfKnown(TintTypedArray.java:81)
at android.support.v7.app.AppCompatDelegateImplBase.<init>(AppCompatDelegateImplBase.java:127)
at android.support.v7.app.AppCompatDelegateImplV9.<init>(AppCompatDelegateImplV9.java:147)
at android.support.v7.app.AppCompatDelegateImplV11.<init>(AppCompatDelegateImplV11.java:27)
at android.support.v7.app.AppCompatDelegateImplV14.<init>(AppCompatDelegateImplV14.java:53)
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:205)
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:185)
at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:525)
at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:74)
at com.teamlukas.motivationapp.MainActivity.onCreate(MainActivity.java:15)
at android.app.Activity.performCreate(Activity.java:5275)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2166)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2252)
            at android.app.ActivityThread.access$800(ActivityThread.java:139)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1200)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5103)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:606)
            at dalvik.system.NativeStart.main(Native Method)
Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #17: invalid drawable tag vector
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:933)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:877)
at android.content.res.Resources.loadDrawable(Resources.java:2132)
            at android.content.res.Resources.getDrawable(Resources.java:715)
            at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:374)
            at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:200)
            at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:188)
            at android.support.v7.widget.AppCompatDrawableManager.checkVectorDrawableSetup(AppCompatDrawableManager.java:723)
            at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:193)
            at android.support.v7.widget.TintTypedArray.getDrawableIfKnown(TintTypedArray.java:81)
            at android.support.v7.app.AppCompatDelegateImplBase.<init>(AppCompatDelegateImplBase.java:127)
            at android.support.v7.app.AppCompatDelegateImplV9.<init>(AppCompatDelegateImplV9.java:147)
            at android.support.v7.app.AppCompatDelegateImplV11.<init>(AppCompatDelegateImplV11.java:27)
            at android.support.v7.app.AppCompatDelegateImplV14.<init>(AppCompatDelegateImplV14.java:53)
            at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:205)
            at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:185)
            at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:525)
            at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:74)
            at com.teamlukas.motivationapp.MainActivity.onCreate(MainActivity.java:15)
            at android.app.Activity.performCreate(Activity.java:5275)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2166)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2252)
            at android.app.ActivityThread.access$800(ActivityThread.java:139)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1200)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5103)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:606)
            at dalvik.system.NativeStart.main(Native Method)
It works on api 23, but when it's api 19, it gives me this crash. Any ideas to fix the error? I've never faced this error before so I don't know what to do. By the way, MainActivity code:
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(), Quote.class);
startActivity(intent);
}
});
Button settings = (Button) findViewById(R.id.button3);
settings.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent setting = new Intent(getApplicationContext(), Settings.class);
startActivity(setting);
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Gradle app module:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
vectorDrawables.useSupportLibrary = true
applicationId "com.teamlukas.motivationapp"
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:25.0.0'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.android.support:support-v4:25.0.0'
}
This shouldn't be a big issue to solve, try to do the following:
Method 1:
add the android:design in gradle
compile 'com.android.support:design:x.x.x.x'
replace the x.x.x.x with your available api tools.
Method 2:
Inside the activity that uses the vector add the following static code
static
{
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}
Method 3:
if you using gradle 1.5 use the following method
defaultConfig {
generatedDensities = []
}
// This is handled for you by the 2.0+ Gradle Plugin
aaptOptions {
additionalParameters "--no-version-vectors"
}
Method 4:
This method will work despite the gradle version you will be using
If targeting prelollipop devices use a selector directly from your imageview
1) app:srcCompat="#drawable/my_vector_drawable"
2) This will be the code for your selector :
name this: selector_my_vector_drawable
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/my_vector_drawable" />
</selector>
3) The pass the selector
for TextView :
<TextView
android:gravity="center_vertical"
android:drawableLeft="#drawable/selector_my_vector_drawable"
android:drawableStart="#drawable/selector_my_vector_drawable"
android:drawableRight="#drawable/selector_my_vector_drawable"
android:drawableEnd="#drawable/selector_my_vector_drawable"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/This will work" />
Method 5:
Learn about vectors here
Vectors
What is your min sdk. If you mentioned min sdk 20 that time it will crash. Ping me your min sdk with gradle file.

Error with reading parcelable object (after application is restored)

I have to save my custom class in save state bundle. So, I made it Parcelable and it looks good. When I rotate screen everything is goind well. But, when I minimalize my app, open some other, rotate screen and I try to go back to my app (from recent apps) it crashes.
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.game/com.example.game.MainActivity}: java.lang.RuntimeException: Parcelable encountered ClassNotFoundException reading a Serializable object (name = com.example.game.Player)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2306)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2366)
at android.app.ActivityThread.access$800(ActivityThread.java:149)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1284)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5297)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:908)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:703)
Caused by: java.lang.RuntimeException: Parcelable encountered ClassNotFoundException reading a Serializable object (name = com.example.game.Player)
at android.os.Parcel.readSerializable(Parcel.java:2378)
at android.os.Parcel.readValue(Parcel.java:2197)
at android.os.Parcel.readListInternal(Parcel.java:2520)
at android.os.Parcel.readList(Parcel.java:1655)
at com.example.game.Players.<init>(Players.java:106)
at com.example.game.Players$1.createFromParcel(Players.java:96)
at com.example.game.Players$1.createFromParcel(Players.java:93)
at android.os.Parcel.readParcelable(Parcel.java:2246)
at android.os.Parcel.readValue(Parcel.java:2146)
at android.os.Parcel.readArrayMapInternal(Parcel.java:2479)
at android.os.BaseBundle.unparcel(BaseBundle.java:221)
at android.os.Bundle.getSparseParcelableArray(Bundle.java:871)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:831)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1049)
at android.app.FragmentManagerImpl.dispatchCreate(FragmentManager.java:1864)
at android.app.Activity.onCreate(Activity.java:949)
at com.example.game.MainActivity.onCreate(MainActivity.java:24)
at android.app.Activity.performCreate(Activity.java:6020)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2259)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2366)
            at android.app.ActivityThread.access$800(ActivityThread.java:149)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1284)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5297)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:908)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:703)
Caused by: java.lang.ClassNotFoundException: com.example.game.Player
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:308)
at android.os.Parcel$2.resolveClass(Parcel.java:2364)
at java.io.ObjectInputStream.readNewClassDesc(ObjectInputStream.java:1641)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:657)
at java.io.ObjectInputStream.readNewObject(ObjectInputStream.java:1782)
at java.io.ObjectInputStream.readNonPrimitiveContent(ObjectInputStream.java:761)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:1983)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:1940)
at android.os.Parcel.readSerializable(Parcel.java:2372)
            at android.os.Parcel.readValue(Parcel.java:2197)
            at android.os.Parcel.readListInternal(Parcel.java:2520)
            at android.os.Parcel.readList(Parcel.java:1655)
            at com.example.game.Players.<init>(Players.java:106)
            at com.example.game.Players$1.createFromParcel(Players.java:96)
            at com.example.game.Players$1.createFromParcel(Players.java:93)
            at android.os.Parcel.readParcelable(Parcel.java:2246)
            at android.os.Parcel.readValue(Parcel.java:2146)
            at android.os.Parcel.readArrayMapInternal(Parcel.java:2479)
            at android.os.BaseBundle.unparcel(BaseBundle.java:221)
            at android.os.Bundle.getSparseParcelableArray(Bundle.java:871)
            at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:831)
            at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
            at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1049)
            at android.app.FragmentManagerImpl.dispatchCreate(FragmentManager.java:1864)
            at android.app.Activity.onCreate(Activity.java:949)
            at com.example.game.MainActivity.onCreate(MainActivity.java:24)
            at android.app.Activity.performCreate(Activity.java:6020)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2259)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2366)
            at android.app.ActivityThread.access$800(ActivityThread.java:149)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1284)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5297)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:908)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:703)
Caused by: java.lang.ClassNotFoundException: com.example.game.Player
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
            at java.lang.Class.classForName(Native Method)
            at java.lang.Class.forName(Class.java:308)
            at android.os.Parcel$2.resolveClass(Parcel.java:2364)
            at java.io.ObjectInputStream.readNewClassDesc(ObjectInputStream.java:1641)
            at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:657)
            at java.io.ObjectInputStream.readNewObject(ObjectInputStream.java:1782)
            at java.io.ObjectInputStream.readNonPrimitiveContent(ObjectInputStream.java:761)
            at java.io.ObjectInputStream.readObject(ObjectInputStream.java:1983)
            at java.io.ObjectInputStream.readObject(ObjectInputStream.java:1940)
            at android.os.Parcel.readSerializable(Parcel.java:2372)
            at android.os.Parcel.readValue(Parcel.java:2197)
            at android.os.Parcel.readListInternal(Parcel.java:2520)
at android.os.Parcel.readList(Parcel.java:1655)
            at com.example.game.Players.<init>(Players.java:106)
            at com.example.game.Players$1.createFromParcel(Players.java:96)
            at com.example.game.Players$1.createFromParcel(Players.java:93)
            at android.os.Parcel.readParcelable(Parcel.java:2246)
            at android.os.Parcel.readValue(Parcel.java:2146)
            at android.os.Parcel.readArrayMapInternal(Parcel.java:2479)
            at android.os.BaseBundle.unparcel(BaseBundle.java:221)
            at android.os.Bundle.getSparseParcelableArray(Bundle.java:871)
            at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:831)
            at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
            at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1049)
            at android.app.FragmentManagerImpl.dispatchCreate(FragmentManager.java:1864)
            at android.app.Activity.onCreate(Activity.java:949)
            at com.example.game.MainActivity.onCreate(MainActivity.java:24)
            at android.app.Activity.performCreate(Activity.java:6020)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2259)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2366)
            at android.app.ActivityThread.access$800(ActivityThread.java:149)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1284)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5297)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:908)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:703)
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
So, players is parcelable class. It is basically a List. Player is another class, serializable.
Player.java
import java.io.Serializable;
public class Player implements Serializable{
private String name;
private int points = 0;
// getters and setters
}
Players.java
public class Players implements Parcelable {
private List<Player> players;
//constructor, getters, setters
#Override
public int describeContents() {
return 0;
}
#Override
public void writeToParcel(Parcel parcel, int i) {
parcel.writeList(players);
}
public static final Parcelable.Creator<Players> CREATOR = new Parcelable.Creator<Players>() {
public Players createFromParcel(Parcel in) {
return new Players(in);
}
public Players[] newArray(int size) {
return new Players[size];
}
};
public Players(Parcel in) {
in.readList(players, List.class.getClassLoader());
}
}
At this point I don't know why my app crash. When I rotate it it's ok, when I minimize and maximize is ok, when I minimize, do some staff (open another app, rotate screen etc) and try to maximize it from recents it crash.
I'll be very gratefull for any kind of help ;) !
Have a good afternoon!
Parcelable class nest parcelable objects only.
Here in your case Player is not parcelable and is used in Parcelable class Players. Try to implement Parcelable in Player class too.
Your problem with minimising and opening the application is because Parcelable object is saved but it is not retrieved properly.
try to make following changes in your code :
public class Player implements Parcelable{
String name;
int points;
// getter setter
public static final Creator<Player> CREATOR = new Parcelable.Creator<Player>() {
#Override
public Player createFromParcel(Parcel in) {
return new Player(in);
}
#Override
public Player[] newArray(int size) {
return new Player[size];
}
};
public Player(Parcel in) {
this.name = in.readString();
this.points = in.readInt();
}
#Override
public int describeContents() {
return 0;
}
#Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(name);
dest.writeInt(points);
}
}
And in Players class while reading the list replace:
in.readList(players, List.class.getClassLoader());
with :
players = new ArrayList<>();
in.readList(players, getClass().getClassLoader());
Your code should work fine after these changes.

Simple facebook login test app will not launch

I'm making an app that needs to login with facebook and then start maps. It crashes instantly on my phone with "has unfortunaly stopped working". It seems to be the facebook SDK widget button that I use for login, but I cant figure out how to fix it
09-15 22:06:32.890 10289-10289/com.example.nan.spymap E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.nan.spymap, PID: 10289
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.nan.spymap/com.example.nan.spymap.MainActivity}: android.view.InflateException: Binary XML file line #16: Error inflating class com.facebook.login.widget.LoginButton
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: android.view.InflateException: Binary XML file line #16: Error inflating class com.facebook.login.widget.LoginButton
at android.view.LayoutInflater.createView(LayoutInflater.java:633)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:378)
at android.app.Activity.setContentView(Activity.java:2145)
at com.example.nan.spymap.MainActivity.onCreate(MainActivity.java:28)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
            at android.app.ActivityThread.access$800(ActivityThread.java:151)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5254)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at android.view.LayoutInflater.createView(LayoutInflater.java:607)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
            at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:378)
            at android.app.Activity.setContentView(Activity.java:2145)
            at com.example.nan.spymap.MainActivity.onCreate(MainActivity.java:28)
            at android.app.Activity.performCreate(Activity.java:5990)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
            at android.app.ActivityThread.access$800(ActivityThread.java:151)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5254)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: The SDK has not been initialized, make sure to call FacebookSdk.sdkInitialize() first.
at com.facebook.internal.Validate.sdkInitialized(Validate.java:136)
at com.facebook.AccessTokenTracker.<init>(AccessTokenTracker.java:55)
at com.facebook.login.widget.LoginButton$2.<init>(LoginButton.java:561)
at com.facebook.login.widget.LoginButton.configureButton(LoginButton.java:561)
at com.facebook.FacebookButtonBase.<init>(FacebookButtonBase.java:66)
at com.facebook.login.widget.LoginButton.<init>(LoginButton.java:200)
            at java.lang.reflect.Constructor.newInstance(Native Method)
            at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
            at android.view.LayoutInflater.createView(LayoutInflater.java:607)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
            at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:378)
            at android.app.Activity.setContentView(Activity.java:2145)
            at com.example.nan.spymap.MainActivity.onCreate(MainActivity.java:28)
            at android.app.Activity.performCreate(Activity.java:5990)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
            at android.app.ActivityThread.access$800(ActivityThread.java:151)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5254)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
My manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.nan.spymap" >
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="#string/facebook_app_id"/>
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.facebook.FacebookActivity"
android:configChanges=
"keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:theme="#android:style/Theme.Translucent.NoTitleBar"
android:label="#string/app_name" />
</application>
</manifest>
My activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:padding="16dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/info"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:textSize="18sp"
/>
<com.facebook.login.widget.LoginButton
android:id="#+id/login_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
/>
</RelativeLayout>
My MainActivity.java
package com.example.nan.spymap;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import com.facebook.CallbackManager;
import com.facebook.FacebookCallback;
import com.facebook.FacebookException;
import com.facebook.FacebookSdk;
import com.facebook.login.LoginResult;
import com.facebook.login.widget.LoginButton;
public class MainActivity extends Activity {
private CallbackManager callbackManager;
private TextView info;
private LoginButton loginButton;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FacebookSdk.sdkInitialize(getApplicationContext());
callbackManager = CallbackManager.Factory.create();
setContentView(R.layout.activity_main);
info = (TextView)findViewById(R.id.info);
loginButton = (LoginButton)findViewById(R.id.login_button);
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult loginResult) {
info.setText("User ID: " +
loginResult.getAccessToken().getUserId() + "\n" +
"Auth Token: " + loginResult.getAccessToken().getToken());
}
#Override
public void onCancel() {
info.setText("Login attempt cancelled.");
}
#Override
public void onError(FacebookException e) {
info.setText("Login attempt failed.");
}
});
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
callbackManager.onActivityResult(requestCode, resultCode, data);
}
}
My gradle build
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.example.nan.spymap"
minSdkVersion 21
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories { mavenCentral() }
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.facebook.android:facebook-android-sdk:4.6.0'
}
it says what's wrong in the stack trace:
Caused by: The SDK has not been initialized, make sure to call FacebookSdk.sdkInitialize() first.
The initialization is done AFTER the layout xml is loaded (in setContentView() ).
Initialize the SDK before or in your Application class.

android.app.Fragment$InstantiationException: Trying to instantiate a class ScannerFragment that is not a Fragment

I updated a few libraries in app.gradle like support library from 22.2.0 -> 23.0.0 and versions of few third party libraries, and now I'm getting the following runtime error in one particular activity:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.shubhamkanodia.bookmybook/com.example.shubhamkanodia.bookmybook.AddBooksActivity_}: android.view.InflateException: Binary XML file line #155: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2339)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2413)
at android.app.ActivityThread.access$800(ActivityThread.java:155)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1317)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5343)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)
Caused by: android.view.InflateException: Binary XML file line #155: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:257)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)
at com.example.shubhamkanodia.bookmybook.AddBooksActivity_.setContentView(AddBooksActivity_.java:56)
at com.example.shubhamkanodia.bookmybook.AddBooksActivity.onCreate(AddBooksActivity.java:140)
at com.example.shubhamkanodia.bookmybook.AddBooksActivity_.onCreate(AddBooksActivity_.java:46)
at android.app.Activity.performCreate(Activity.java:6010)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1129)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2292)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2413)
            at android.app.ActivityThread.access$800(ActivityThread.java:155)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1317)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5343)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)
Caused by: android.app.Fragment$InstantiationException: Trying to instantiate a class com.example.shubhamkanodia.bookmybook.Fragments.ScannerFragment that is not a Fragment
at android.app.Fragment.instantiate(Fragment.java:606)
at android.app.Fragment.instantiate(Fragment.java:582)
at android.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2110)
at android.app.Activity.onCreateView(Activity.java:5348)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:733)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
            at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:257)
            at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)
            at com.example.shubhamkanodia.bookmybook.AddBooksActivity_.setContentView(AddBooksActivity_.java:56)
            at com.example.shubhamkanodia.bookmybook.AddBooksActivity.onCreate(AddBooksActivity.java:140)
            at com.example.shubhamkanodia.bookmybook.AddBooksActivity_.onCreate(AddBooksActivity_.java:46)
            at android.app.Activity.performCreate(Activity.java:6010)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1129)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2292)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2413)
            at android.app.ActivityThread.access$800(ActivityThread.java:155)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1317)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5343)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)
Caused by: java.lang.ClassCastException
            at android.app.Fragment.instantiate(Fragment.java:606)
            at android.app.Fragment.instantiate(Fragment.java:582)
            at android.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2110)
            at android.app.Activity.onCreateView(Activity.java:5348)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:733)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
            at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:257)
            at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)
            at com.example.shubhamkanodia.bookmybook.AddBooksActivity_.setContentView(AddBooksActivity_.java:56)
            at com.example.shubhamkanodia.bookmybook.AddBooksActivity.onCreate(AddBooksActivity.java:140)
            at com.example.shubhamkanodia.bookmybook.AddBooksActivity_.onCreate(AddBooksActivity_.java:46)
            at android.app.Activity.performCreate(Activity.java:6010)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1129)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2292)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2413)
            at android.app.ActivityThread.access$800(ActivityThread.java:155)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1317)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5343)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)
In particular this line seems strange:
Caused by: android.app.Fragment$InstantiationException: Trying to instantiate a class com.example.shubhamkanodia.bookmybook.Fragments.ScannerFragment that is not a Fragment
( ScannerFragment is a fragment that implements dm77 barcode scanner which i updated from 1.7.2 to 1.8.2 )
Scanner Fragment:
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
import me.dm7.barcodescanner.zbar.BarcodeFormat;
import me.dm7.barcodescanner.zbar.Result;
import me.dm7.barcodescanner.zbar.ZBarScannerView;
public class ScannerFragment extends Fragment implements MessageDialogFragment.MessageDialogListener,
ZBarScannerView.ResultHandler, FormatSelectorDialogFragment.FormatSelectorDialogListener,
CameraSelectorDialogFragment.CameraSelectorDialogListener {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle state) {
mScannerView = new ZBarScannerView(getActivity());
//stuff
return mScannerView;
}
#Override
public void onActivityCreated(Bundle state){
super.onCreate(state);
//stuff
}
#Override
public void onCreate(Bundle state) {
super.onCreate(state);
setHasOptionsMenu(true);
}
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
//stuff
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle presses on the action bar items
//stuff
}
#Override
public void onResume() {
super.onResume();
//stuff
}
#Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
//stuff
}
#Override
public void handleResult(Result rawResult) {
//stuff
}
#Override
public void onPause() {
super.onPause();
//stuff
}
XML Snippet:
<FrameLayout
android:id="#+id/flScan"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:id="#+id/fScanner"
class="com.example.shubhamkanodia.bookmybook.Fragments.ScannerFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:layout_marginTop="8dp"
android:background="#color/transparent"
android:padding="12dp">
<ImageButton
android:id="#+id/ibAutofocus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="#drawable/ripple_light"
android:clickable="true"
android:contentDescription="Enable / Disable Autofocus"
android:longClickable="true"
android:padding="8dp"
android:src="#mipmap/ic_action_auto_focus_on" />
<ImageButton
android:id="#+id/ibFlashControl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#id/ibAutofocus"
android:background="#drawable/ripple_light"
android:clickable="true"
android:contentDescription="Enable / Disable Flash"
android:longClickable="true"
android:padding="8dp"
android:src="#mipmap/ic_action_image_flash_off" />
</RelativeLayout>
</FrameLayout>
Any help would be appreciated!
Try importing android.app.Fragment instead of android.support.v4.app.Fragment basically don't use support library if you don't need it 'or check that Activity in which you are inflating this fragment about : Whether you are using the FragmentManager and FragmentTransaction from support library only.

Find missing onError in the project

I am trying to locate a missing onError() in a project. It means that the app crashes because a subscription does not handle the throwables so I want to locate that subcription and add the onError method.
Unfortunatelly the stacktrace is not really helpful here and it only shows the line of the throw new IOException but nothing more:
FATAL EXCEPTION: main
Process: my.app.example.dev, PID: 20309
java.lang.IllegalStateException: Fatal Exception thrown on Scheduler.Worker thread.
at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:54)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: rx.exceptions.OnErrorFailedException: Error occurred when trying to propagate error to Observer.onError
at rx.observers.SafeSubscriber._onError(SafeSubscriber.java:201)
at rx.observers.SafeSubscriber.onError(SafeSubscriber.java:111)
at rx.android.app.OperatorConditionalBinding$1.onError(OperatorConditionalBinding.java:69)
at rx.internal.operators.NotificationLite.accept(NotificationLite.java:147)
at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber.pollQueue(OperatorObserveOn.java:177)
at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber.access$000(OperatorObserveOn.java:65)
at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber$2.call(OperatorObserveOn.java:153)
at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:47)
            at android.os.Handler.handleCallback(Handler.java:739)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5221)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: rx.exceptions.CompositeException: 2 exceptions occurred.
            at rx.observers.SafeSubscriber._onError(SafeSubscriber.java:201)
            at rx.observers.SafeSubscriber.onError(SafeSubscriber.java:111)
            at rx.android.app.OperatorConditionalBinding$1.onError(OperatorConditionalBinding.java:69)
            at rx.internal.operators.NotificationLite.accept(NotificationLite.java:147)
            at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber.pollQueue(OperatorObserveOn.java:177)
            at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber.access$000(OperatorObserveOn.java:65)
            at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber$2.call(OperatorObserveOn.java:153)
            at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:47)
            at android.os.Handler.handleCallback(Handler.java:739)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5221)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: rx.exceptions.CompositeException$CompositeExceptionCausalChain: Chain of Causes for CompositeException In Order Received =>
at com.splunk.mint.ExceptionHandler.uncaughtException(ExceptionHandler.java:42)
at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:693)
at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:690)
at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:58)
            at android.os.Handler.handleCallback(Handler.java:739)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5221)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: retrofit.RetrofitError: java.io.IOException: No connectivity
at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:385)
at retrofit.RestAdapter$RestHandler.access$100(RestAdapter.java:221)
at retrofit.RestAdapter$RestHandler$1.call(RestAdapter.java:271)
at retrofit.RestAdapter$RestHandler$1.call(RestAdapter.java:269)
at retrofit.RxSupport$2.run(RxSupport.java:46)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.io.IOException: No connectivity
at my.app.example.manager.ApiManager$NetworkAwareOKClient.execute(ApiManager.java:1071)
at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:322)
            at retrofit.RestAdapter$RestHandler.access$100(RestAdapter.java:221)
            at retrofit.RestAdapter$RestHandler$1.call(RestAdapter.java:271)
            at retrofit.RestAdapter$RestHandler$1.call(RestAdapter.java:269)
            at retrofit.RxSupport$2.run(RxSupport.java:46)
            at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
            at java.util.concurrent.FutureTask.run(FutureTask.java:237)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
            at java.lang.Thread.run(Thread.java:818)
Any ideas to locate the subscription (line in code) that does not have the onError() ?
This can be a pain to debug. Funnily enough I had an error inside the Action1<Throwable> [facepalm].
The best was to debug this is to register a global error handler. This will saw you the truth in your code:
RxJavaPlugins.getInstance().registerErrorHandler(new RxJavaErrorHandler() {
#Override
public void handleError(Throwable e) {
Log.w("Error",e);
}
});
A discussion on github: https://github.com/ReactiveX/RxJava/issues/2293
If the onError is not implemented, then RxJava throw a OnErrorNotImplementedException exception. It's seems that RxJava didn't succed to call the onError method ("Error occurred when trying to propagate error to Observer.onError")
You can try to register an error handler to find the root exception.
static {
RxJavaPlugins.getInstance().registerErrorHandler(new RxJavaErrorHandler() {
#Override
public void handleError(Throwable e) {
e.printStackTrace();
}
});
}
Use this one:
RxJavaHooks.setOnError(throwable -> {
if (throwable != null && throwable.getMessage() != null) {
Log.e("Error", throwable.getMessage());
}
});
Instead of deprecated RxJavaPlugins.getInstance()

Categories

Resources