please solve this issue I am a beginner in android development I don't know what the issue is.
Process: com.example.myapplicationofexarth, PID: 2703
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.example.myapplicationofexarth/com.example.myapplicationofexarth.MainActivity}:
java.lang.ClassCastException:
android.support.constraint.ConstraintLayout cannot be cast to
android.widget.TextView 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:
android.support.constraint.ConstraintLayout cannot be cast to
android.widget.TextView at
com.example.myapplicationofexarth.MainActivity.onCreate(MainActivity.java:15)
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)
MainActivity.Java
package com.example.myapplicationofexarth;
import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
TextView text;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
text=(TextView)findViewById(R.id.textexample);
text.setTextColor(Color.RED);
}
}
looking at the error message I'd say you've probably given the R.Id.textexample to the constraint layout instead of the TextView by accident.
check the Id of the textView in the xml layout.
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();
I am new to Android in-app purchases. I have followed the official documentation and I can't go beyond building the BillingClient as app crashes when it tries to build the BillingClient. Any help or any reference to a android in-app purchases in Java is much appreciated. My MainActivity.java codes is as follows:
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import com.android.billingclient.api.BillingClient;
import com.android.billingclient.api.BillingClientStateListener;
import com.android.billingclient.api.BillingResult;
import com.android.billingclient.api.Purchase;
import com.android.billingclient.api.PurchasesUpdatedListener;
import java.util.List;
public class MainActivity extends AppCompatActivity{
private PurchasesUpdatedListener purchaseUpdateListener = new PurchasesUpdatedListener() {
#Override
public void onPurchasesUpdated(BillingResult billingResult, List<Purchase> purchases) {
// To be implemented in a later section.
}
};
private BillingClient billingClient = BillingClient.newBuilder(MainActivity.this)
.setListener(purchaseUpdateListener)
.enablePendingPurchases()
.build();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Crash Log is as follows:
2020-07-07 01:19:40.667 27956-27956/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.js.bs, PID: 27956
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.js.bs/com.js.bs.MainActivity}: 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:3272)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3500)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2049)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7523)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:941)
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:122)
at com.android.billingclient.api.BillingClientImpl.initialize(com.android.billingclient:billing##3.0.0:26)
at com.android.billingclient.api.BillingClientImpl.<init>(com.android.billingclient:billing##3.0.0:13)
at com.android.billingclient.api.BillingClientImpl.<init>(com.android.billingclient:billing##3.0.0:1)
at com.android.billingclient.api.BillingClient$Builder.build(com.android.billingclient:billing##3.0.0:14)
at com.js.bs.MainActivity.<init>(MainActivity.java:31)
at java.lang.Class.newInstance(Native Method)
at android.app.AppComponentFactory.instantiateActivity(AppComponentFactory.java:95)
at androidx.core.app.CoreComponentFactory.instantiateActivity(CoreComponentFactory.java:41)
at android.app.Instrumentation.newActivity(Instrumentation.java:1253)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3260)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3500)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2049)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7523)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:941)
2020-07-07 01:19:41.044 27956-27956/? I/Process: Sending signal. PID: 27956 SIG: 9
Please change the billingClient object creation as below. While creating this object from outside the context may be null, so crashing. Move the object creation to onCreate() method of the activity.
private BillingClient billingClient;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
billingClient = BillingClient.newBuilder(this)
.setListener(purchaseUpdateListener)
.enablePendingPurchases()
.build();
}
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.
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
}