Android Question CastException PrefencesDialog

Cosmo

Member
Hi all,

when I try to use a PreferencesDialog like this:


B4X:
Private Sub Prefs_Click
    Public pfdialog As PreferencesDialog

    pfdialog.Initialize(Me,"Prefs", 300, 300)
    pfdialog.LoadFromJson(File.ReadString(File.DirAssets,"prefs.json"))
    Dim Data As Map = CreateMap()
    Wait For (pfdialog.ShowDialog(Data, "OK", "CANCEL")) Complete (Result As Int)
    If Result = xui.DialogResponse_Positive Then
'
    End If

End Sub

I get a Exception

b4xdialog$ResumableSub_ShowCustomresume (java line: 613)
java.lang.ClassCastException: java.lang.Class cannot be cast to android.view.View
at anywheresoftware.b4a.objects.B4XViewWrapper.getViewObject(B4XViewWrapper.java:104)
at anywheresoftware.b4a.objects.B4XViewWrapper.asPanelWrapper(B4XViewWrapper.java:107)
at anywheresoftware.b4a.objects.B4XViewWrapper.GetAllViewsRecursive(B4XViewWrapper.java:322)
at Cirrus7Papierbestand.app.b4xdialog$ResumableSub_ShowCustom.resume(b4xdialog.java:613)
at Cirrus7Papierbestand.app.b4xdialog._showcustom(b4xdialog.java:553)
at Cirrus7Papierbestand.app.b4xdialog$ResumableSub_ShowTemplate.resume(b4xdialog.java:1126)
at Cirrus7Papierbestand.app.b4xdialog._showtemplate(b4xdialog.java:1090)
at Cirrus7Papierbestand.app.preferencesdialog$ResumableSub_ShowDialog.resume(preferencesdialog.java:2007)
at Cirrus7Papierbestand.app.preferencesdialog._showdialog(preferencesdialog.java:1819)
at Cirrus7Papierbestand.app.main$ResumableSub_Prefs_Click.resume(main.java:627)
at Cirrus7Papierbestand.app.main._prefs_click(main.java:595)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:221)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:205)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:6897)
at android.widget.TextView.performClick(TextView.java:12727)
at android.view.View$PerformClick.run(View.java:26101)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6944)
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)


Any suggestions whats going wrong?

Thanks in advance!
Bernhard
 
Solution
what should Root be? A B4XView? How to initialize?
If you are using a B4XPages project, you use something like this:
B4X:
Private pfdialog As PreferencesDialog  'in class_globals sub
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
pfdialog.Initialize(Root,"Prefs", 300dip, 300dip)

And if you are using the classic type of project:
B4X:
Private pfdialog As PreferencesDialog  'in globals sub
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("1")  'or whatever your layout is
pfdialog.Initialize(Activity,"Prefs", 300dip, 300dip)

Mahares

Expert
Licensed User
Longtime User
what should Root be? A B4XView? How to initialize?
If you are using a B4XPages project, you use something like this:
B4X:
Private pfdialog As PreferencesDialog  'in class_globals sub
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
pfdialog.Initialize(Root,"Prefs", 300dip, 300dip)

And if you are using the classic type of project:
B4X:
Private pfdialog As PreferencesDialog  'in globals sub
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("1")  'or whatever your layout is
pfdialog.Initialize(Activity,"Prefs", 300dip, 300dip)
 
Upvote 0
Solution
Top