Problem creating preferences screen.

William Hunter

Active Member
Licensed User
Longtime User
I am having a problem creating a preferences screen. If I use a Button to launch “StartActivity(SettingsScreen.CreateIntent)” the preferences screen appears as it should. Whereas, if I use a AHQuickAction menu item for the launch I get the error message “The application pop3(Process.Eraps.pop3) has stopped unexpectedly. Please try again”, along with a force stop Button. The log contains this information:

** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **

I don’t understand why there is this difference, because in all other respects the setups are in the main identical, other than the Button is set up in “Sub CreatePreferenceScreen”, while the AHQuickAction menu is set up in “Sub Activity_Create”. Is there something I need to add to my code in order to use the AHQuickAction menu to launch a preference screen? Any help would be greatly appreciated. :BangHead:
 

William Hunter

Active Member
Licensed User
Longtime User
>>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
CheckJNI is ON

--- registering native functions ---
GC_EXPLICIT freed 322 objects / 17872 bytes in 98ms
Scanning package: /data/app/vmdl42690.tmp
Scanning package net.wapps.pop3
/data/app/net.wapps.pop3-1.apk changed; unpacking
DexInv: --- BEGIN '/data/app/net.wapps.pop3-1.apk' ---
DexOpt: load 319ms, verify 1039ms, opt 32ms
DexInv: --- END '/data/app/net.wapps.pop3-1.apk' (success) ---
Activities: anywheresoftware.b4a.objects.preferenceactivity net.wapps.pop3.main
Force stopping package net.wapps.pop3 uid=10037
move /data/dalvik-cache/data@[email protected]@classes.dex -> /data/dalvik-cache/data@[email protected]@classes.dex
New package installed in /data/app/net.wapps.pop3-1.apk
GC_FOR_MALLOC freed 12696 objects / 717664 bytes in 208ms
GC_EXPLICIT freed 5320 objects / 291336 bytes in 251ms
Shutting down VM
adbd disconnected
NOTE: attach of thread 'Binder Thread #3' failed
no available voice recognition services found

>>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
CheckJNI is ON
--- registering native functions ---
Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=net.wapps.pop3/.main }
Shutting down VM
adbd disconnected
NOTE: attach of thread 'Binder Thread #3' failed
Start proc net.wapps.pop3 for activity net.wapps.pop3/.main: pid=343 uid=10037 gids={3003}
** Activity (main) Create, isFirst = true **

GC_FOR_MALLOC freed 5946 objects / 362112 bytes in 177ms

** Activity (main) Resume **

Displayed activity net.wapps.pop3/.main: 4308 ms (total 4308 ms)

GC_EXPLICIT freed 729 objects / 53600 bytes in 435ms

Starting activity: Intent { flg=0x20000 cmp=net.wapps.pop3/anywheresoftware.b4a.objects.preferenceactivity (has extras) }

** Activity (main) Pause, UserClosed = false **

Shutting down VM

threadid=1: thread exiting with uncaught exception (group=0x4001d800)

GC_FOR_MALLOC freed 8306 objects / 493936 bytes in 141ms

FATAL EXCEPTION: main

java.lang.RuntimeException: Unable to start activity ComponentInfo{net.wapps.pop3/anywheresoftware.b4a.objects.preferenceactivity}: java.lang.ClassCastException: java.lang.String
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
at android.app.ActivityThread.access$2300(ActivityThread.java:125)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassCastException: java.lang.String

at android.app.ContextImpl$SharedPreferencesImpl.getBoolean(ContextImpl.java:2724)
at android.preference.Preference.getPersistedBoolean(Preference.java:1425)
at android.preference.CheckBoxPreference.onSetInitialValue(CheckBoxPreference.java:259)
at android.preference.Preference.dispatchSetInitialValue(Preference.java:1172)
at android.preference.Preference.onAttachedToHierarchy(Preference.java:984)
at android.preference.PreferenceGroup.addPreference(PreferenceGroup.java:156)
at anywheresoftware.b4a.objects.preferenceactivity$PreferenceCategoryWrapper.createPreference(preferenceactivity.java:278)
at anywheresoftware.b4a.objects.preferenceactivity$PreferenceScreenWrapper.createPreference(preferenceactivity.java:170)
at anywheresoftware.b4a.objects.preferenceactivity.onCreate(preferenceactivity.java:41)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
... 11 more
Force finishing activity net.wapps.pop3/anywheresoftware.b4a.objects.preferenceactivity

Force finishing activity net.wapps.pop3/.main

Activity pause timeout for HistoryRecord{44ff9488 net.wapps.pop3/anywheresoftware.b4a.objects.preferenceactivity}

Sending signal. PID: 343 SIG: 9

Process net.wapps.pop3 (pid 343) has died.

WIN DEATH: Window{4506f8e8 net.wapps.pop3/net.wapps.pop3.main paused=true}
Got RemoteException sending setActive(false) notification to pid 343 uid 10037

Activity destroy timeout for HistoryRecord{44f75f58 net.wapps.pop3/.main}

Activity destroy timeout for HistoryRecord{44ff9488 net.wapps.pop3/anywheresoftware.b4a.objects.preferenceactivity}
Hello Erel - Thank you for your reply. This is what appears in the unfiltered log.

Regards
 
Upvote 0

William Hunter

Active Member
Licensed User
Longtime User
Problem creating preferences screen

Hello Erel - I have taken the popup menu out of the mix in order to simplify things. However, I still get the same error. This is the new unfiltered error log:

>>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
CheckJNI is ON

--- registering native functions ---
GC_EXPLICIT freed 130 objects / 7184 bytes in 100ms
Scanning package: /data/app/vmdl44682.tmp
Removing non-system package:net.wapps.pop3
Force stopping package net.wapps.pop3 uid=10037
Scanning package net.wapps.pop3
Package net.wapps.pop3 codePath changed from /data/app/net.wapps.pop3-2.apk to /data/app/net.wapps.pop3-1.apk; Retaining data and using new
/data/app/net.wapps.pop3-1.apk changed; unpacking
DexInv: --- BEGIN '/data/app/net.wapps.pop3-1.apk' ---
DexOpt: load 308ms, verify 1082ms, opt 34ms
DexInv: --- END '/data/app/net.wapps.pop3-1.apk' (success) ---
Code path for pkg : net.wapps.pop3 changing from /data/app/net.wapps.pop3-2.apk to /data/app/net.wapps.pop3-1.apk
Resource path for pkg : net.wapps.pop3 changing from /data/app/net.wapps.pop3-2.apk to /data/app/net.wapps.pop3-1.apk
Activities: anywheresoftware.b4a.objects.preferenceactivity net.wapps.pop3.main
Force stopping package net.wapps.pop3 uid=10037
GC_FOR_MALLOC freed 9601 objects / 613344 bytes in 197ms
move /data/dalvik-cache/data@[email protected]@classes.dex -> /data/dalvik-cache/data@[email protected]@classes.dex
New package installed in /data/app/net.wapps.pop3-1.apk
Force stopping package net.wapps.pop3 uid=10037
GC_EXPLICIT freed 852 objects / 45968 bytes in 147ms
GC_EXPLICIT freed 6964 objects / 398368 bytes in 309ms
no available voice recognition services found
unlink /data/dalvik-cache/data@[email protected]@classes.dex
Shutting down VM
adbd disconnected
NOTE: attach of thread 'Binder Thread #3' failed

>>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
CheckJNI is ON
--- registering native functions ---
Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=net.wapps.pop3/.main }
Shutting down VM
adbd disconnected
Start proc net.wapps.pop3 for activity net.wapps.pop3/.main: pid=614 uid=10037 gids={3003}
NOTE: attach of thread 'Binder Thread #3' failed
request time failed: java.net.SocketException: Address family not supported by protocol

** Activity (main) Create, isFirst = true **

GC_FOR_MALLOC freed 7239 objects / 323472 bytes in 131ms

** Activity (main) Resume **

Displayed activity net.wapps.pop3/.main: 4413 ms (total 59967 ms)

Starting activity: Intent { flg=0x20000 cmp=net.wapps.pop3/anywheresoftware.b4a.objects.preferenceactivity (has extras) }

** Activity (main) Pause, UserClosed = false **

Shutting down VM

threadid=1: thread exiting with uncaught exception (group=0x4001d800)

FATAL EXCEPTION: main

java.lang.RuntimeException: Unable to start activity ComponentInfo{net.wapps.pop3/anywheresoftware.b4a.objects.preferenceactivity}: java.lang.ClassCastException: java.lang.String
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
at android.app.ActivityThread.access$2300(ActivityThread.java:125)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassCastException: java.lang.String

at android.app.ContextImpl$SharedPreferencesImpl.getBoolean(ContextImpl.java:2724)
at android.preference.Preference.getPersistedBoolean(Preference.java:1425)
at android.preference.CheckBoxPreference.onSetInitialValue(CheckBoxPreference.java:259)
at android.preference.Preference.dispatchSetInitialValue(Preference.java:1172)
at android.preference.Preference.onAttachedToHierarchy(Preference.java:984)
at android.preference.PreferenceGroup.addPreference(PreferenceGroup.java:156)
at anywheresoftware.b4a.objects.preferenceactivity$PreferenceCategoryWrapper.createPreference(preferenceactivity.java:278)
at anywheresoftware.b4a.objects.preferenceactivity$PreferenceScreenWrapper.createPreference(preferenceactivity.java:170)
at anywheresoftware.b4a.objects.preferenceactivity.onCreate(preferenceactivity.java:41)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
... 11 more
Force finishing activity net.wapps.pop3/anywheresoftware.b4a.objects.preferenceactivity

Force finishing activity net.wapps.pop3/.main
Activity pause timeout for HistoryRecord{45045a38 net.wapps.pop3/anywheresoftware.b4a.objects.preferenceactivity}

Sending signal. PID: 614 SIG: 9

Process net.wapps.pop3 (pid 614) has died.

WIN DEATH: Window{45042df0 net.wapps.pop3/net.wapps.pop3.main paused=true}
Got RemoteException sending setActive(false) notification to pid 614 uid 10037

Activity destroy timeout for HistoryRecord{44f33f30 net.wapps.pop3/.main}

Activity destroy timeout for HistoryRecord{45045a38 net.wapps.pop3/anywheresoftware.b4a.objects.preferenceactivity}

These are the Subs I am using:

Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
CreatePreferenceScreen
If SettingsManager.GetAll.Size = 0 Then SetDefaults
End If
Activity.LoadLayout("maintablet7")
End Sub

Sub CreatePreferenceScreen
SettingsScreen.Initialize("Settings", "")
'create one category
Dim cat1 As PreferenceCategory
cat1.Initialize("POP3 Settings")
cat1.AddEditText("edit1", "Server Address", "", "")
cat1.AddEditText("edit2", "User Name", "", "")
cat1.AddEditText("edit3", "Password", "", "")
cat1.AddCheckBox("check1", "Check to Use SSL", "", False)
'add the category to the settings screen
SettingsScreen.AddPreferenceCategory(cat1)
End Sub

Sub SetDefaults
'defaults are only set on the first run.
SettingsManager.SetString("edit1", "") ' ( replace empty strings with stored variables
SettingsManager.SetString("edit2", "") ' (
SettingsManager.SetString("edit3", "") ' (
SettingsManager.SetString("check1", "") ' (
'Return
End Sub

Sub settingsButton2_Click
StartActivity(SettingsScreen.CreateIntent)
End Sub

I look forward to your comments.
 
Upvote 0

William Hunter

Active Member
Licensed User
Longtime User
Problem creating preferences screen

This is the problem:
B4X:
SettingsManager.SetString("check1", "") '
You cannot put a string value in a checkbox.
Hello Erel - Thank you for your reply. I have corrected that error, which I should have seen. Unfortunately, I still get the same error. This is the new unfiltered error log:
>>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
CheckJNI is ON

--- registering native functions ---
GC_EXPLICIT freed 123 objects / 6520 bytes in 163ms
Scanning package: /data/app/vmdl22746.tmp
Removing non-system package:mail.purge
Force stopping package mail.purge uid=10037
Scanning package mail.purge
Package mail.purge codePath changed from /data/app/mail.purge-1.apk to /data/app/mail.purge-2.apk; Retaining data and using new
/data/app/mail.purge-2.apk changed; unpacking
DexInv: --- BEGIN '/data/app/mail.purge-2.apk' ---
DexOpt: load 311ms, verify 1090ms, opt 33ms
DexInv: --- END '/data/app/mail.purge-2.apk' (success) ---
Code path for pkg : mail.purge changing from /data/app/mail.purge-1.apk to /data/app/mail.purge-2.apk
Resource path for pkg : mail.purge changing from /data/app/mail.purge-1.apk to /data/app/mail.purge-2.apk
Activities: anywheresoftware.b4a.objects.preferenceactivity mail.purge.main
Force stopping package mail.purge uid=10037
move /data/dalvik-cache/data@[email protected]@classes.dex -> /data/dalvik-cache/data@[email protected]@classes.dex
New package installed in /data/app/mail.purge-2.apk
Force stopping package mail.purge uid=10037
GC_EXPLICIT freed 10392 objects / 689920 bytes in 346ms
GC_EXPLICIT freed 122 objects / 4600 bytes in 250ms
no available voice recognition services found
GC_EXPLICIT freed 4671 objects / 255208 bytes in 248ms
unlink /data/dalvik-cache/data@[email protected]@classes.dex
Shutting down VM
adbd disconnected
NOTE: attach of thread 'Binder Thread #3' failed

>>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
CheckJNI is ON
--- registering native functions ---
Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=mail.purge/.main }
Shutting down VM
adbd disconnected
NOTE: attach of thread 'Binder Thread #3' failed
Start proc mail.purge for activity mail.purge/.main: pid=754 uid=10037 gids={3003}

** Activity (main) Create, isFirst = true **

GC_FOR_MALLOC freed 7270 objects / 327368 bytes in 128ms

** Activity (main) Resume **

Displayed activity mail.purge/.main: 4089 ms (total 4089 ms)

Starting activity: Intent { flg=0x20000 cmp=mail.purge/anywheresoftware.b4a.objects.preferenceactivity (has extras) }

** Activity (main) Pause, UserClosed = false **

Shutting down VM

threadid=1: thread exiting with uncaught exception (group=0x4001d800)

FATAL EXCEPTION: main

java.lang.RuntimeException: Unable to start activity ComponentInfo{mail.purge/anywheresoftware.b4a.objects.preferenceactivity}: java.lang.ClassCastException: java.lang.String
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
at android.app.ActivityThread.access$2300(ActivityThread.java:125)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassCastException: java.lang.String

at android.app.ContextImpl$SharedPreferencesImpl.getBoolean(ContextImpl.java:2724)
at android.preference.Preference.getPersistedBoolean(Preference.java:1425)
at android.preference.CheckBoxPreference.onSetInitialValue(CheckBoxPreference.java:259)
at android.preference.Preference.dispatchSetInitialValue(Preference.java:1172)
at android.preference.Preference.onAttachedToHierarchy(Preference.java:984)
at android.preference.PreferenceGroup.addPreference(PreferenceGroup.java:156)
at anywheresoftware.b4a.objects.preferenceactivity$PreferenceCategoryWrapper.createPreference(preferenceactivity.java:278)
at anywheresoftware.b4a.objects.preferenceactivity$PreferenceScreenWrapper.createPreference(preferenceactivity.java:170)
at anywheresoftware.b4a.objects.preferenceactivity.onCreate(preferenceactivity.java:41)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
... 11 more
Force finishing activity mail.purge/anywheresoftware.b4a.objects.preferenceactivity

Force finishing activity mail.purge/.main
Activity pause timeout for HistoryRecord{45002380 mail.purge/anywheresoftware.b4a.objects.preferenceactivity}

Sending signal. PID: 754 SIG: 9

Process mail.purge (pid 754) has died.

WIN DEATH: Window{45071748 mail.purge/mail.purge.main paused=true}
Got RemoteException sending setActive(false) notification to pid 754 uid 10037

GC_EXPLICIT freed 151 objects / 11096 bytes in 201ms

Activity destroy timeout for HistoryRecord{44ff8fa8 mail.purge/.main}

Activity destroy timeout for HistoryRecord{45002380 mail.purge/anywheresoftware.b4a.objects.preferenceactivity}

GC_EXPLICIT freed 67 objects / 3096 bytes in 107ms

request time failed: java.net.SocketException: Address family not supported by protocol
I have redone my subs and I can't see any error. These are my subs:
Sub CreatePreferenceScreen
SettingsScreen.Initialize("Settings", "")
'create one category
Dim cat1 As PreferenceCategory
cat1.Initialize("POP3 Settings")
cat1.AddEditText("edit1", "Server Address", "", "pop.server.add") ' ( replace end strings with empty strings
cat1.AddEditText("edit2", "User Name", "", "UserName") ' (
cat1.AddEditText("edit3", "Password", "", "password") ' (
cat1.AddCheckBox("check1", "Check to Use SSL", "", False)
'add the category to the settings screen
SettingsScreen.AddPreferenceCategory(cat1)
End Sub

Sub SetDefaults
'defaults are only set on the first run.
SettingsManager.SetString("edit1", "pop.server.add") ' ( replace end strings with stored variables
SettingsManager.SetString("edit2", "UserName") ' (
SettingsManager.SetString("edit3", "password") ' (
SettingsManager.SetBoolean("check1", False)
End Sub

Sub settingsButton2_Click
StartActivity(SettingsScreen.CreateIntent)
End Sub
:BangHead: I don't like having to post this again, but I've looked long and hard to see what I might have done wrong, and still can't find an error. I look forward to your reply.

Best regards
 
Upvote 0

William Hunter

Active Member
Licensed User
Longtime User
Problem creating preferences screen

I guess that the problem is that the value is already stored as string. Try to uninstall the program from the phone and then install it again.
Hello Erel – You were correct in your suggestion. I simply had to clear the data and uninstall the program from the emulator. I wasn’t aware that a certain level of housekeeping was required. :signOops: I learn something new every day, and will now do my housekeeping chores on a regular and frequent basis.

Thank you for the assistance.
 
Upvote 0
Top