Issue in creating a sample app for microstream in Android - android

I am trying to build a sample android app for microstream but getting the error.
Gradle Dependencies
dependencies {
implementation 'one.microstream:microstream-storage-embedded:05.00.02-MS-GA'
...
}
Error
Process: com.example.microstream, PID: 6369
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.microstream/com.example.microstream.MainActivity}: one.microstream.persistence.exceptions.PersistenceException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: one.microstream.persistence.exceptions.PersistenceException
at one.microstream.persistence.internal.PersistenceTypeDictionaryFileHandler.writeTypeDictionary(PersistenceTypeDictionaryFileHandler.java:107)
at one.microstream.persistence.internal.PersistenceTypeDictionaryFileHandler.writeTypeDictionary(PersistenceTypeDictionaryFileHandler.java:203)
at one.microstream.persistence.internal.PersistenceTypeDictionaryFileHandler.storeTypeDictionary(PersistenceTypeDictionaryFileHandler.java:209)
at one.microstream.persistence.types.PersistenceTypeDictionaryExporter$Default.exportTypeDictionary(PersistenceTypeDictionaryExporter.java:93)
at one.microstream.persistence.types.PersistenceTypeDictionaryManager$Exporting.exportTypeDictionary(PersistenceTypeDictionaryManager.java:267)
at one.microstream.persistence.types.PersistenceTypeDictionaryManager$Exporting.synchUpdateExport(PersistenceTypeDictionaryManager.java:258)
at one.microstream.persistence.types.PersistenceTypeDictionaryManager$Exporting.registerRuntimeTypeDefinitions(PersistenceTypeDictionaryManager.java:324)
at one.microstream.persistence.types.PersistenceTypeHandlerManager$Default.synchUnvalidatedRegisterTypeHandlers(PersistenceTypeHandlerManager.java:662)
at one.microstream.persistence.types.PersistenceTypeHandlerManager$Default.registerTypeHandlers(PersistenceTypeHandlerManager.java:644)
at one.microstream.persistence.types.PersistenceTypeHandlerManager$Default.initialRegisterTypeHandlers(PersistenceTypeHandlerManager.java:687)
at one.microstream.persistence.types.PersistenceTypeHandlerManager$Default.synchInternalInitialize(PersistenceTypeHandlerManager.java:968)
at one.microstream.persistence.types.PersistenceTypeHandlerManager$Default.initialize(PersistenceTypeHandlerManager.java:941)
at one.microstream.storage.embedded.types.EmbeddedStorageFoundation$Default.createEmbeddedStorageManager(EmbeddedStorageFoundation.java:791)
at one.microstream.storage.embedded.types.EmbeddedStorage.createAndStartStorageManager(EmbeddedStorage.java:649)
at one.microstream.storage.embedded.types.EmbeddedStorage.start(EmbeddedStorage.java:467)
at one.microstream.storage.embedded.types.EmbeddedStorage.start(EmbeddedStorage.java:317)
at com.example.microstream.MainActivity.microstreamStorageManager(MainActivity.kt:52)
at com.example.microstream.MainActivity.checkPermission(MainActivity.kt:78)
at com.example.microstream.MainActivity.onCreate(MainActivity.kt:47)
at android.app.Activity.performCreate(Activity.java:7136)
at android.app.Activity.performCreate(Activity.java:7127)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048) 
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) 
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) 
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808) 
at android.os.Handler.dispatchMessage(Handler.java:106) 
at android.os.Looper.loop(Looper.java:193) 
at android.app.ActivityThread.main(ActivityThread.java:6669) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) 
Caused by: one.microstream.exceptions.IORuntimeException: java.nio.file.AccessDeniedException: storage/PersistenceTypeDictionary.ptd
2021-10-20 07:26:34.758 6369-6369/com.example.microstream E/AndroidRuntime: at one.microstream.afs.nio.types.NioIoHandler$Default.specificCreate(NioIoHandler.java:324)
at one.microstream.afs.nio.types.NioIoHandler$Default.specificCreate(NioIoHandler.java:1)
at one.microstream.afs.types.AIoHandler$Abstract.create(AIoHandler.java:701)
at one.microstream.afs.types.AWritableFile.create(AWritableFile.java:102)
at one.microstream.persistence.internal.PersistenceTypeDictionaryFileHandler.writeTypeDictionary(PersistenceTypeDictionaryFileHandler.java:91)
... 33 more
Caused by: java.nio.file.AccessDeniedException: storage/PersistenceTypeDictionary.ptd
at sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:214)
at java.nio.file.Files.newByteChannel(Files.java:361)
at java.nio.file.Files.createFile(Files.java:632)
at one.microstream.afs.nio.types.NioIoHandler$Default.specificCreate(NioIoHandler.java:320)
... 37 more
How to resolve this issue?

The problem is described in the log. You are trying to write to a location where the application cannot store data.
To get the path for writing data, you can use for example:
Context instrumentationContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
targetDirectory = instrumentationContext.getFilesDir().toPath();
targetDirectory = targetDirectory.resolve("storage");
targetDirectory.toFile().mkdir();
and after that:
EmbeddedStorageManager storage = EmbeddedStorage.start(root, targetDirectory);

Related

When choose Pick from gallery or camera options get error

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.m3h.pmne, PID: 19352
java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = com.m3h.pmne.ServerResponse.FormParentResponse)
at android.os.Parcel.writeSerializable(Parcel.java:1730)
at android.os.Parcel.writeValue(Parcel.java:1678)
at android.os.Parcel.writeArrayMapInternal(Parcel.java:891)
at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1579)
at android.os.Bundle.writeToParcel(Bundle.java:1233)
at android.os.Parcel.writeBundle(Parcel.java:931)
at androidx.fragment.app.FragmentState.writeToParcel(FragmentState.java:125)
at android.os.Parcel.writeTypedObject(Parcel.java:1532)
at android.os.Parcel.writeTypedList(Parcel.java:1411)
at android.os.Parcel.writeTypedList(Parcel.java:1396)
at androidx.fragment.app.FragmentManagerState.writeToParcel(FragmentManagerState.java:58)
at android.os.Parcel.writeParcelable(Parcel.java:1699)
at android.os.Parcel.writeValue(Parcel.java:1605)
at android.os.Parcel.writeArrayMapInternal(Parcel.java:891)
at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1579)
at android.os.Bundle.writeToParcel(Bundle.java:1233)
at android.os.Parcel.writeBundle(Parcel.java:931)
at android.os.Parcel.writeValue(Parcel.java:1596)
at android.os.Parcel.writeArrayMapInternal(Parcel.java:891)
at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1579)
at android.os.Bundle.writeToParcel(Bundle.java:1233)
at android.os.Parcel.writeBundle(Parcel.java:931)
at android.os.Parcel.writeValue(Parcel.java:1596)
at android.os.Parcel.writeArrayMapInternal(Parcel.java:891)
at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1579)
at android.os.Bundle.writeToParcel(Bundle.java:1233)
at android.app.IActivityManager$Stub$Proxy.activityStopped(IActivityManager.java:3858)
at android.app.servertransaction.PendingTransactionActions$StopInfo.run(PendingTransactionActions.java:144)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7156)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:975)
Caused by: java.io.NotSerializableException: com.m3h.pmne.ServerResponse.Data
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1240)
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1604)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1565)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1488)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1234)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:354)
at android.os.Parcel.writeSerializable(Parcel.java:1725)
at android.os.Parcel.writeValue(Parcel.java:1678) 
at android.os.Parcel.writeArrayMapInternal(Parcel.java:891) 
at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1579) 
at android.os.Bundle.writeToParcel(Bundle.java:1233) 
at android.os.Parcel.writeBundle(Parcel.java:931) 
at androidx.fragment.app.FragmentState.writeToParcel(FragmentState.java:125) 
at android.os.Parcel.writeTypedObject(Parcel.java:1532) 
at android.os.Parcel.writeTypedList(Parcel.java:1411) 
at android.os.Parcel.writeTypedList(Parcel.java:1396) 
at androidx.fragment.app.FragmentManagerState.writeToParcel(FragmentManagerState.java:58) 
at android.os.Parcel.writeParcelable(Parcel.java:1699) 
at android.os.Parcel.writeValue(Parcel.java:1605) 
at android.os.Parcel.writeArrayMapInternal(Parcel.java:891) 
at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1579) 
at android.os.Bundle.writeToParcel(Bundle.java:1233) 
at android.os.Parcel.writeBundle(Parcel.java:931) 
at android.os.Parcel.writeValue(Parcel.java:1596) 
at android.os.Parcel.writeArrayMapInternal(Parcel.java:891) 
at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1579) 
at android.os.Bundle.writeToParcel(Bundle.java:1233) 
at android.os.Parcel.writeBundle(Parcel.java:931) 
at android.os.Parcel.writeValue(Parcel.java:1596) 
at android.os.Parcel.writeArrayMapInternal(Parcel.java:891) 
at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1579) 
at android.os.Bundle.writeToParcel(Bundle.java:1233) 
at android.app.IActivityManager$Stub$Proxy.activityStopped(IActivityManager.java:3858) 
at android.app.servertransaction.PendingTransactionActions$StopInfo.run(PendingTransactionActions.java:144) 
at android.os.Handler.handleCallback(Handler.java:873) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loop(Looper.java:214) 
at android.app.ActivityThread.main(ActivityThread.java:7156) 
at java.lang.reflect.Method.invoke(Native Method) 

RuntimeException : when calling BillingClient function in in app purchase

private BillingClient billingClient = BillingClient.newBuilder(activity)
.setListener(purchasesUpdatedListener)
.enablePendingPurchases()
.build();
I am integrating billing google api for purchase but when I call this method, I get an error in place of activity.
The error is:
/AndroidRuntime: FATAL EXCEPTION: main
Process: com.xxxxx.xxxxx, PID: 9433
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.xxxxx.xxxx/com.xxxx.coins_history.activity.CoinsHistoryActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Context android.content.Context.getApplicationContext()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2876)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3081)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1831)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:201)
at android.app.ActivityThread.main(ActivityThread.java:6810)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Context android.content.Context.getApplicationContext()' on a null object reference
at android.content.ContextWrapper.getApplicationContext(ContextWrapper.java:126)
at com.android.billingclient.api.BillingClientImpl.initialize(com.android.billingclient:billing##4.0.0:1)
at com.android.billingclient.api.BillingClientImpl.<init>(com.android.billingclient:billing##4.0.0:4)
at com.android.billingclient.api.BillingClientImpl.<init>(com.android.billingclient:billing##4.0.0:9)
at com.android.billingclient.api.BillingClient$Builder.build(com.android.billingclient:billing##4.0.0:4)
at com.jetmedianetwork.coins_history.activity.CoinsHistoryActivity.<init>(CoinsHistoryActivity.java:133)
at java.lang.Class.newInstance(Native Method)
at android.app.AppComponentFactory.instantiateActivity(AppComponentFactory.java:69)
at androidx.core.app.CoreComponentFactory.instantiateActivity(CoreComponentFactory.java:45)
at android.app.Instrumentation.newActivity(Instrumentation.java:1216)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2864)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3081) 
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) 
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) 
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1831) 
at android.os.Handler.dispatchMessage(Handler.java:106) 
at android.os.Looper.loop(Looper.java:201) 
at android.app.ActivityThread.main(ActivityThread.java:6810) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873) 
E/FirebaseCrashlytics: Error handling uncaught exception
java.util.concurrent.TimeoutException
at com.google.firebase.crashlytics.internal.common.Utils.awaitEvenIfOnMainThread(Utils.java:122)
at com.google.firebase.crashlytics.internal.common.CrashlyticsController.handleUncaughtException(CrashlyticsController.java:231)
at com.google.firebase.crashlytics.internal.common.CrashlyticsController$1.onUncaughtException(CrashlyticsController.java:153)
at com.google.firebase.crashlytics.internal.common.CrashlyticsUncaughtExceptionHandler.uncaughtException(CrashlyticsUncaughtExceptionHandler.java:54)
at com.facebook.internal.instrument.crashreport.CrashHandler.uncaughtException(CrashHandler.java:65)
at org.chromium.base.JavaExceptionReporter.uncaughtException(chromium-Monochrome.aab-stable-432418123:6)
at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:1068)
at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:1063)
at java.lang.Thread.dispatchUncaughtException(Thread.java:1955)
I think the issue here is that there is a Null Pointer in your code since the billing client has not bee instantiated.
Try modifying the code as follows
private BillingClient billingClient = BillingClient!!.newBuilder(activity)
.setListener(purchasesUpdatedListener)
.enablePendingPurchases()
.build();

kotlin.Unit cannot be cast to "Class" Dagger 2 in Android Kotlin

I am developing an Android app using Kotlin. I am trying to understand how Dagger 2 works to perform dependency injection. I am very new to Dagger 2. I am following this tutorial,https://medium.com/#elye.project/dagger-2-for-dummies-in-kotlin-with-one-page-simple-code-project-618a5f9f2fe8 to understand how it works and applying it to my project too. But I am getting an error. Following is what I have done so far.
I created an interface called AppComponent with the following code
package com.example.utils
import com.example.memento.LoginActivity
import dagger.Component
#Component
interface AppComponent
{
fun inject(app: LoginActivity)
}
I also created a class called AuthService with the following code.
package com.example.services
import javax.inject.Inject
class AuthService #Inject constructor()
{
public fun login(): String
{
return "I am logged in";
}
}
This is my LoginActivity class
class LoginActivity : AppCompatActivity()
{
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_login)
val authService = DaggerAppComponent.create().inject(this) as AuthService
tv_testing.text = authService.login();
}
}
When I run my app, I get the following error
java.lang.ClassCastException: kotlin.Unit cannot be cast to com.example.services.AuthService
at com.example.memento.LoginActivity.onCreate(LoginActivity.kt:25)
at android.app.Activity.performCreate(Activity.java:7136)
at android.app.Activity.performCreate(Activity.java:7127)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at androidx.test.runner.MonitoringInstrumentation.callActivityOnCreate(MonitoringInstrumentation.java:674)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
E/MonitoringInstr: Exception encountered by: com.example.memento.LoginActivity#39cc00e. Dumping thread state to outputs and pining for the fjords.
java.lang.ClassCastException: kotlin.Unit cannot be cast to com.example.services.AuthService
at com.example.memento.LoginActivity.onCreate(LoginActivity.kt:25)
at android.app.Activity.performCreate(Activity.java:7136)
at android.app.Activity.performCreate(Activity.java:7127)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at androidx.test.runner.MonitoringInstrumentation.callActivityOnCreate(MonitoringInstrumentation.java:674)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
E/THREAD_STATE: Thread[MonitoringInstrumentation,5,main]
java.lang.Object.wait(Native Method)
android.app.Instrumentation.startActivitySync(Instrumentation.java:496)
android.app.Instrumentation.startActivitySync(Instrumentation.java:435)
androidx.test.runner.MonitoringInstrumentation.access$101(MonitoringInstrumentation.java:98)
androidx.test.runner.MonitoringInstrumentation$4.call(MonitoringInstrumentation.java:443)
androidx.test.runner.MonitoringInstrumentation$4.call(MonitoringInstrumentation.java:440)
java.util.concurrent.FutureTask.run(FutureTask.java:266)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
java.lang.Thread.run(Thread.java:764)
Thread[Binder:11719_2,5,main]
Thread[magnifier pixel copy result handler,5,main]
android.os.MessageQueue.nativePollOnce(Native Method)
android.os.MessageQueue.next(MessageQueue.java:326)
android.os.Looper.loop(Looper.java:160)
android.os.HandlerThread.run(HandlerThread.java:65)
Thread[FinalizerWatchdogDaemon,5,system]
java.lang.Object.wait(Native Method)
java.lang.Daemons$FinalizerWatchdogDaemon.sleepUntilNeeded(Daemons.java:297)
java.lang.Daemons$FinalizerWatchdogDaemon.runInternal(Daemons.java:277)
java.lang.Daemons$Daemon.run(Daemons.java:103)
java.lang.Thread.run(Thread.java:764)
Thread[InstrumentationConnectionThread,5,main]
android.os.MessageQueue.nativePollOnce(Native Method)
android.os.MessageQueue.next(MessageQueue.java:326)
android.os.Looper.loop(Looper.java:160)
android.os.HandlerThread.run(HandlerThread.java:65)
Thread[Profile Saver,5,system]
Thread[main,5,main]
dalvik.system.VMStack.getThreadStackTrace(Native Method)
java.lang.Thread.getStackTrace(Thread.java:1538)
java.lang.Thread.getAllStackTraces(Thread.java:1588)
androidx.test.runner.MonitoringInstrumentation.getThreadState(MonitoringInstrumentation.java:643)
androidx.test.runner.MonitoringInstrumentation.dumpThreadStateToOutputs(MonitoringInstrumentation.java:638)
androidx.test.runner.MonitoringInstrumentation.onException(MonitoringInstrumentation.java:632)
androidx.test.runner.AndroidJUnitRunner.onException(AndroidJUnitRunner.java:522)
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2910)
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
android.os.Handler.dispatchMessage(Handler.java:106)
android.os.Looper.loop(Looper.java:193)
android.app.ActivityThread.main(ActivityThread.java:6669)
java.lang.reflect.Method.invoke(Native Method)
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Thread[Binder:11719_1,5,main]
Thread[ReferenceQueueDaemon,5,system]
java.lang.Object.wait(Native Method)
java.lang.Daemons$ReferenceQueueDaemon.runInternal(Daemons.java:178)
java.lang.Daemons$Daemon.run(Daemons.java:103)
java.lang.Thread.run(Thread.java:764)
Thread[Jit thread pool worker thread 0,5,main]
Thread[FinalizerDaemon,5,system]
java.lang.Object.wait(Native Method)
java.lang.Object.wait(Object.java:422)
java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:188)
java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:209)
java.lang.Daemons$FinalizerDaemon.runInternal(Daemons.java:232)
java.lang.Daemons$Daemon.run(Daemons.java:103)
java.lang.Thread.run(Thread.java:764)
Thread[HeapTaskDaemon,5,system]
Thread[Instr: com.example.memento.MockTestRunner,5,main]
java.lang.Object.w
E/MonitoringInstr: Dying now...
D/AndroidRuntime: Shutting down VM
--------- beginning of crash
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.memento, PID: 11719
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.memento/com.example.memento.LoginActivity}: java.lang.ClassCastException: kotlin.Unit cannot be cast to com.example.services.AuthService
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.ClassCastException: kotlin.Unit cannot be cast to com.example.services.AuthService
at com.example.memento.LoginActivity.onCreate(LoginActivity.kt:25)
at android.app.Activity.performCreate(Activity.java:7136)
at android.app.Activity.performCreate(Activity.java:7127)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at androidx.test.runner.MonitoringInstrumentation.callActivityOnCreate(MonitoringInstrumentation.java:674)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048) 
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) 
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) 
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808) 
at android.os.Handler.dispatchMessage(Handler.java:106) 
at android.os.Looper.loop(Looper.java:193) 
at android.app.ActivityThread.main(ActivityThread.java:6669) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) 
E/MonitoringInstr: Exception encountered by: Thread[main,5,main]. Dumping thread state to outputs and pining for the fjords.
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.memento/com.example.memento.LoginActivity}: java.lang.ClassCastException: kotlin.Unit cannot be cast to com.example.services.AuthService
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.ClassCastException: kotlin.Unit cannot be cast to com.example.services.AuthService
at com.example.memento.LoginActivity.onCreate(LoginActivity.kt:25)
at android.app.Activity.performCreate(Activity.java:7136)
at android.app.Activity.performCreate(Activity.java:7127)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at androidx.test.runner.MonitoringInstrumentation.callActivityOnCreate(MonitoringInstrumentation.java:674)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048) 
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) 
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) 
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808) 
at android.os.Handler.dispatchMessage(Handler.java:106) 
at android.os.Looper.loop(Looper.java:193) 
at android.app.ActivityThread.main(ActivityThread.java:6669) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) 
E/THREAD_STATE: Thread[MonitoringInstrumentation,5,main]
java.lang.Object.wait(Native Method)
android.app.Instrumentation.startActivitySync(Instrumentation.java:496)
android.app.Instrumentation.startActivitySync(Instrumentation.java:435)
androidx.test.runner.MonitoringInstrumentation.access$101(MonitoringInstrumentation.java:98)
androidx.test.runner.MonitoringInstrumentation$4.call(MonitoringInstrumentation.java:443)
androidx.test.runner.MonitoringInstrumentation$4.call(MonitoringInstrumentation.java:440)
java.util.concurrent.FutureTask.run(FutureTask.java:266)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
java.lang.Thread.run(Thread.java:764)
Thread[Binder:11719_2,5,main]
Thread[magnifier pixel copy result handler,5,main]
android.os.MessageQueue.nativePollOnce(Native Method)
android.os.MessageQueue.next(MessageQueue.java:326)
android.os.Looper.loop(Looper.java:160)
android.os.HandlerThread.run(HandlerThread.java:65)
Thread[FinalizerWatchdogDaemon,5,system]
java.lang.Object.wait(Native Method)
java.lang.Daemons$FinalizerWatchdogDaemon.sleepUntilNeeded(Daemons.java:297)
java.lang.Daemons$FinalizerWatchdogDaemon.runInternal(Daemons.java:277)
java.lang.Daemons$Daemon.run(Daemons.java:103)
java.lang.Thread.run(Thread.java:764)
Thread[InstrumentationConnectionThread,5,main]
android.os.MessageQueue.nativePollOnce(Native Method)
android.os.MessageQueue.next(MessageQueue.java:326)
android.os.Looper.loop(Looper.java:160)
android.os.HandlerThread.run(HandlerThread.java:65)
Thread[Profile Saver,5,system]
Thread[main,5,main]
dalvik.system.VMStack.getThreadStackTrace(Native Method)
java.lang.Thread.getStackTrace(Thread.java:1538)
java.lang.Thread.getAllStackTraces(Thread.java:1588)
androidx.test.runner.MonitoringInstrumentation.getThreadState(MonitoringInstrumentation.java:643)
androidx.test.runner.MonitoringInstrumentation.dumpThreadStateToOutputs(MonitoringInstrumentation.java:638)
androidx.test.runner.MonitoringInstrumentation.onException(MonitoringInstrumentation.java:632)
androidx.test.runner.AndroidJUnitRunner.onException(AndroidJUnitRunner.java:522)
androidx.test.runner.MonitoringInstrumentation$3.uncaughtException(MonitoringInstrumentation.java:268)
java.lang.Thread.dispatchUncaughtException(Thread.java:1955)
Thread[Binder:11719_1,5,main]
Thread[ReferenceQueueDaemon,5,system]
java.lang.Object.wait(Native Method)
java.lang.Daemons$ReferenceQueueDaemon.runInternal(Daemons.java:178)
java.lang.Daemons$Daemon.run(Daemons.java:103)
java.lang.Thread.run(Thread.java:764)
Thread[Jit thread pool worker thread 0,5,main]
Thread[FinalizerDaemon,5,system]
java.lang.Object.wait(Native Method)
java.lang.Object.wait(Object.java:422)
java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:188)
java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:209)
java.lang.Daemons$FinalizerDaemon.runInternal(Daemons.java:232)
java.lang.Daemons$Daemon.run(Daemons.java:103)
java.lang.Thread.run(Thread.java:764)
Thread[HeapTaskDaemon,5,system]
Thread[Instr: com.example.memento.MockTestRunner,5,main]
java.lang.Object.wait(Native Method)
java.lang.Thread.parkFor$(Thread.java:2137)
sun.misc.Unsafe.park(Unsafe.java:358)
java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:230)
java.util.concurrent.FutureTask.awaitDone(FutureTask.java:447)
java.util.concurrent.FutureTask.get(FutureTask.java:205)
androidx.test.runner.MonitoringInstrumentation.startActivitySync(MonitoringInstrumentation.java:448)
androidx.test.rule.ActivityTestRule.launchActivity(ActivityTestRule.java:354)
androidx.test.rule.ActivityTestRule$ActivityStatement.evaluate(ActivityTestRule.java:525)
org.junit.rules.RunRules.evaluate(RunRules.java:20)
org.junit.runners.ParentRunner.runLeaf(ParentRunner
E/MonitoringInstr: Dying now...
W/MonitoringInstr: Invoking uncaught exception handler java.lang.ThreadGroup[name=main,maxpri=10] (a class java.lang.ThreadGroup)
I/Process: Sending signal. PID: 11719 SIG: 9
Test running failed: Instrumentation run failed due to 'Process crashed.'
What is wrong with my code?
I tried updating the LoginActivity to this
class LoginActivity : AppCompatActivity()
{
lateinit var authService: AuthService
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_login)
DaggerAppComponent.create().inject(this)
tv_testing.text = authService.login()
}
}
Then I got this error
kotlin.UninitializedPropertyAccessException: lateinit property authService has not been initialized
at com.example.memento.LoginActivity.onCreate(LoginActivity.kt:27)
DaggerAppComponent.create().inject(this) doesn't return anything but you're trying to cast it to AuthService. Therefore, you get ClassCastException. Instead, you should first declare AuthService as lateinit var and annotate it with #Inject. Then you can call inject() function. You can see full code below:
class LoginActivity : AppCompatActivity()
{
#Inject
private lateinit var authService: AuthService
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_login)
DaggerAppComponent.create().inject(this)
tv_testing.text = authService.login();
}
}
I hope my answer helps.

App crashes on opening error:Unable to start activity Component Info

I was just coded a simple app and when i run it
I got this error
2019-05-16 15:12:46.079 6879-6879/net.perkglobal.myapplication E/AndroidRuntime: FATAL EXCEPTION: main
Process: net.perkglobal.myapplication, PID: 6879
java.lang.RuntimeException: Unable to start activity ComponentInfo{net.perkglobal.myapplication/net.perkglobal.myapplication.MainActivity}: java.lang.IllegalArgumentException: Not an array: class java.util.ArrayList
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.IllegalArgumentException: Not an array: class java.util.ArrayList
at java.lang.reflect.Array.notAnArray(Array.java:823)
at java.lang.reflect.Array.get(Array.java:210)
at net.perkglobal.myapplication.MainActivity.onCreate(MainActivity.java:91)
at android.app.Activity.performCreate(Activity.java:7136)
at android.app.Activity.performCreate(Activity.java:7127)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048) 
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) 
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) 
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808) 
at android.os.Handler.dispatchMessage(Handler.java:106) 
at android.os.Looper.loop(Looper.java:193) 
at android.app.ActivityThread.main(ActivityThread.java:6669) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
According to the the error there is error in line 91.So i try changing it but nothing seems to work
can Someone please tell me what i should do
here is a part of code which has the error
TextView text= findViewById(R.id.WP);
List<String> list = new ArrayList<String>();
list.add("A");
list.add("B");
list.add("C");
list.add("D");
list.add("E");
list.add("F");
list.add("G");
list.add("H");
list.add("I");
list.add("J");
list.add("K");
list.add("L");
list.add("M");
list.add("N");
list.add("O");
list.add("P");
list.add("Q");
list.add("R");
list.add("S");
list.add("T");
list.add("U");
list.add("V");
list.add("W");
list.add("X");
list.add("Y");
list.add("Z");
list.add("a");
list.add("b");
list.add("c");
list.add("d");
list.add("e");
list.add("f");
list.add("g");
list.add("h");
list.add("i");
list.add("j");
list.add("k");
list.add("l");
list.add("m");
list.add("n");
list.add("o");
list.add("p");
list.add("q");
list.add("r");
list.add("s");
list.add("t");
list.add("u");
list.add("v");
list.add("w");
list.add("x");
list.add("y");
list.add("z");
list.add("1");
list.add("2");
list.add("3");
list.add("4");
list.add("5");
list.add("6");
list.add("7");
list.add("8");
list.add("9");
list.add("0");
list.add(" "); for (int n=0 ;n<64;n++){
String string = Array.get(list,n).toString();
text.setText(string);}
change your for loop to this
Iterator i = list.iterator();
while (i.hasNext()) {
Log.d("string",i.next())
//your code goes here
}

My code is throwing an error [Fatal error: Main] can you tell me why?

I'm creating all the objects after onCreate and setContentView but I'm still getting the error [Fatal Error: Main] and it makes my app crash. I've seen people face the same problem but it's when they make objects for their EditText above the setContentView tag and I've tried moving it around but it's just not working for me hope you can help me. I'll provide you guys with the code... Thanks
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//-----------------------------------------------------------------------------------------------------------------------
//ASSIGNING
final EditText name=(findViewById(R.id.editText));
final EditText date=(findViewById(R.id.editText3));
EditText month=(findViewById(R.id.editText4));
final EditText year=(findViewById(R.id.editText5));
Button b=(findViewById(R.id.button));
//-----------------------------------------------------------------------------------------------------------------------
//NAME NUMBER
String s= name.getText().toString();
char[] n=s.toCharArray();
int i,total=0;
The Error I'm getting:-
2019-02-09 13:24:08.085 6934-6934/com.example.numerologysolutions E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.numerologysolutions, PID: 6934
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.numerologysolutions/com.example.numerologysolutions.MainActivity}: java.lang.NumberFormatException: For input string: ""
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.NumberFormatException: For input string: ""
at java.lang.Integer.parseInt(Integer.java:627)
at java.lang.Integer.parseInt(Integer.java:650)
at com.example.numerologysolutions.MainActivity.onCreate(MainActivity.java:81)
at android.app.Activity.performCreate(Activity.java:7136)
at android.app.Activity.performCreate(Activity.java:7127)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048) 
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) 
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) 
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808) 
at android.os.Handler.dispatchMessage(Handler.java:106) 
at android.os.Looper.loop(Looper.java:193) 
at android.app.ActivityThread.main(ActivityThread.java:6669) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) 
That's the problem according to your error stack trace. You're trying to convert a string to a number.
Caused by: java.lang.NumberFormatException: For input string: ""

Categories

Resources