If I try to use the following code, I am able to use Truecaller's SDK and fetch the user's profile if he has truecaller installed.
//has_truecaller = TrueSDK.getInstance().isUsable(); //doesnt work before init() methof
TrueSdkScope trueScope;
TrueSdkScope.Builder sdkBuilder = new TrueSdkScope.Builder(this, sdkCallback)
.consentMode(TrueSdkScope.CONSENT_MODE_POPUP )
.consentTitleOption( TrueSdkScope.SDK_CONSENT_TITLE_VERIFY )
.footerType( TrueSdkScope.FOOTER_TYPE_SKIP );
if(has_truecaller) {
trueScope = sdkBuilder.sdkOptions( TrueSdkScope.SDK_OPTION_WITH_OTP ).build();
}else{
//TODO get mobile number
BaseActivity.USER_MOBILE_NUMBER = "12345677";
trueScope = sdkBuilder.sdkOptions( TrueSdkScope.SDK_OPTION_WITH_OTP ).build();
}
TrueSDK.init(trueScope);
However If i remove Truecaller from the device i get the following error:
2-06 10:38:45.437 25694-25694/com.project.xyz.userclientapp E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.project.xyz.userclientapp, PID: 25694 java.lang.NoClassDefFoundError:
Failed resolution of: Lretrofit2/converter/gson/GsonConverterFactory;
at com.truecaller.android.sdk.b.c.a(Unknown Source:9)
at com.truecaller.android.sdk.clients.a.<init>(Unknown Source:10)
at com.truecaller.android.sdk.a.<init>(Unknown Source:46)
at com.truecaller.android.sdk.a.a(Unknown Source:2)
at com.truecaller.android.sdk.TrueSDK.init(Unknown Source:5)
at com.project.xyz.userclientapp.login.LoginActivity.setupTrueSdk(LoginActivity.java:49)
at com.project.xyz.userclientapp.login.LoginActivity.onCreate(LoginActivity.java:30)
at android.app.Activity.performCreate(Activity.java:7149)
at android.app.Activity.performCreate(Activity.java:7140)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1288)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3017)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3172)
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:1906)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6863)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:537)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
You can check if the Truecaller app is present on the device or not by using the following line -
TrueSDK.getInstance().isUsable()
You do need to initialize the SDK using the init() method before checking for this. It will return a boolean true / false depending on wether Truecaller is installed or not.
Also, the logs what you shared are because of missing a library dependency in your android project. Can you try add the following dependency in your gradle. This should help solve the error -
compile 'com.squareup.retrofit2:retrofit:2.0.0-beta4'
compile 'com.squareup.retrofit2:converter-gson:2.0.0-beta4'
Related
I want to get the primary text on my clipboard and would like to know how to do that in newer android versions.
This code works perfectly when I tested it in an emulator running Android Pie, but the app crashes when I use it on my Phone running android 12.1.
please help me with this.
clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
if (clipboard.hasPrimaryClip())
clipItem = clipboard.getPrimaryClip().getItemAt(0);
clipText = clipItem.getText().toString();
Details.setText(clipItem.getText().toString());
Here's the Error I got from Logcat
2022-10-01 19:23:27.595 1349-5125 ClipboardService pid-1349 E Denying clipboard access to com.jery.tachisyrpc, the application is not in focus nor is it a system service for user 0
2022-10-01 19:23:27.595 8222-8222 AndroidRuntime com.jery.tachisyrpc D Shutting down VM
2022-10-01 19:23:27.596 8222-8222 AndroidRuntime com.jery.tachisyrpc E FATAL EXCEPTION: main
Process: com.jery.tachisyrpc, PID: 8222
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.jery.tachisyrpc/com.jery.tachisyrpc.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.CharSequence android.content.ClipData$Item.getText()' on a null object reference at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4111) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4277) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103)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:2443) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loopOnce(Looper.java:226) at android.os.Looper.loop(Looper.java:313)
at android.app.ActivityThread.main(ActivityThread.java:8751)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.CharSequence android.content.ClipData$Item.getText()' on a null object reference
at com.jery.tachisyrpc.MainActivity.onCreate(MainActivity.java:55)
at android.app.Activity.performCreate(Activity.java:8290)
at android.app.Activity.performCreate(Activity.java:8270)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1329)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4085)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4277)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103)
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:2443)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:313)
at android.app.ActivityThread.main(ActivityThread.java:8751)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
I am getting this error on pre-launch report from playstore console.
I am not able to generate this crash on any real device I try.
The device from pre-launch report is Samsung s9 (Android 8.0).
This is the stacktrace :
FATAL EXCEPTION: main
java.lang.IllegalStateException: Cannot perform this action on a sealed instance.
at android.view.accessibility.AccessibilityNodeInfo.enforceNotSealed(AccessibilityNodeInfo.java:2992)
at android.view.accessibility.AccessibilityNodeInfo.setSource(AccessibilityNodeInfo.java:818)
at android.view.accessibility.AccessibilityNodeInfo.setSource(AccessibilityNodeInfo.java:795)
at android.view.accessibility.AccessibilityNodeInfo.obtain(AccessibilityNodeInfo.java:3008)
at android.view.View.createAccessibilityNodeInfoInternal(View.java:7897)
at android.view.View.createAccessibilityNodeInfo(View.java:7883)
at android.view.AccessibilityInteractionController$AccessibilityNodePrefetcher.prefetchDescendantsOfRealNode(AccessibilityInteractionController.java:1051)
at android.view.AccessibilityInteractionController$AccessibilityNodePrefetcher.prefetchAccessibilityNodeInfos(AccessibilityInteractionController.java:876)
at android.view.AccessibilityInteractionController.findAccessibilityNodeInfoByAccessibilityIdUiThread(AccessibilityInteractionController.java:199)
at android.view.AccessibilityInteractionController.-wrap1(Unknown Source:0)
at android.view.AccessibilityInteractionController$PrivateHandler.handleMessage(AccessibilityInteractionController.java:1225)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6938)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
Without seeing more code, I'd recommend looking through the following links to try and determine an exact cause.
https://stackoverflow.com/a/57964014/5779200
When updating values for AccessibilityNodeInfo it has been seen that calling .getClassName() to see if the value is NULL can help prevent this error.
https://stackoverflow.com/a/32829963/5779200
Similar to the previous, If you are changing the text of an accessibilityNodeInfo you can check to see if it's sealed by calling isSealed(). on the AccessibilityNodeInfo object
I have an app working on every api completely but in android 8 api 26 it crashes and I don't know why this happend .
The app use sms sending and receiving permissions and I put all requestPermissions in activity and manifests. Target sdk is on 26
Here the logcat of android studio error when app crash:
hapital.com.BitCar E/AndroidRuntime: FATAL EXCEPTION: main Process: hapital.com.BitCar, PID: 25271
java.lang.RuntimeException: Unable to start activity ComponentInfo{hapital.com.BitCar/hapital.com.BitCar.MainActivity}: java.lang.IllegalArgumentException: Invalid destinationAddress
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: java.lang.IllegalArgumentException: Invalid destinationAddress
at android.telephony.SmsManager.sendTextMessageInternal(SmsManager.java:320)
at android.telephony.SmsManager.sendTextMessage(SmsManager.java:312)
at hapital.com.BitCar.MainActivity.onCreate(MainActivity.java:194)
at android.app.Activity.performCreate(Activity.java:6975)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Invalid destinationAddress ?? what does it mean??
For example it has an error on SmsManager.java when open it just like pic below has error in import libraries
enter image description here
Could someone help what should i do?
According to the source code of SmsManager, that exception is thrown when you call sendTextMessage with a destination address parameter that is null or an empty String.
If your code to send the SMS (as per your comment) is this:
SharedPreferences panelnumber = getSharedPreferences("Prefs", MODE_PRIVATE);
String string_from_sp = panelnumber.getString("myStringName", "");
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(string_from_sp.toString(), null,
smsBody.toString(), null, null);
then it follows that string_from_sp is a null or empty String.
Given the way you are initializing that variable, either:
the "mystringName" field retrieved from the preferences is empty, or
you have the preference field name incorrect, and you are getting the default value which you have specified to be an empty String.
There is not sufficient info to explain why this happens with API 26 only ... if that is what you are saying.
finally i found the problem
problem was in layout of activity that i used NavigationView like belo :
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="230dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_header_main2"
app:menu="#menu/activity_main2_drawer" />
and in api 26 and higher not support
I am having weird problems with my code and I cannot explain anything that's happening. It's crashing on Marshmallow but not on Nougat which makes this more bizarre.
I can point to a line where the error occurs but the error itself is not clear. I am not sure what is crashing and how to prevent it. Here are the details:
The crash happens when I try to make a call to the server. To do this, I use Retrofit alongside RxJava and I do this in Kotlin. Here is my code:
fun login(username: String, password: String, callback: Login.OnLoginListener) {
RestClient.getInstance().service
.loginUser( //<- This line is crashing for no apparent reason
Utils.RequestBodyParser.parseString(username),
Utils.RequestBodyParser.parseString(password)
)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
{ success ->
(
if (success.status)
callback.onLoginSuccess()
else
callback.onLoginError()
)
},
{ error ->
GenericErrorHandler.handleError(error, callback.retrieveContext())
}
)
}
Here is the logcat output:
java.lang.IncompatibleClassChangeError: Class 'java.lang.VirtualMachineError' does not implement interface 'java.lang.CharSequence' in call to 'java.lang.String java.lang.CharSequence.toString()' (declaration of 'java.lang.Throwable' appears in /system/framework/core-libart.jar)
at fi.hohtolabs.kuuratablet.network.WebController$Companion.login(WebController.kt:19)
at fi.hohtolabs.kuuratablet.presenter.LoginPresenter.login(LoginPresenter.kt:31)
at fi.hohtolabs.kuuratablet.dialog.LoginDialog.lambda$onResume$2$LoginDialog(LoginDialog.java:74)
at fi.hohtolabs.kuuratablet.dialog.LoginDialog$$Lambda$2.onClick(Unknown Source)
at android.view.View.performClick(View.java:5198)
at android.view.View$PerformClick.run(View.java:21147)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Does anybody have any suggestions on what I should do? (I tried cleaning, rebuilding, restarting and invalidating caches, deleted the .gradle folder and all other stuff like that, nothing helps)
The problem had occurred only on Marshmellow devices and later was different one. Later i got the ArrayIndexOutOfBoundsException and finally found out what the problem was.
The problem was that my libraries were over 64K methods and because Instant Run was on, there was no multidex error and whole application did not compile well.
My android application was running smoothly before i install some Android Studio updates, and asked me to upgrade gradle etc after the update been installed.
Later on, the Android Studio asked me to update my Android Emulator (Emulator Nexus 5X API 24 Android v7.0), since i've made all these changes, my application has been unable to open when i click run. But remember it has no codding errors when i debug etc.
The error message from Android Monitor is:
08-13 14:07:30.735 3889-3889/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.smartlegal.law.freeman.smartlegal, PID: 3889
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.smartlegal.law.freeman.smartlegal/com.smartlegal.law.freeman.smartlegal.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
at com.smartlegal.law.freeman.smartlegal.MainActivity.onCreate(MainActivity.java:39)
at android.app.Activity.performCreate(Activity.java:6662)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
08-13 14:07:30.744 3889-3896/? W/art: Suspending all threads took: 5.874ms
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
As the error states, you're trying to set an onClickListener on a Button that does not exist (returns null). To simplify, when you're defining your Button, you call findViewById to associate the Button in Java with an XML element, but the ID that you are passing is not valid - either you're trying to call the setOnClickListener before you call setContentView, or the ID you are passing to findViewById has a typo or simply does not exist in the XML layout file.
Some more information, such as the code to your MainActivity and the layout file, would be useful to determine the exact cause of your problem.
Yes you're right, i forgot to specify the ID for the editText and Button, that is why it wasnt possible to find them ID on XML. So i've set it up and reloaded the project and it is running smoothly now. Thanks guys for the support.
"As the error states, you're trying to set an onClickListener on a Button that does not exist (returns null). To simplify, when you're defining your Button, you call findViewById to associate the Button in Java with an XML element, but the ID that you are passing is not valid. by: Timothy Langer".