Announcement

Collapse
No announcement yet.

Java unhandled exception error

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Gary Beene
    replied
    Hi Jose!
    If you insist in using code from the dark ages and ignore all the improvements
    Personally, I prefer light bulbs over candles for illumination - so bring me on into the modern age!

    If I didn't comment on your other post, it was because my search never turned up the post! Thanks for the link.

    BTW, I just went looking for your newer post to see how I missed it. Searching for "Web Browser Example", your post wasn't included in the 20 page search results! I got the same result in a few other searches.

    In the post you gave me the link to, you were logged in as a "Guest". I wonder if that was affected my search?
    Unfortunately, nobody seems to read it and always copy the version of post #1
    Going to try out the newer version right now!

    Leave a comment:


  • José Roca
    replied
    The first version is to be used with PB 7 only. The modified version can be used with 8+. With PB 9 and 10 it should be not used at all because much better options are available.

    I wrote it to allow the mix of Automation and low-level COM. It was the only way at that time, but since PB 9 and 10 have native direct interface calls, to continue using these now archaic workarounds is like throwing all the work done in the last 8 years to improve the compilers by the board.

    Anyway, it's not my business which code will be used by someone else, but I wanted to warn Gary that he was using the wrong version.

    Leave a comment:


  • Knuth Konrad
    replied
    Hi José,

    Originally posted by José Roca View Post
    Two years later, I posted a correct version for compiler 8+. See post #6 i this thread: http://www.powerbasic.com/support/pb...tlMakeDispatch

    Unforunately, nobody seems to read it and always copy the version of post #1.
    You wrote "I changed my password and I'm not longer allowed to edit my original post." in post #8.

    A suggestion: PM the forum admin and ask him to replace the code in #1 with the one in #8 so that this doesn't happen anymore.

    Leave a comment:


  • José Roca
    replied
    Hi Gary,

    If you insist in using code from the dark ages and ignore all the improvements made in the last eight years, be at least aware that the AtlMakeDispatch procedure, that I wrote in 2003, was intentionally wrong to workaround a bug in PB 7.0.

    Two years later, I posted a correct version for compiler 8+. See post #6 i this thread: http://www.powerbasic.com/support/pb...tlMakeDispatch

    Unforunately, nobody seems to read it and always copy the version of post #1.

    To read the text, you need to geet a reference to the IHTMLDocument3 interface and then to the IHTMLElement interface (both in the MTHML component) and call the method innerText. Search for innetHTML in the forum to find some old code.

    If you want to try a more modern approach, try this (don't click the "Get text" button until the page has been loaded):

    Code:
    #COMPILE EXE
    #DIM ALL
    %UNICODE = 1
    
    ' // Include files for external files
    %USEWEBBROWSER = 1            ' // Use the WebBrowser control
    #INCLUDE ONCE "CWindow.inc"   ' // CWindow class
    
    ' // Identifier
    %IDC_WEBBROWSER = 101
    
    ' ########################################################################################
    ' Main
    ' ########################################################################################
    FUNCTION WinMain (BYVAL hInstance AS DWORD, BYVAL hPrevInstance AS DWORD, BYVAL lpszCmdLine AS WSTRINGZ PTR, BYVAL nCmdShow AS LONG) AS LONG
    
       ' // Set process DPI aware
    '   SetProcessDPIAware
    
       ' // Create an instance of the class
       LOCAL pWindow AS IWindow
       pWindow = CLASS "CWindow"
       IF ISNOTHING(pWindow) THEN EXIT FUNCTION
    
       ' // Create the main window
       pWindow.CreateWindow(%NULL, "WebBrowser Template", 0, 0, 0, 0, 0, 0, CODEPTR(WindowProc))
       ' // Set the client siz
       pWindow.SetClientSize 600, 400
       ' // Center the window
       pWindow.CenterWindow
    
       ' // Add a WebBrowser control
       LOCAL hCtl AS DWORD
       LOCAL bstrURL AS WSTRING
       bstrURL = "http://www.powerbasic.com/support/pbforums/"
       hCtl = pWindow.AddWebBrowserControl(pWindow.hwnd, %IDC_WEBBROWSER, bstrURL, NOTHING, 0, 0, pWindow.ClientWidth, pWindow.ClientHeight)
    
       ' // Add a button
       pWindow.AddButton(pWindow.hwnd, %IDOK, "Get text", 0, 0, 0, 0)
    
       ' // Default message pump (you can replace it with your own)
       pWindow.DoEvents(nCmdShow)
    
    END FUNCTION
    ' ########################################################################################
    
    ' ========================================================================================
    ' Main callback function.
    ' ========================================================================================
    FUNCTION WindowProc (BYVAL hwnd AS DWORD, BYVAL uMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG
    
       STATIC pWindow AS IWindow        ' // Reference to the IWindow interface
    
       SELECT CASE uMsg
    
          CASE %WM_CREATE
             ' // Get a reference to the IWindow interface from the CREATESTRUCT structure
             pWindow = CWindow_GetObjectFromCreateStruct(lParam)
             EXIT FUNCTION
    
          CASE %WM_SYSCOMMAND
             ' // Capture this message and send a WM_CLOSE message
             ' // Note: Needed with some OCXs, that otherwise remain in memory
             IF (wParam AND &HFFF0) = %SC_CLOSE THEN
                SendMessage hwnd, %WM_CLOSE, 0, 0
                EXIT FUNCTION
             END IF
    
          CASE %WM_COMMAND
             SELECT CASE LO(WORD, wParam)
                CASE %IDCANCEL
                   ' // If the Escape key has been pressed...
                   IF HI(WORD, wParam) = %BN_CLICKED THEN
                      ' // ... close the application by sending a WM_CLOSE message
                      SendMessage hwnd, %WM_CLOSE, 0, 0
                      EXIT FUNCTION
                   END IF
    
                CASE %IDOK  ' // Get the text
                   LOCAL pWB AS IWebBrowser2
                   pWB = OC_GetDispatch(GetDlgItem(hwnd, %IDC_WEBBROWSER))
                   IF ISOBJECT(pWB) THEN
                      LOCAL pDoc AS IHTMLDocument3
                      pDoc = pWB.Document
                      IF ISOBJECT(pDoc) THEN
                         LOCAL pElement AS IHTMLElement
                         pElement = pDoc.documentElement
                         ? pElement.innerText
                      END IF
                   END IF
    
             END SELECT
    
          CASE %WM_SIZE
             IF wParam <> %SIZE_MINIMIZED THEN
                ' // Resize the control
                pWindow.MoveWindow GetDlgItem(hwnd, %IDC_WEBBROWSER), 0, 0, pWindow.ClientWidth, pWindow.ClientHeight - 50, %TRUE
                pWindow.MoveWindow GetDlgItem(hwnd, %IDOK), pWindow.ClientWidth - 100, pWindow.ClientHeight - 35, 70, 23, %TRUE
             END IF
    
          CASE %WM_DESTROY
             ' // End the application
             PostQuitMessage 0
             EXIT FUNCTION
    
       END SELECT
    
       ' // Pass unprocessed messages to Windows
       FUNCTION = DefWindowProc(hwnd, uMsg, wParam, lParam)
    
    END FUNCTION
    ' ========================================================================================
    BTW you can find several WebBrowser examples in my forum.
    Last edited by José Roca; 6 Oct 2011, 09:52 PM.

    Leave a comment:


  • Gary Beene
    replied
    Looking at the code in post #2 again bring to mind the question of where I can find the exposed methods of the control.

    It would be too simple if it was like this:
    Code:
    oOCX.selectall
    oOCX.copy
    Now I'm getting an even better reason to work with objects. I'm guessing my PB COM browser will rescue me here? I'll go look!

    Leave a comment:


  • Gary Beene
    replied
    A browser in my app is way cool. I don't know why I haven't done more with it so far, but I will ... but to my question ...

    With a URL displayed, as with the code from Jose up in post#2, can I capture all the displayed text? That would be most useful in one of my apps.

    I don't know enough about the technique to know if there's a simple method or two that will do the trick. I don't care about maintaining formatting.

    I could download the *.htm file and try to parse out the HTML stuff, but it would seem like that smart thing to do to let the browser control do it for me, and just work with the results.

    I'll go look into it, but I thought someone more familiar with the code might have a ready-at-hand solution!

    ... added ... if there are no built-in methods to the browser control, then programmatically sending Ctrl-A and then Ctrl-C to the browser control would be just fine too. Heck, I might even be able to figure out that one!
    Last edited by Gary Beene; 6 Oct 2011, 03:33 PM.

    Leave a comment:


  • Paul Franks
    replied
    Originally posted by Mike Doty:

    java/lang/NoSuchMethodError was not handled.
    Would you like to debug the application?
    Wouldn't worry too much about Java Applets not working - it's pretty
    much a dead technology, for a couple of reasons: 1. Flash players are
    installed in something like 97% of desktop browsers, vs. a far smaller
    percentage with the JRE installed. 2. The JRE still takes forever
    to load and start an applet running, while Flash applets start up
    almost instantly. 99.999% of those irritating animated ads on the
    web are using your Flash player.

    Now, if you're talking cell phones or app servers, Java is pervasive, just
    not on the desktop.


    ------------------

    --pdf

    Leave a comment:


  • Mike Doty
    replied
    'great. i need to leave (really great code.)
    'project for the week! a web browser with printing/preview and within ddt!
    'looks like some of you already have it! ''
    '
    'definitely start another thread (if you would.)'
    'i've got the code combined, but not working yet.
    '
    'mike

    'found this one that already prints, but doesn't take a url as is. http://www.powerbasic.com/support/pb...ad.php?t=24065




    [this message has been edited by mike doty (edited june 24, 2007).]

    Leave a comment:


  • Brad D Byrne
    replied
    hehe, yeah Mike, I knew this all looked pretty familar,

    most of that code is on an old machine, I'll try to dig it out tonight
    after I get some pressing work done, I'm glad you re-opened this topic
    it's actually good timing for me, I was into a web interface I wasn't
    sure how to handle!

    ------------------
    Washington DC Area
    Borje's "Poff's" is likely the BEST tool for learning PB.. http://www.reonis.com/POFFS/index.htm
    And a few PBTool's & Beginner Help:http://sweetheartgames.com/PBTools/JumpStart.html
    & Another Good Resource: http://www.fredshack.com/docs/powerbasic.html

    Leave a comment:


  • Mike Doty
    replied
    here is how to print: http://www.powerbasic.com/support/pb...ad.php?t=24237

    'now need to piece them together

    ------------------

    Leave a comment:


  • Mike Doty
    replied
    brad,
    if this is you, looks like you have been this route for printing. http://www.powerbasic.com/support/pb...ad.php?t=24222

    ------------------

    Leave a comment:


  • Mike Doty
    replied
    There was a recent Java update recently which I was required to
    install. The animation does play within IE7 browser.
    I'm updating Java on an older Windows 98 SE machine, now.
    There is a option to verify now to see the current Java version.

    Followed update instruction and found no option in browser for
    Java2 within Windows 98 SE. Looked in XP with IE7 and find
    no option for Java2 there, either.

    ------------------


    [This message has been edited by Mike Doty (edited June 24, 2007).]

    Leave a comment:


  • Brad D Byrne
    replied
    hmmm, I take that back, the code must still be using my IE7 that I have
    installed, because if I simply open http://java.com/en/dukeszone/ in the Firefox browser itself the animation doesn't play

    ------------------
    Washington DC Area
    Borje's "Poff's" is likely the BEST tool for learning PB.. http://www.reonis.com/POFFS/index.htm
    And a few PBTool's & Beginner Help:http://sweetheartgames.com/PBTools/JumpStart.html
    & Another Good Resource: http://www.fredshack.com/docs/powerbasic.html

    Leave a comment:


  • Mike Doty
    replied
    Thanks, Brad. Duke said "Hi", then.
    It works with the IE7 browswer here, but not the PB code.
    Again, trivial compared to getting printing capability.


    ------------------

    Leave a comment:


  • Brad D Byrne
    replied
    Mike the animations work here,

    I have default browser

    Firefox/1.5.0.12

    XP pro, 2002, service pak 2

    ------------------
    Washington DC Area
    Borje's "Poff's" is likely the BEST tool for learning PB.. http://www.reonis.com/POFFS/index.htm
    And a few PBTool's & Beginner Help:http://sweetheartgames.com/PBTools/JumpStart.html
    & Another Good Resource: http://www.fredshack.com/docs/powerbasic.html

    Leave a comment:


  • Mike Doty
    replied
    I'm adding new items to wish list, now.
    Hope others see this code.

    Code:
    'To do list:
    '1 Print button
    '    With printing all internet and local documents right here
    '    with the benefit of images within html documents!
    '
    '2 Refresh button
    '3 Stop button
    '
    'Down the road:
    '4 Get to work in PbForms
    '5 Add html editing
    '6 Add upload capability
    'With the above you could download/upload and display on-the-fly to anyone in the world!
    ------------------




    [This message has been edited by Mike Doty (edited June 24, 2007).]

    Leave a comment:


  • Brad D Byrne
    replied
    TOOOO COOOOOL!!!

    I Love IT!! I am posting this thru the program!

    I'll check the Java site,

    Thanks! Mike & Jose

    ------------------
    Washington DC Area
    Borje's "Poff's" is likely the BEST tool for learning PB.. http://www.reonis.com/POFFS/index.htm
    And a few PBTool's & Beginner Help:http://sweetheartgames.com/PBTools/JumpStart.html
    & Another Good Resource: http://www.fredshack.com/docs/powerbasic.html

    Leave a comment:


  • Mike Doty
    replied
    'Heck, it isn't that much code and it is a must see!
    '
    Code:
    'To do list:
    '1 Print button
    '    With printing all internet and local documents right here
    '    with the benefit of images within html documents!
    '
    '2 Refresh button
    '3 Stop button
    '
    '4 Get to work in PbForms
    '5 Add html editing (a whole new subject)
    '6 Add upload capability
    'With the above you could download/upload and display on-the-fly!
    '
    'Help system could also be written using html and used with this.
    'Internet documents and local documents available easily.
    '
    '
    'Is ATL.DLL present in all versions of Windows? Works with Windows 98, too.

    'A browser within DDT, wow!
    '
    '***********************************************************
    'This is the most valuable code I've seen in a long time.
    '***********************************************************
    'Code by Jose Roca (of course.)
    Code:
    '
    '
    'New version of the first example. I have made the dialog modeless to
    'be able to pass the keystrokes to the WebBrowser control for processing,
    'otherwise the main dialog will eat them and shortcuts like Ctrl-C
    'won't work.
    
      #DIM ALL
      #INCLUDE "win32api.inc"
    
      %WM_FORWARDMSG = &H37F ' (895)
    
      %ID_OCX     = 1001
      %IDC_URL    = 1010
      %IDC_BTNAVG = 1011
      %IDC_BTBACK = 1012
      %IDC_BTFRWD = 1013
      %IDC_LABEL1 = 1014
    
      GLOBAL hDlg AS DWORD
      GLOBAL hOcx AS DWORD
      GLOBAL oOcx AS DISPATCH
    
    
      DECLARE FUNCTION AtlAxWinInit LIB "ATL.DLL" ALIAS "AtlAxWinInit" () AS LONG
    ' *********************************************************************************************
      DECLARE FUNCTION AtlAxWinTerm () AS LONG
    ' *********************************************************************************************
      FUNCTION AtlAxWinTerm () AS LONG
        UnregisterClass ("AtlAxWin", GetModuleHandle(BYVAL %NULL))
      END FUNCTION
    ' *********************************************************************************************
    ' **********************************************************************************************
      DECLARE FUNCTION AtlAxGetControl LIB "ATL.DLL" ALIAS "AtlAxGetControl" _
         ( _
         BYVAL hWnd AS DWORD, _   ' [in] A handle to the window that is hosting the control.
         BYREF pp AS DWORD _      ' [out] The IUnknown of the control being hosted.
      ) AS DWORD
    ' *********************************************************************************************
    
    ' *********************************************************************************************
    ' Puts the address of an object in a variant and marks it as containing a dispatch variable
    ' *********************************************************************************************
      SUB AtlMakeDispatch ( _
         BYVAL lpObj AS DWORD, _                        ' Address of the object instance
         BYREF vObj AS VARIANT _                        ' Variant to contain this address
         ) EXPORT
    
         LOCAL lpvObj AS VARIANTAPI PTR                 ' Pointer to a VARIANTAPI structure
         LET vObj = EMPTY                               ' Make sure is empty to avoid memory leaks
         lpvObj = VARPTR(vObj)                          ' Get the VARIANT address
         @lpvObj.vt = %VT_DISPATCH                      ' Mark it as containing a dispatch variable
         @lpvObj.vd.pdispVal = lpObj                    ' Set the dispatch pointer address
    
      END SUB
    ' *********************************************************************************************
    
    ' *********************************************************************************************
    ' Main dialog callback
    ' *********************************************************************************************
      CALLBACK FUNCTION MainDlgProc()
    
         LOCAL rc AS RECT
         LOCAL r AS LONG
         LOCAL x AS LONG
         LOCAL y AS LONG
         LOCAL xx AS LONG
         LOCAL yy AS LONG
    
    
         SELECT CASE CBMSG
    
            CASE %WM_SIZE
               GetClientRect CBHNDL, rc
               x = rc.nLeft
               y = rc.nTop
               xx = rc.nRight - rc.nLeft
               yy = rc.nBottom - rc.nTop - 32
               MoveWindow hOcx, x, y, xx, yy, %TRUE
    
            CASE %WM_DESTROY
               PostQuitMessage 0
    
            CASE %WM_COMMAND
               SELECT CASE CBCTL
                  CASE %IDCANCEL
                     IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                        DIALOG END CBHNDL, 0
                     END IF
                  CASE %IDC_BTNAVG
                     IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                        LOCAL strUrl AS STRING, vVar AS VARIANT
                        CONTROL GET TEXT CBHNDL, %IDC_URL TO strUrl
                        vVar = strUrl
                        OBJECT CALL oOcx.Navigate(vVar)
                     END IF
                  CASE %IDC_BTBACK
                     IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                        OBJECT CALL oOcx.GoBack
                     END IF
                  CASE %IDC_BTFRWD
                     IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                        OBJECT CALL oOcx.GoForward
                     END IF
               END SELECT
    
         END SELECT
    
      END FUNCTION
    ' *********************************************************************************************
    
    ' *********************************************************************************************
    ' Main
    ' *********************************************************************************************
      FUNCTION PBMAIN
    
         LOCAL hInst AS DWORD
         LOCAL hr AS DWORD
         LOCAL OcxName AS ASCIIZ * 255
         LOCAL pUnk AS DWORD
         LOCAL vVar AS VARIANT
         LOCAL uMsg AS tagMsg
         LOCAL dwCookie AS DWORD
    
         OcxName = "Shell.Explorer"
    
         AtlAxWinInit   ' // Initializes ATL
    
         DIALOG NEW 0, "A Web Browser in a DDT dialog",,, 528, 334, %WS_OVERLAPPEDWINDOW, 0 TO hDlg
         CONTROL ADD "AtlAxWin", hDlg, %ID_OCX, OcxName, 0, 0, 0, 0, %WS_VISIBLE OR %WS_CHILD
         CONTROL HANDLE hDlg, %ID_OCX TO hOcx
         CONTROL ADD LABEL, hDlg, %IDC_LABEL1, "URL", 226, 322, 16, 12
         CONTROL ADD TEXTBOX, hDlg, %IDC_URL, "", 250, 320, 210, 14
         CONTROL ADD BUTTON, hDlg, %IDC_BTNAVG, "&Navigate", 470, 320, 46, 14, %WS_TABSTOP OR %BS_DEFAULT
         CONTROL ADD BUTTON, hDlg, %IDC_BTBACK, "&Back", 5, 320, 46, 14, %WS_TABSTOP
         CONTROL ADD BUTTON, hDlg, %IDC_BTFRWD, "&Forward", 58, 320, 46, 14, %WS_TABSTOP
         CONTROL SET TEXT hDlg, %IDC_URL, "http://www.java.com"
    
         AtlAxGetControl(hOcx, pUnk)
         AtlMakeDispatch(pUnk, vVar)
         SET oOcx = vVar
    
         SetFocus(hOcx)
         DIALOG SHOW MODELESS hDlg, CALL MainDlgProc TO hr
    
         WHILE GetMessage(uMsg, %NULL, 0, 0)
            '// Pass keyboard messages to the ancestor
            '// Returns 0 if the message was not processed, nonzero if it was
            IF SendMessage(hOcx, %WM_FORWARDMSG, 0, VARPTR(uMsg)) = 0 THEN
               IF IsDialogMessage(hDlg, uMsg) = %FALSE THEN
                  TranslateMessage uMsg
                  DispatchMessage uMsg
               END IF
            END IF
         WEND
    
         AtlAxWinTerm   ' // Uninitializes ATL
         SET oOcx = NOTHING
    
      END FUNCTION
    ' *********************************************************************************************

    ------------------




    [This message has been edited by Mike Doty (edited June 24, 2007).]

    Leave a comment:


  • Mike Doty
    started a topic Java unhandled exception error

    Java unhandled exception error

    '***********************************************
    'The code below is a MUST see
    'Forget about the java error and see the code!
    '***********************************************


    java/lang/NoSuchMethodError was not handled.
    Would you like to debug the application?

    Tried calling browser using VB6 and get same error.


    The error occurs by visiting http://www.java.com
    Click on Dukes Zone
    Error occurs when Duke's little animation window attempts to animate.


    The error doe not occur using IE7.

    Just tested using Windows 98SE and it works.
    Animation doesn't display, but no java exception error to debug.

    The error doe not occur using IE6.

    This error is trivial compared to adding printing support.




    [This message has been edited by Mike Doty (edited June 24, 2007).]
Working...
X
😀
🥰
🤢
😎
😡
👍
👎