Android Question java.lang.RuntimeException: java.lang.reflect.InvocationTargetException

IanMc

Well-Known Member
Licensed User
Longtime User
Hi all,

I have added a new activity to my app, put some controls on it but apart from that I haven't started coding it yet. Occasionally I'll get a crash, sometimes just while its sitting in the background.

I am using the phone library to force orientation, do you think this might be the problem?

Here is the code and below is the error:
Code: Copy
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim p As Phone
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("screen3landscape")
    p.SetScreenOrientation(0) 'Landscape
    'p.SetScreenOrientation(1) 'Portrait
    'p.SetScreenOrientation(-1) 'Both

End Sub

Code: Copy
screen3landscapeinitializeProcessGlobals (java line: 276)


java.lang.RuntimeException: java.lang.reflect.InvocationTargetException


    at com.btinterface.trial.beta.screen3landscape.initializeProcessGlobals(screen3landscape.java:276)
    at com.btinterface.trial.beta.screen3landscape.afterFirstLayout(screen3landscape.java:85)
    at com.btinterface.trial.beta.screen3landscape.access$100(screen3landscape.java:16)
    at com.btinterface.trial.beta.screen3landscape$WaitForLayout.run(screen3landscape.java:74)
    at android.os.Handler.handleCallback(Handler.java:587)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:130)
    at android.app.ActivityThread.main(ActivityThread.java:3703)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:507)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:507)
    at com.btinterface.trial.beta.screen3landscape.initializeProcessGlobals(screen3landscape.java:274)
    ... 12 more
Caused by: java.lang.RuntimeException: java.lang.NullPointerException
    at com.btinterface.trial.beta.main.initializeProcessGlobals(main.java:612)
    ... 15 more
Caused by: java.lang.NullPointerException
    at com.btinterface.trial.beta.main._process_globals(main.java:698)
    at com.btinterface.trial.beta.main.initializeProcessGlobals(main.java:592)
    ... 15 more
 
Certainly, thanks for looking.

Code: Copy
'Activity module MAIN
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim pm As PackageManager   
    Dim PackageName As String = MySubs.GetPackageName
    Dim VersionCode As String = pm.GetVersionCode(PackageName)
    Dim VersionName As String = pm.GetVersionName(PackageName)
    Dim ApplicationLabel As String = pm.GetApplicationLabel(PackageName)
  
    Dim commandPauseMillis As Long = 0 'DateTime.Now + PauseMillis = how many milliseconds to pause
    Dim encodingType As String ="UTF-8" 'mult-byte encoding can represent Unicode characters
    'Dim encodingType As String = "ISO-8859-1" 'single byte encoding
    Dim TTS1 As TTS 'Text To Speech
    Dim admin As BluetoothAdmin
    Dim serial1 As Serial
    Dim foundDevices As List
    Type NameAndMac (Name As String, Mac As String)
    Dim connectedDevice As NameAndMac
    Dim SystemLog As List 'a global list object, this should be cleared to clear the log in the terminal screen
    Dim connected As Boolean = False
    Dim gravityCenter As Int = Bit.OR(Gravity.CENTER_VERTICAL, Gravity.center)
    Dim gravityRight As Int = Bit.OR(Gravity.CENTER_VERTICAL, Gravity.right)
    Dim gravityLeft As Int = Bit.OR(Gravity.CENTER_VERTICAL, Gravity.left)   
  End Sub
 
Upvote 0
The problem is here:
Code: Copy
 Dim PackageName As String = MySubs.GetPackageName
    Dim VersionCode As String = pm.GetVersionCode(PackageName)
    Dim VersionName As String = pm.GetVersionName(PackageName)
    Dim ApplicationLabel As String = pm.GetApplicationLabel(PackageName)
Process_Globals should only be used for variables declarations or assignment of "simple" variables.
You should move this code.
 
Upvote 0
Back
Top