Reputation: 6035
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
Upvotes: 4
Views: 892
Reputation: 31
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.
Upvotes: 3
Reputation: 26
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.* { *; }
Upvotes: 0
Reputation: 13358
In kotlin get userType like this
val userType=CurrentUser.getInstance().userType
Upvotes: 0