Android App Shortcuts Broke in Lower Android Versions - android

Today, I was making an application with the newest Android 7.1 feature, App Shortcuts. At first, it runs well on Android 7.1.1. However, when I made it run on MIUI 8 on Android M, it broke unfortunately. I have wrote something to make it run on M or lower version, but it broke again. I was confused. I hope someone can give me a solution on this problem. I will be appreciated if someone can help me. Thanks anyway!
Here is my code.
findViewById(R.id.textView5).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
addshortcut();
}
});
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
shortcutManager = getSystemService(ShortcutManager.class);
}
public void addshortcut(){
TextView textView = (TextView)findViewById(R.id.textView5);
String name = textView.getText().toString();
ShortcutInfo dynamicShortcut = null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
dynamicShortcut = new ShortcutInfo.Builder(this, "shortcut_dynamic-zty")
.setShortLabel(name)
.setLongLabel(name)
.setIcon(Icon.createWithResource(this,R.drawable.ic_account_circle))
.setIntents(
new Intent[]{
new Intent(Intent.ACTION_VIEW, Uri.EMPTY,com.zengtianyu.gallery1.DetailZTY.this, DetailZTY.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK),
})
.build();
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
shortcutManager.setDynamicShortcuts(Arrays.asList(dynamicShortcut));
}
Toast.makeText(this,"添加成功",Toast.LENGTH_SHORT).show();
}
Here is the log.
java.lang.NoClassDefFoundError: Failed resolution of:Landroid/content/pm/ShortcutManager;
at com.zengtianyu.gallery1.DetailLSW.onCreate(DetailLSW.java:88)
at android.app.Activity.performCreate(Activity.java:6323)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2411)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2518)
at android.app.ActivityThread.access$1000(ActivityThread.java:153)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1382)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:5544)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:102)
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.content.pm.ShortcutManager" on path: DexPathList[[zip file "/data/app/com.zengtianyu.gallery1-1/base.apk"],nativeLibraryDirectories=[/data/app/com.zengtianyu.gallery1-1/lib/arm64, /vendor/lib64, /system/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
... 14 more
Suppressed: java.lang.ClassNotFoundException: Didn't find class "android.content.pm.ShortcutManager" on path: DexPathList[[dex file "/data/dalvik-cache/xposed_XResourcesSuperClass.dex"],nativeLibraryDirectories=[/vendor/lib64, /system/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 15 more
Suppressed: java.lang.ClassNotFoundException:android.content.pm.ShortcutManager
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:504)
... 16 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available

You are passing ShortcutManager.class instead of the string constant SHORTCUT_SERVICE
Change line 8 to the following:
shortcutManager = (ShortcutManager)getSystemService(SHORTCUT_SERVICE);
If you wish to support older android versions, don't make shortcutManager a global variable and instead create it in the addShortcut() function and wrapping the usage of the function inside the sdk version check on line 7
So you should end up with:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
addShortcut();
}
...
public void addShortcut(){
ShortcutManager shortcutManager = (ShortcutManager)getSystemService(SHORTCUT_SERVICE);
...
}

Related

App stopped responding on adding data to FireBase. Getting: Failed resolution of: Lcom/google/common/base/CharMatcher;

I'm new to FireStore, and when I was trying to insert a data using Hashmap it is showing error.
This is the line which I'm adding to my firestore:
Map map = new HashMap<>();
map.put("And","What");
map.put("So","What Bro");
firebaseFirestore.collection("mycollection").document("mydocument").set(map).addOnSuccessListener(new OnSuccessListener<Void>() {
#Override
public void onSuccess(Void aVoid) {
Toast.makeText(ContactActivity.this, "Success", Toast.LENGTH_SHORT).show();
}
}).addOnFailureListener(new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
Toast.makeText(ContactActivity.this, "Failure", Toast.LENGTH_SHORT).show();
}
});
And the error is:
E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1
Process: com.example.myapp, PID: 13076
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/common/base/CharMatcher;
at com.google.common.base.Splitter.on(Splitter.java:125)
at io.grpc.internal.GrpcUtil.(GrpcUtil.java:203)
at io.grpc.internal.AbstractManagedChannelImplBuilder.(AbstractManagedChannelImplBuilder.java:84)
at io.grpc.okhttp.OkHttpChannelProvider.builderForTarget(OkHttpChannelProvider.java:48)
at io.grpc.okhttp.OkHttpChannelProvider.builderForTarget(OkHttpChannelProvider.java:27)
at io.grpc.ManagedChannelBuilder.forTarget(ManagedChannelBuilder.java:73)
at com.google.firebase.firestore.remote.GrpcCallProvider.initChannel(com.google.firebase:firebase-firestore##21.4.3:113)
at com.google.firebase.firestore.remote.GrpcCallProvider.lambda$initChannelTask$6(com.google.firebase:firebase-firestore##21.4.3:256)
at com.google.firebase.firestore.remote.GrpcCallProvider$$Lambda$5.call(com.google.firebase:firebase-firestore##21.4.3)
at com.google.android.gms.tasks.zzv.run(Unknown Source)
at com.google.firebase.firestore.util.ThrottledForwardingExecutor.lambda$execute$0(com.google.firebase:firebase-firestore##21.4.3:54)
at com.google.firebase.firestore.util.ThrottledForwardingExecutor$$Lambda$1.run(com.google.firebase:firebase-firestore##21.4.3)
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.lang.ClassNotFoundException: Didn't find class "com.google.common.base.CharMatcher" on path: DexPathList[[zip file "/data/app/com.example.myapp-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at com.google.common.base.Splitter.on(Splitter.java:125) 
at io.grpc.internal.GrpcUtil.(GrpcUtil.java:203) 
at io.grpc.internal.AbstractManagedChannelImplBuilder.(AbstractManagedChannelImplBuilder.java:84) 
at io.grpc.okhttp.OkHttpChannelProvider.builderForTarget(OkHttpChannelProvider.java:48) 
at io.grpc.okhttp.OkHttpChannelProvider.builderForTarget(OkHttpChannelProvider.java:27) 
at io.grpc.ManagedChannelBuilder.forTarget(ManagedChannelBuilder.java:73) 
at com.google.firebase.firestore.remote.GrpcCallProvider.initChannel(com.google.firebase:firebase-firestore##21.4.3:113) 
at com.google.firebase.firestore.remote.GrpcCallProvider.lambda$initChannelTask$6(com.google.firebase:firebase-firestore##21.4.3:256) 
at com.google.firebase.firestore.remote.GrpcCallProvider$$Lambda$5.call(com.google.firebase:firebase-firestore##21.4.3) 
at com.google.android.gms.tasks.zzv.run(Unknown Source) 
at com.google.firebase.firestore.util.ThrottledForwardingExecutor.lambda$execute$0(com.google.firebase:firebase-firestore##21.4.3:54) 
at com.google.firebase.firestore.util.ThrottledForwardingExecutor$$Lambda$1.run(com.google.firebase:firebase-firestore##21.4.3) 
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) 
Suppressed: java.lang.NoClassDefFoundError: com.google.common.base.CharMatcher
at dalvik.system.DexFile.defineClassNative(Native Method)
at dalvik.system.DexFile.defineClass(DexFile.java:226)
at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:219)
at dalvik.system.DexPathList.findClass(DexPathList.java:321)
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:54)
... 17 more
Suppressed: java.lang.ClassNotFoundException: com.google.common.base.CharMatcher
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:504)
... 16 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
I got the solution. After pasting this line of code in apps > Build.gradle file it worked fined.
Here is the code:
implementation group: 'com.google.guava', name: 'guava', version: '28.1-android'

java.lang.NoClassDefFoundError: Failed resolution of: Landroid/telephony/data/ApnSetting$Builder;

I'm trying to create a mobile application to add APN(Access Point Network) into mobile application. Then I used ApnSetting.Builder() according to the android documentation
I implemented it as following in MainActivity class:
package com.example.myapplication;
import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
import android.content.Context;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.telephony.data.ApnSetting;
import android.util.Log;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import java.net.InetAddress;
import java.net.UnknownHostException;
public class MainActivity extends AppCompatActivity {
private static String TAG = "MainActivity";
#RequiresApi(api = Build.VERSION_CODES.P)
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Create an MMS proxy address with a hostname. A network might not be
// available, so supply a dummy (0.0.0.0) IPv4 address to avoid DNS lookup.
String host = "mms.example.com";
byte[] ipAddress = new byte[4];
InetAddress mmsProxy;
try {
mmsProxy = InetAddress.getByAddress(host, ipAddress);
} catch (UnknownHostException e) {
e.printStackTrace();
return;
}
ApnSetting apn = new ApnSetting.Builder()
.setApnTypeBitmask(ApnSetting.TYPE_DEFAULT | ApnSetting.TYPE_MMS)
.setApnName("apn.example.com")
.setEntryName("Example Carrier APN")
.setMmsc(Uri.parse("http://mms.example.com:8002"))
.setMmsProxyAddress(mmsProxy)
.setMmsProxyPort(8799)
.build();
ComponentName name = new ComponentName(getApplicationContext(), MainActivity.class);
DevicePolicyManager devicePolicyManager = (DevicePolicyManager) getApplicationContext().getSystemService(Context.DEVICE_POLICY_SERVICE);
devicePolicyManager.addOverrideApn(name, apn);
}
}
But it is showing the following error:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.myapplication, PID: 4314
java.lang.NoClassDefFoundError: Failed resolution of: Landroid/telephony/data/ApnSetting$Builder;
at com.example.myapplication.MainActivity.onCreate(MainActivity.java:42)
at android.app.Activity.performCreate(Activity.java:6609)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1134)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3113)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3275)
at android.app.ActivityThread.access$1000(ActivityThread.java:218)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1744)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:7007)
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:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.telephony.data.ApnSetting$Builder" on path: DexPathList[[zip file "/data/app/com.example.myapplication-2/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at com.example.myapplication.MainActivity.onCreate(MainActivity.java:42) 
at android.app.Activity.performCreate(Activity.java:6609) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1134) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3113) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3275) 
at android.app.ActivityThread.access$1000(ActivityThread.java:218) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1744) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:145) 
at android.app.ActivityThread.main(ActivityThread.java:7007) 
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:1404) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199) 
Suppressed: java.lang.ClassNotFoundException: android.telephony.data.ApnSetting$Builder
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:504)
... 15 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
So what should I do for that?
The ApnSetting has added in API level 28 means below API level 28 don't have that method ApnSetting.Builder(). That's why it's not working and causing ClassNotFoundException in Android API level < 28.
Option - 1:
If you really want to use this API and don't need to support older
devices just set the minSdkVersion to 28 in your build.gradle or
AndroidManifest.xml
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
...
minSdkVersion 28 // this is important
targetSdkVersion 29
...
}
}
Option - 2:
If your code is deliberately accessing newer APIs, and you have
ensured (e.g. with conditional execution) that this code will only
ever be called on a supported platform, then you can annotate your
class or method with the #TargetApi annotation specifying the local
minimum SDK to apply, such as #TargetApi(28), such that this check
considers 28 rather than your manifest file's minimum SDK as the
required API level.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
...
ApnSetting apn = new ApnSetting.Builder()
...
}

Cannot load class from .aar file when i added Room persistence library into my library

I am currently developing an alarm library, that needs to store multiple alarm details in sqlite database.
So I used google's Room persistence library, with my alarm library.
I have added below code to build.gradle.
implementation 'android.arch.persistence.room:runtime:1.1.1'
annotationProcessor 'android.arch.persistence.room:compiler:1.1.1'
I have added database class
#Database(entities = AlarmDetails.class, version = 1)
public abstract class AlarmDatabase extends RoomDatabase {
public abstract AlarmDao alarmDao();
}
I have also added Data Access Object
#Dao
public interface AlarmDao {
#Insert(onConflict = OnConflictStrategy.REPLACE)
void insert(AlarmDetails alarmDetails);
#Update
void update(AlarmDetails alarmDetails);
#Delete
void delete(AlarmDetails alarmDetails);
#Query("SELECT * FROM alarms")
List<AlarmDetails> getAll();
}
I am creating a database instance in the main class of my library as below
/*Constructor*/
public AlarmBase(Context mcontext,Context ncontext) {
this.mContext = mcontext;
alarmDatabase= Room.databaseBuilder(ncontext,
AlarmDatabase.class, "alarm_db")
.build();
}
i am calling the above constructor from my demo project and passing application context as below
Context applicationContext=MyApplicationClass.getContext();
alarmBase = new AlarmBase(this,applicationContext);
And this is my application class
public class MyApplicationClass extends MultiDexApplication {
private static MultiDexApplication instance;
#Override
public void onCreate() {
super.onCreate();
instance = this;
}
public static Context getContext() {
return instance.getApplicationContext();
}
}
But when I run the project I get the below error
--------- beginning of crash
02-21 20:23:34.643 11930-11930/com.mid.alarmdemo E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.mid.alarmdemo, PID: 11930
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/mid/alarmlib/roomsqlite/AlarmDatabase;
at com.mid.alarmlib.AlarmBase.<init>(AlarmBase.java:39)
at com.mid.alarmdemo.MainActivity.onCreate(MainActivity.java:54)
at android.app.Activity.performCreate(Activity.java:6362)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2441)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2548)
at android.app.ActivityThread.access$1100(ActivityThread.java:154)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1399)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5613)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:774)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:652)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.mid.alarmlib.roomsqlite.AlarmDatabase" on path: DexPathList[[zip file "/data/app/com.mid.alarmdemo-1/base.apk"],nativeLibraryDirectories=[/data/app/com.mid.alarmdemo-1/lib/arm64, /vendor/lib64, /system/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at com.mid.alarmlib.AlarmBase.<init>(AlarmBase.java:39) 
at com.mid.alarmdemo.MainActivity.onCreate(MainActivity.java:54) 
at android.app.Activity.performCreate(Activity.java:6362) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2441) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2548) 
at android.app.ActivityThread.access$1100(ActivityThread.java:154) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1399) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:157) 
at android.app.ActivityThread.main(ActivityThread.java:5613) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:774) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:652) 
Suppressed: java.lang.NoClassDefFoundError: com.mid.alarmlib.roomsqlite.AlarmDatabase
at dalvik.system.DexFile.defineClassNative(Native Method)
at dalvik.system.DexFile.defineClass(DexFile.java:226)
at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:219)
at dalvik.system.DexPathList.findClass(DexPathList.java:338)
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:54)
... 16 more
Suppressed: java.lang.ClassNotFoundException: com.mid.alarmlib.roomsqlite.AlarmDatabase
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:504)
... 15 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
I was able to run the project along with my library until I added Room persistence to my library
I just added below lines to the build.gradle(Module app) of the project also,
implementation 'android.arch.persistence.room:runtime:1.1.1'
annotationProcessor 'android.arch.persistence.room:compiler:1.1.1'
and it worked fine

Passing Object in Bundle - ClassNotFoundException

I have a problem passing a custom class to another activity resulting in a Activity Manager crash. I have a class like this:
public class MyClass implements Serializable/Parcelable {
public final String a;
public final Long b;
public final Boolean c;
}
Intent intent = new Intent(getActivity(), TargetActivity.class);
Bundle parameter = new Bundle();
parameter.putParcelable(TargetActivity.DATA_KEY, instance_of_my_class);
startActivity(intent, parameter);
I have tried both Serializable as well as Parcelable and both ways fail with the same problem: ClassNotFoundException.
There are some older discussions about this where setClassLoader and setExtrasClassLoader are recommended, unfortunately it does not work. For example I have tried parameter.setClassLoader(getClass().getClassLoader()); the result was the same.
Anyone knows the solution? Is it possible that a third party library has an influence on this? (I have EventBus in the project)
The stack trace in the Parcelable case looks like this:
08-23 14:40:37.086 1487-1783/system_process E/Parcel: Class not found when unmarshalling: com.example.MyClass
java.lang.ClassNotFoundException: com.example.MyClass
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:309)
at java.lang.Class.forName(Class.java:273)
at android.os.Parcel.readParcelableCreator(Parcel.java:2281)
at android.os.Parcel.readParcelable(Parcel.java:2245)
at android.os.Parcel.readValue(Parcel.java:2152)
at android.os.Parcel.readArrayMapInternal(Parcel.java:2485)
at android.os.BaseBundle.unparcel(BaseBundle.java:221)
at android.os.BaseBundle.getString(BaseBundle.java:918)
at android.app.ActivityOptions.<init>(ActivityOptions.java:570)
at com.android.server.am.ActivityRecord.<init>(ActivityRecord.java:417)
at com.android.server.am.ActivityStackSupervisor.startActivityLocked(ActivityStackSupervisor.java:1482)
at com.android.server.am.ActivityStackSupervisor.startActivityMayWait(ActivityStackSupervisor.java:951)
at com.android.server.am.ActivityManagerService.startActivityAsUser(ActivityManagerService.java:3369)
at com.android.server.am.ActivityManagerService.startActivity(ActivityManagerService.java:3356)
at android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:139)
at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2208)
at android.os.Binder.execTransact(Binder.java:446)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.MyClass" on path: DexPathList[[directory "."],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at java.lang.Class.classForName(Native Method) 
at java.lang.Class.forName(Class.java:309) 
at java.lang.Class.forName(Class.java:273) 
at android.os.Parcel.readParcelableCreator(Parcel.java:2281) 
at android.os.Parcel.readParcelable(Parcel.java:2245) 
at android.os.Parcel.readValue(Parcel.java:2152) 
at android.os.Parcel.readArrayMapInternal(Parcel.java:2485) 
at android.os.BaseBundle.unparcel(BaseBundle.java:221) 
at android.os.BaseBundle.getString(BaseBundle.java:918) 
at android.app.ActivityOptions.<init>(ActivityOptions.java:570) 
at com.android.server.am.ActivityRecord.<init>(ActivityRecord.java:417) 
at com.android.server.am.ActivityStackSupervisor.startActivityLocked(ActivityStackSupervisor.java:1482) 
at com.android.server.am.ActivityStackSupervisor.startActivityMayWait(ActivityStackSupervisor.java:951) 
at com.android.server.am.ActivityManagerService.startActivityAsUser(ActivityManagerService.java:3369) 
at com.android.server.am.ActivityManagerService.startActivity(ActivityManagerService.java:3356) 
at android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:139) 
at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2208) 
at android.os.Binder.execTransact(Binder.java:446) 
Suppressed: java.lang.ClassNotFoundException: com.example.MyClass
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:504)
... 19 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
Classes implementing the Parcelable interface must also have a non-null static field called CREATOR of a type that implements the Parcelable.Creator interface.
Ref: https://developer.android.com/reference/android/os/Parcelable.html
To make that in a easy way try to find plugins which will handle parcelable creation.
Example:
https://github.com/mcharmas/android-parcelable-intellij-plugin

Cloudmine java.lang.NoClassDefFoundError: Failed resolution of: Lorg/slf4j/LoggerFactory;

I am trying to store some data using Cloudmine.
However, I got the error java.lang.NoClassDefFoundError: Failed resolution of: Lorg/slf4j/LoggerFactory; when I call initialize() for authorization.
I'm not running on a separate thread or something. I'm testing stuff out right now so I just have it so that when a button is clicked, it uploads some information from some EditText fields.
This is my code
public class ButtonClick implements View.OnClickListener {
private MainWindowActivity mainWindowActivity;
public ButtonClick(MainWindowActivity mainWindowActivity, Button doneBtn, Button addBtn) {
this.mainWindowActivity = mainWindowActivity;
addBtn.setEnabled(true);
addBtn.setOnClickListener(this);
}
#Override
public void onClick(View v) {
// This will initialize your credentials
// ERROR HERE
CMApiCredentials initialize = CMApiCredentials.initialize("id", "key");
SimpleCMObject location = new SimpleCMObject();
location.add("address", Runner.getAddressStr());
location.add("city", Runner.getCityStr());
location.add("state", Runner.getStateStr());
location.add("zip", Runner.getZipStr());
location.save(new ObjectModificationResponseCallback() {
public void onCompletion(ObjectModificationResponse response) {
Toast.makeText(mainWindowActivity, "Location saved: " + response.wasSuccess(), Toast.LENGTH_SHORT).show();
}
});
EditText address = (EditText) mainWindowActivity.findViewById(R.id.address);
address.setText("");
EditText city = (EditText) mainWindowActivity.findViewById(R.id.city);
city.setText("");
EditText state = (EditText) mainWindowActivity.findViewById(R.id.state);
state.setText("");
EditText zip = (EditText) mainWindowActivity.findViewById(R.id.zip);
zip.setText("");
}
}
This is the Logcat:
Process: prog, PID: 26580
java.lang.NoClassDefFoundError: Failed resolution of: Lorg/slf4j/LoggerFactory;
at com.cloudmine.api.CMApiCredentials.<clinit>(CMApiCredentials.java:21)
at prog.ButtonClick.onClick(ButtonClick.java:52)
at android.view.View.performClick(View.java:4780)
at android.view.View$PerformClick.run(View.java:19866)
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:5257)
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.ClassNotFoundException: Didn't find class "org.slf4j.LoggerFactory" on path: DexPathList[[zip file "/data/app/prog-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
            at com.cloudmine.api.CMApiCredentials.<clinit>(CMApiCredentials.java:21)
            at prog.ButtonClick.onClick(ButtonClick.java:52)
            at android.view.View.performClick(View.java:4780)
            at android.view.View$PerformClick.run(View.java:19866)
            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:5257)
            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)
Suppressed: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
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:504)
... 13 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
As I have commented, download zip file from SLF4J distribution and use as library in your project. Then, use slf4j-api-1.7.12.jar (and slf4j-android-1.7.12.jar if needed).
I had the same error and found this solution on github.
Just add the following to your grandle:
implementation 'org.slf4j:slf4j-api:1.7.25'
https://github.com/nomis/slf4j-android
I hade the same problem only on Android 5.0 - 5.1 (a real device and emulators). At that moment, I used Android Studio 2.3.3 and build tools v26.
I solved the problem turning off Instant Run that I didn't use anyway.
Steps:
go to File -> Settings -> Build, Execution, Deployment -> Instant run
Disable it (first checkbox).

Categories

Resources