Caused by io.realm.exceptions.RealmMigrationNeededException android - android

I am getting following exception while user is upgrading from 1 to 3 db schema
Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{SplashActivity}: io.realm.exceptions.RealmMigrationNeededException: Realm on disk need to migrate from v1 to v3
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2924)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2985)
at android.app.ActivityThread.-wrap14(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1635)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6692)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)
Caused by io.realm.exceptions.RealmMigrationNeededException: Realm on disk need to migrate from v1 to v3
at io.realm.Realm.createAndValidateFromCache(Realm.java:389)
at io.realm.Realm.createInstance(Realm.java:364)
at io.realm.RealmCache.doCreateRealmOrGetFromCache(RealmCache.java:346)
at io.realm.RealmCache.createRealmOrGetFromCache(RealmCache.java:284)
at io.realm.Realm.getDefaultInstance(Realm.java:273)
at android.app.Activity.performCreate(Activity.java:6912)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2877)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2985)
at android.app.ActivityThread.-wrap14(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1635)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6692)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)**
Realm configuration is as follows:
RealmConfiguration realmConfiguration = new RealmConfiguration.Builder()
.name(AppConstants.DB_NAME)
.schemaVersion(schemaVersion)
.build();
try {
Realm.migrateRealm(realmConfiguration, new DBMigration()));
} catch (Exception ignored) {
// If the Realm file doesn't exist, just ignore.
}
Realm.setDefaultConfiguration(realmConfiguration);
I have specified DB migrations in code in which i have mentioned all DB changes.
I am using realm version 3.3.0
Can you please help in resolving this issue
Thanks in advance.

Related

Can't Generate Certificate Exception When Generating Key Pair In API 21

I've been trying to solve this exception that only happens in Android Lollipop (API 21). I tried to look for other solutions but the only one related is Generate KeyPair with KeyPairGeneratorSpec on API < 23 and the suggested solution didn't work.
Am I missing anything? Thanks!
Here's my code that's throwing at the last line:
Calendar start = Calendar.getInstance();
Calendar end = Calendar.getInstance();
end.add(Calendar.YEAR, 30);
KeyPairGeneratorSpec spec = new KeyPairGeneratorSpec.Builder(appContext)
.setAlias(getSecureSettingsKeyAlias())
.setSubject(new X500Principal("CN=" + getSecureSettingsKeyAlias()))
.setSerialNumber(BigInteger.TEN)
.setStartDate(start.getTime())
.setEndDate(end.getTime())
.build();
KeyPairGenerator kpg = KeyPairGenerator.getInstance(KeyProperties.KEY_ALGORITHM_RSA, AndroidKeyStore);
kpg.initialize(spec);
kpg.generateKeyPair();
Here's the exception that's happening:
Caused by: java.lang.IllegalStateException: Can't generate certificate
at android.security.AndroidKeyPairGenerator.generateKeyPair(AndroidKeyPairGenerator.java:136)
at java.security.KeyPairGenerator$KeyPairGeneratorImpl.generateKeyPair(KeyPairGenerator.java:276)
at com.sampleid.sampleid_sdk.common.FileSettingsStorage.getKeystore(FileSettingsStorage.java:302)
at com.sampleid.sampleid_sdk.common.FileSettingsStorage.writeSecureSettings(FileSettingsStorage.java:185)
at com.sampleid.sampleid_sdk.common.SettingsImpl.saveSecureSettings(SettingsImpl.java:473)
at com.sampleid.sampleid_sdk.common.SettingsImpl.saveSettings(SettingsImpl.java:321)
at com.sampleid.sampleid_sdk.sampleIDService.saveSettingsToStorage(sampleIDService.java:102)
at com.sampleid.sampleid_sdk.sampleIDService.saveSettings(sampleIDService.java:91)
at com.sampleid.sampleid.features.shared.BaseActivity.onStop(BaseActivity.java:182)
at android.app.Instrumentation.callActivityOnStop(Instrumentation.java:1261)
at android.app.Activity.performStop(Activity.java:6089)
at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:3341)
at android.app.ActivityThread.handleStopActivity(ActivityThread.java:3390)
at android.app.ActivityThread.access$1100(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1307)
at android.os.Handler.dispatchMessage(Handler.java:102)
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: java.lang.UnsupportedOperationException: private exponent cannot be extracted
at com.android.org.conscrypt.OpenSSLRSAPrivateKey.getPrivateExponent(OpenSSLRSAPrivateKey.java:161)
at org.spongycastle.jcajce.provider.asymmetric.rsa.RSAUtil.generatePrivateKeyParameter(RSAUtil.java:63)
at org.spongycastle.jcajce.provider.asymmetric.rsa.DigestSignatureSpi.engineInitSign(DigestSignatureSpi.java:95)
at java.security.Signature$SignatureImpl.engineInitSign(Signature.java:679)
at java.security.Signature.initSign(Signature.java:330)
at com.android.org.bouncycastle.x509.X509Util.calculateSignature(X509Util.java:243)
at com.android.org.bouncycastle.x509.X509V3CertificateGenerator.generate(X509V3CertificateGenerator.java:434)
at com.android.org.bouncycastle.x509.X509V3CertificateGenerator.generate(X509V3CertificateGenerator.java:412)
at android.security.AndroidKeyPairGenerator.generateKeyPair(AndroidKeyPairGenerator.java:133)
at java.security.KeyPairGenerator$KeyPairGeneratorImpl.generateKeyPair(KeyPairGenerator.java:276)
at com.sampleid.sampleid_sdk.common.FileSettingsStorage.getKeystore(FileSettingsStorage.java:302)
at com.sampleid.sampleid_sdk.common.FileSettingsStorage.writeSecureSettings(FileSettingsStorage.java:185)
at com.sampleid.sampleid_sdk.common.SettingsImpl.saveSecureSettings(SettingsImpl.java:473)
at com.sampleid.sampleid_sdk.common.SettingsImpl.saveSettings(SettingsImpl.java:321)
at com.sampleid.sampleid_sdk.sampleIDService.saveSettingsToStorage(sampleIDService.java:102)
at com.sampleid.sampleid_sdk.sampleIDService.saveSettings(sampleIDService.java:91)
at com.sampleid.sampleid.features.shared.BaseActivity.onStop(BaseActivity.java:182)
at android.app.Instrumentation.callActivityOnStop(Instrumentation.java:1261)
at android.app.Activity.performStop(Activity.java:6089)
at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:3341)
at android.app.ActivityThread.handleStopActivity(ActivityThread.java:3390)
at android.app.ActivityThread.access$1100(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1307)
at android.os.Handler.dispatchMessage(Handler.java:102)
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)
Was finally able to solve this. The issue is with the following:
KeyPairGenerator kpg = KeyPairGenerator.getInstance(KeyProperties.KEY_ALGORITHM_RSA, AndroidKeyStore);
KeyProperties.KEY_ALGORITHM_RSA is only available starting API 23, so it fails in APIs before that. Replace it with "RSA"
Also, if you're using SpongyCastle, it should be added using the following approach:
static {
// as per https://github.com/rtyley/spongycastle/issues/27
Security.addProvider(new org.spongycastle.jce.provider.BouncyCastleProvider());
}

android.content.res.Resources android.content.Context.getResources() error when using github repository

I am using https://github.com/BlacKCaT27/CurrencyEditText to enter currency into my application and I am using this code:
CurrencyEditText cet = new CurrencyEditText(this, null);
Here is the logcat:
Process: com.dharquissandas.budget, PID: 17620
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.dharquissandas.budget/com.dharquissandas.budget.add_expense}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResources()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2819)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2988)
at android.app.ActivityThread.-wrap14(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1631)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6682)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResources()' on a null object reference
at android.content.ContextWrapper.getResources(ContextWrapper.java:86)
at android.view.ContextThemeWrapper.getResourcesInternal(ContextThemeWrapper.java:127)
at android.view.ContextThemeWrapper.getResources(ContextThemeWrapper.java:121)
at android.support.v7.app.AppCompatActivity.getResources(AppCompatActivity.java:542)
at android.view.View.<init>(View.java:4306)
at android.view.View.<init>(View.java:4454)
at android.widget.TextView.<init>(TextView.java:995)
at android.widget.EditText.<init>(EditText.java:79)
at android.widget.EditText.<init>(EditText.java:75)
at android.widget.EditText.<init>(EditText.java:71)
at com.blackcat.currencyedittext.CurrencyEditText.<init>(CurrencyEditText.java:33)
at com.dharquissandas.budget.add_expense.<init>(add_expense.java:29)
at java.lang.Class.newInstance(Native Method)
at android.app.Instrumentation.newActivity(Instrumentation.java:1086)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2809)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2988) 
at android.app.ActivityThread.-wrap14(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1631) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6682) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410) 
What am I doing wrong I don't know, I am fairly new to android programming can someone help me out. What am I supposed to put in the attribute part of the code?
Here is my code: https://pastebin.com/57mTUMWX
You should not be creating view elements in your Code.
Add the view for CurrencyText to your XML.
Then you make sure it has an #+id/myName and find it by doing
CurrencyText myText = findViewById(R.id.myName);

kotlin android - Xposed IllegalArgumentException 'android.content.res.CoollifeUITpedArray'

How to solve this error
Xposed: java.lang.IllegalArgumentException: Cannot transfer object from class android.content.res.CoollifeUITypedArray to class android.content.res.XResources$XTypedArray
E/Xposed: java.lang.IllegalArgumentException: Cannot transfer object from class android.content.res.CoollifeUITypedArray to class android.content.res.XResources$XTypedArray
at de.robv.android.xposed.XposedBridge.setObjectClass(XposedBridge.java:468)
at de.robv.android.xposed.XposedInit$10.afterHookedMethod(XposedInit.java:353)
at de.robv.android.xposed.XposedBridge.handleHookedMethod(XposedBridge.java:348)
at android.content.res.TypedArray.<init>(<Xposed>)
at android.content.res.CoollifeUITypedArray.<init>(CoollifeUITypedArray.java:14)
at android.content.res.TypedArray.obtain(TypedArray.java:66)
at android.content.res.Resources$Theme.obtainStyledAttributes(Resources.java:1838)
at android.content.Context.obtainStyledAttributes(Context.java:537)
at android.transition.Transition.<init>(Transition.java:270)
at android.transition.TransitionSet.<init>(TransitionSet.java:85)
at android.transition.TransitionInflater.createTransitionFromXml(TransitionInflater.java:169)
at android.transition.TransitionInflater.inflateTransition(TransitionInflater.java:79)
at com.android.internal.policy.PhoneWindow.getTransition(PhoneWindow.java:4237)
at com.android.internal.policy.PhoneWindow.installDecor(PhoneWindow.java:4198)
at com.android.internal.policy.PhoneWindow.getDecorView(PhoneWindow.java:2031)
at android.support.v7.app.AppCompatDelegateImplV9.createSubDecor(AppCompatDelegateImplV9.java:379)
at android.support.v7.app.AppCompatDelegateImplV9.ensureSubDecor(AppCompatDelegateImplV9.java:328)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:289)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.info.edudharma.activities.Activity_Main.onCreate(Activity_Main.java:125)
at android.app.Activity.performCreate(Activity.java:6309)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1114)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2537)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2672)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1495)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5769)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:861)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:751)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:102)

InvocationTargetException : Could not execute method of the activity

I am new in Android and I want to put Click event on XML instead of java, and I have implemented following method on Activity class
public void onInfoClick(View v){
switch(v.getId()) {
case R.id.ivAcceptAmericanExpress:
showPopup(v, getString(R.string.apt_american_express));
break;
}
}
and in XML , I have done following code
<ImageView
android:id="#+id/ivAcceptAmericanExpress"
android:layout_width="24.286dp"
android:layout_height="24.286dp"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:layout_toRightOf="#id/txtAcceptAmericanExpress"
android:src="#drawable/info_image"
android:onClick="onInfoClick" />
but when I click on Image I am getting following error
Could not execute method of the activity
android.view.View$1.onClick(View.java:4021)
android.view.View.performClick(View.java:4781)
android.view.View$PerformClick.run(View.java:19873)
android.os.Handler.handleCallback(Handler.java:739)
android.os.Handler.dispatchMessage(Handler.java:95)
android.os.Looper.loop(Looper.java:135)
android.app.ActivityThread.main(ActivityThread.java:5291)
java.lang.reflect.Method.invoke(Native Method)
java.lang.reflect.Method.invoke(Method.java:372)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699):: Cause : java.lang.reflect.InvocationTargetException
java.lang.reflect.Method.invoke(Native Method)
java.lang.reflect.Method.invoke(Method.java:372)
android.view.View$1.onClick(View.java:4016)
android.view.View.performClick(View.java:4781)
android.view.View$PerformClick.run(View.java:19873)
android.os.Handler.handleCallback(Handler.java:739)
android.os.Handler.dispatchMessage(Handler.java:95)
android.os.Looper.loop(Looper.java:135)
android.app.ActivityThread.main(ActivityThread.java:5291)
java.lang.reflect.Method.invoke(Native Method)
java.lang.reflect.Method.invoke(Method.java:372)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
The InvocationTargetException usually points to an exception in the onClick method which you are trying to execute - in your case the onInfoClick method - you can confirm this by commenting out your case-statement and see if you still get the error. Once you have identified the problem - you can make the necessary changes to resolve the exception. You should probably surround the body of the method with a try-catch to be safe.

ParseTwitterUtils initialize throws NullPointerException

I am getting a NullPointerException from calling
ParseTwitterUtils.initialize(TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET);
Here is the stack trace
java.lang.RuntimeException: Unable to create application com.myapp.app.android.Application: java.lang.NullPointerException: Attempt to invoke virtual method 'java.io.File com.parse.ParsePlugins.getParseDir()' on a null object reference
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5015)
at android.app.ActivityThread.access$1600(ActivityThread.java:172)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1482)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5837)
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:1388)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1183)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.io.File com.parse.ParsePlugins.getParseDir()' on a null object reference
at com.parse.Parse.getParseDir(Parse.java:313)
at com.parse.ParseCorePlugins.getCurrentUserController(ParseCorePlugins.java:124)
at com.parse.ParseUser.getCurrentUserController(ParseUser.java:56)
at com.parse.ParseUser.getCurrentUser(ParseUser.java:892)
at com.parse.ParseUser.getCurrentUser(ParseUser.java:879)
at com.parse.ParseUser.registerAuthenticationProvider(ParseUser.java:1125)
at com.parse.ParseTwitterUtils.getAuthenticationProvider(ParseTwitterUtils.java:20)
at com.parse.ParseTwitterUtils.initialize(ParseTwitterUtils.java:50)
at com.myapp.app.android.Application.onCreate(Application.java:42)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1020)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5012)
            at android.app.ActivityThread.access$1600(ActivityThread.java:172)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1482)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:145)
            at android.app.ActivityThread.main(ActivityThread.java:5837)
            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:1388)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1183)
My app used to work before I added the line ParseTwitterUtils.initialize(...). Here is the onCreate method of my Application class
public void onCreate(){
super.onCreate();
registerDatabaseTables();
ParseTwitterUtils.initialize(TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET);
Parse.enableLocalDatastore(this);
Parse.initialize(this, PARSE_APPLICATION_ID, PARSE_CLIENT_KEY);
}
Unfortunately the instructions on parse.com do not say this, but you have to initialize Parse before you initialize Twitter. This is not obvious since you are required to do so much before you initialize parse. So anyway change your code to this:
public void onCreate(){
super.onCreate();
registerDatabaseTables();
Parse.enableLocalDatastore(this);
Parse.initialize(this, PARSE_APPLICATION_ID, PARSE_CLIENT_KEY);
ParseTwitterUtils.initialize(TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET);
}

Categories

Resources