Runtime error " ....." null object reference

hello all ,
my name memet from indonesian ,
i’am trying to make extensions ,
the extension is to make a call and sms from specified sim card (on dual sim Android Phone)…
the extension for sms / texting from specified sim is work…
but the extension for call get Runtime error ,
anyone can help me ??

thanks

Hi @memet_foe

Please provide some more details about the error, such as the specific error message and a stack trace from adb logcat. This can help us to better diagnose your issue.

error is “Runtime Error”,
"Attempt to invoke virtual method ‘android.telephony.TelephonyManager android.telephony.TelephonyManager.createForSubscriptionId(int)’ on a null obhect reference …

i have looking adb command to get the stack trace but i didn’t get it ,…

and very very thank you for responding me …
this very important for me ,
i looking for method ,
i just need this work on my phone ,
i looked , decompile existing apk to get a source code , i refer to android developer , i think the simple method to get call from a specified sim is “createForSubcriptionId” ,

or , maybe mr.Ewpatton have another way , like to wrtie settings as a user to changing default voice key , default voice key is choosed by default to make a call …
ak had decompile my phone settings , my phone apk to make a call , but i cant access them because "not exported from uid and pid, it mean in they manyfest dosn’t write "android exported : true:, when they doesn’t exported , they not allow access from another app …

i really hope , i have a friend maybe a teacher to ask , except google … its realy compicated and i’am sorry if my english too bad for conversation …

Thankss aloot mr.ewpatton …

there i finally get the stacktrace …

10-23 22:32:50.081 3637 3637 I KodularHelper: Prepare new RippleDrawable succe
ssfully executed
10-23 22:32:50.197 3637 3637 I KodularHelper: Prepare new RippleDrawable succe
ssfully executed
10-23 22:32:50.212 3637 3637 W System.err: java.lang.NullPointerException: Att
empt to invoke virtual method ‘android.telephony.TelephonyManager android.teleph
ony.TelephonyManager.createForSubscriptionId(int)’ on a null object reference
10-23 22:32:50.212 3637 3637 W System.err: at com.memetlq.Lq2simTexting.sim
1Call(Lq2simTexting.java:103)
10-23 22:32:50.212 3637 3637 W System.err: at java.lang.reflect.Method.invo
ke(Native Method)
10-23 22:32:50.212 3637 3637 W System.err: at gnu.expr.PrimProcedure.apply(
PrimProcedure.java:285)
10-23 22:32:50.212 3637 3637 W System.err: at gnu.mapping.CallContext.runUn
tilDone(CallContext.java:234)
10-23 22:32:50.212 3637 3637 W System.err: at gnu.mapping.CallContext.runUn
tilValue(CallContext.java:298)
10-23 22:32:50.212 3637 3637 W System.err: at gnu.mapping.MethodProc.applyN
(MethodProc.java:113)
10-23 22:32:50.212 3637 3637 W System.err: at gnu.kawa.reflect.Invoke.apply
N(Invoke.java:193)
10-23 22:32:50.212 3637 3637 W System.err: at gnu.kawa.functions.ApplyToArg
s.applyN(ApplyToArgs.java:139)
10-23 22:32:50.213 3637 3637 W System.err: at gnu.kawa.functions.Apply.appl
yN(Apply.java:70)
10-23 22:32:50.213 3637 3637 W System.err: at gnu.mapping.ProcedureN.apply2
(ProcedureN.java:39)
10-23 22:32:50.213 3637 3637 W System.err: at com.google.youngandroid.runti
me.callComponentMethod(runtime4954007513301323857.scm:1041)
10-23 22:32:50.213 3637 3637 W System.err: at io.kodular.memet_foe.aaaa.Scr
een1.Button1$Click(Screen1.yail:33)
10-23 22:32:50.213 3637 3637 W System.err: at io.kodular.memet_foe.aaaa.Scr
een1$frame.apply0(Screen1.yail:523)
10-23 22:32:50.213 3637 3637 W System.err: at gnu.expr.ModuleBody.applyN(Mo
duleBody.java:226)
10-23 22:32:50.213 3637 3637 W System.err: at gnu.expr.ModuleMethod.applyN(
ModuleMethod.java:216)
10-23 22:32:50.213 3637 3637 W System.err: at gnu.kawa.functions.ApplyToArg
s.applyN(ApplyToArgs.java:139)
10-23 22:32:50.213 3637 3637 W System.err: at gnu.kawa.functions.Apply.appl
yN(Apply.java:70)
10-23 22:32:50.213 3637 3637 W System.err: at gnu.mapping.ProcedureN.apply2
(ProcedureN.java:39)
10-23 22:32:50.213 3637 3637 W System.err: at io.kodular.memet_foe.aaaa.Scr
een1.dispatchEvent(Screen1.yail:10125)
10-23 22:32:50.213 3637 3637 W System.err: at com.google.appinventor.compon
ents.runtime.EventDispatcher.hxYOFxFjLpN1maJuWNxUV40nExCGxsxkDPOTgtzMu4zlZCQb3bP
lKsXo1SYJg6ME(SourceFile:243)
10-23 22:32:50.213 3637 3637 W System.err: at com.google.appinventor.compon
ents.runtime.EventDispatcher.dispatchEvent(SourceFile:199)
10-23 22:32:50.213 3637 3637 W System.err: at com.google.appinventor.compon
ents.runtime.Button.Click(SourceFile:54)
10-23 22:32:50.213 3637 3637 W System.err: at com.google.appinventor.compon
ents.runtime.Button.click(SourceFile:45)
10-23 22:32:50.213 3637 3637 W System.err: at com.google.appinventor.compon
ents.runtime.ButtonBase.onClick(SourceFile:639)
10-23 22:32:50.213 3637 3637 W System.err: at android.view.View.performClic
k(View.java:6304)
10-23 22:32:50.213 3637 3637 W System.err: at android.view.View$PerformClic
k.run(View.java:24803)
10-23 22:32:50.213 3637 3637 W System.err: at android.os.Handler.handleCall
back(Handler.java:794)
10-23 22:32:50.213 3637 3637 W System.err: at android.os.Handler.dispatchMe
ssage(Handler.java:99)
10-23 22:32:50.213 3637 3637 W System.err: at android.os.Looper.loop(Looper
.java:176)
10-23 22:32:50.213 3637 3637 W System.err: at android.app.ActivityThread.ma
in(ActivityThread.java:6651)
10-23 22:32:50.213 3637 3637 W System.err: at java.lang.reflect.Method.invo
ke(Native Method)
10-23 22:32:50.213 3637 3637 W System.err: at com.android.internal.os.Runti
meInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
10-23 22:32:50.213 3637 3637 W System.err: at com.android.internal.os.Zygot
eInit.main(ZygoteInit.java:824)
10-23 22:32:50.214 3637 3637 I RuntimeErrorAlert: in alert
10-23 22:32:50.215 3637 3637 E com.google.appinventor.components.runtime.util.
RuntimeErrorAlert: Attempt to invoke virtual method ‘android.telephony.Telephony
Manager android.telephony.TelephonyManager.createForSubscriptionId(int)’ on a nu
ll object reference

The typical reason for this is that you probably aren’t initializing things in the right order. You will want to set up a reference to the TelephonyManager service first by calling the appropriate method on the component’s Form object. Since you’re not doing that before your call to get the SIM card, the pointer is null and you get the NullPointerException, which gets wrapped into the final RuntimeError that you see.

sorry mr.ewpatton ,
can you give e a example ?
may be some class in appinvsource code ??

We don’t have any examples of accessing the telephony manager in App Inventor, but you should be able to do something like:

private TelephonyManager telephonyManager;

public MyExtension(Form form) {
  super(form);
  telephonyManager = (TelephonyManager) form.getSystemService(Context.TELEPHONY_SERVICE);
}

Generally, I would recommend that you understand how to write the code to do what you want in Android Studio first as there are plenty of examples on the web (cf. StackOverflow). Once you know how to make it work in Android, you can port the code into an App Inventor extension.

i used new method ,
List android.telephony.SubscriptionManager.getActiveSubscriptionInfoList()"to get active subID)
and in createForSubscriptionId( list.get(0) 0 or 1 according to sim 1 or 2 …
but it same error ,

but error in method " java.util.list android.telephony.SubscriptionManager.getActiveSubscriptionInfoList() " on a null object reference …

i have try getCapablePhoneAccount() / its same error in the method …

yeah i know , i have jump the step …
its not easy , i have to learn from basic java programming for understand what i need to do…
i just need this one function , call from a specified sim …
that all enough …
if that extension just can work in my phone , it not a problem for me , i create not for sale but for use …

okay , finally very thanksfully mr.ewpatton ,
i’ll look another extension where they use a telephony service and try implement that to my extension , thanksyou mr …