3

how I'll be able to get data from Singleton class of java in kotlin class.? since my project is an old project and whole app is in java now I'm implementing its new module in kotlin where I'm using Java's Singleton (CurrentUser.java) in kotlin's Service Class(UpdateWidgetService.kt).while I'm using this CurrentUser.getInstance().userType code for getting type of user in My service class its throwing below exception

Process: com.example.myapp, PID: 27066
    java.lang.NoClassDefFoundError: Failed resolution of: Lcom/myapp/main/CurrentUser

Java

   public class CurrentUser {

          String userType = "";

     private static CurrentUser instance;

      public static CurrentUser getInstance() {
            if (instance == null) {
                instance = new CurrentUser();
            }
            return instance;
        }

        public void setUserType(String userType) {
            this.userType = userType;
        }

        public String getUserType() {
            return userType ;
        }



    }

Kotlin

CurrentUser.getInstance().userType
Atif AbbAsi
  • 5,633
  • 7
  • 26
  • 47

3 Answers3

2

Rebuild and invalidate cache your project and then restart your android studio. Also Sync file system. I was having the same issue and i did this trick and it worked for me. Hope this may helps you.

0

In kotlin get userType like this

 val userType=CurrentUser.getInstance().userType
sasikumar
  • 12,540
  • 3
  • 28
  • 48
0

Would you mind to provide information if you are using ProGuard for minifying the Code?

If Yes Make sure u add the model class in your proguard-rules.pro file

exmp: -keep class packagename.models.* { *; }