Dukascopy
 
 
Wiki JStore Search Login

Attention! Read the forum rules carefully before posting a topic.

    Submit JForex API bug reports in this forum only.
    Submit Converter issues in Converter Issues.
    Off topics are strictly forbidden.

Any topics which do not satisfy these rules will be deleted.

NPE with IChartPanelMouseListener in chart
 Post subject: NPE with IChartPanelMouseListener in chart Post rating: 0   New post Posted: Tue 04 Oct, 2016, 21:25 
User avatar

User rating: 0
Joined: Fri 18 Sep, 2015, 14:32
Posts: 15
Location: Germany, Dresden
I used the MainOpenChart.java (https://www.dukascopy.com/wiki/#IClient_functionality) and added an IChartPanelMouseListener. (The additional code I show at the end of this post. The whole source code you'll find in the attachement.

maven dependencies:

      <dependency>
         <groupId>com.dukascopy.dds2</groupId>
         <artifactId>DDS2-jClient-JForex</artifactId>
         <!-- find the latest available version here: https://www.dukascopy.com/client/jforexlib/publicrepo/com/dukascopy/dds2/DDS2-jClient-JForex/ -->
         <version>2.45.52</version>
         <exclusions>
            <exclusion>
               <groupId>org.slf4j</groupId>
               <artifactId>slf4j-jdk14</artifactId>
            </exclusion>
         </exclusions>
      </dependency>
      <!-- find the latest available version here: https://www.dukascopy.com/client/jforexlib/publicrepo/com/dukascopy/api/JForex-API/ -->
      <dependency>
         <groupId>com.dukascopy.api</groupId>
         <artifactId>JForex-API</artifactId>
         <version>2.12.41</version>
         <classifier>sources</classifier>
      </dependency>


I also tested this in my own implementations, where the same exception happened.

It seems only to happen with the live chart -> ClientFactory.getDefaultInstance()

It works perfectly if a backtest is running -> TesterFactory.getDefaultInstance()

The NPE:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
   at com.dukascopy.charts.wrapper.StrategyThreadDelegatableMouseListener.mouseEntered(StrategyThreadDelegatableMouseListener.java:69)
   at com.dukascopy.charts.view.swing.AbstractChartPanelView$1.mouseEntered(AbstractChartPanelView.java:127)
   at java.awt.AWTEventMulticaster.mouseEntered(AWTEventMulticaster.java:300)
   at java.awt.Component.processMouseEvent(Component.java:6544)
   at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
   at java.awt.Component.processEvent(Component.java:6300)
   at java.awt.Container.processEvent(Container.java:2236)
   at java.awt.Component.dispatchEventImpl(Component.java:4891)
   at java.awt.Container.dispatchEventImpl(Container.java:2294)
   at java.awt.Component.dispatchEvent(Component.java:4713)
   at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4888)
   at java.awt.LightweightDispatcher.retargetMouseEnterExit(Container.java:4676)
   at java.awt.LightweightDispatcher.trackMouseEnterExit(Container.java:4654)
   at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4505)
   at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4466)
   at java.awt.Container.dispatchEventImpl(Container.java:2280)
   at java.awt.Window.dispatchEventImpl(Window.java:2750)
   at java.awt.Component.dispatchEvent(Component.java:4713)
   at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
   at java.awt.EventQueue.access$500(EventQueue.java:97)
   at java.awt.EventQueue$3.run(EventQueue.java:709)
   at java.awt.EventQueue$3.run(EventQueue.java:703)
   at java.security.AccessController.doPrivileged(Native Method)
   at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
   at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
   at java.awt.EventQueue$4.run(EventQueue.java:731)
   at java.awt.EventQueue$4.run(EventQueue.java:729)
   at java.security.AccessController.doPrivileged(Native Method)
   at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
   at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
   at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
   at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
   at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
   at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
   at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
   at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)


Sourcecode:
      // open charts
      for (Instrument instrument : instrArr) {
         IFeedDescriptor feedDescriptor = new TicksFeedDescriptor(instrument);
         feedDescriptor.setOfferSide(OfferSide.BID);// need to set due to
                                          // platform requirements
         IChart chart = client.openChart(feedDescriptor);
         chart.addMouseListener(false, new IChartPanelMouseListener() {
            
            @Override
            public void mouseReleased(IChartPanelMouseEvent e) {
               // TODO Auto-generated method stub
               
            }
            
            @Override
            public void mousePressed(IChartPanelMouseEvent e) {
               // TODO Auto-generated method stub
               
            }
            
            @Override
            public void mouseMoved(IChartPanelMouseEvent e) {
               // TODO Auto-generated method stub
               
            }
            
            @Override
            public void mouseExited(IChartPanelMouseEvent e) {
               // TODO Auto-generated method stub
               
            }
            
            @Override
            public void mouseEntered(IChartPanelMouseEvent e) {
               // TODO Auto-generated method stub
               
            }
            
            @Override
            public void mouseDragged(IChartPanelMouseEvent e) {
               // TODO Auto-generated method stub
               
            }
            
            @Override
            public void mouseClicked(IChartPanelMouseEvent e) {
               // TODO Auto-generated method stub
               
            }
         });
         final IClientGUI clientGUI = client.getClientGUI(chart);
         SwingUtilities.invokeLater(new Runnable() {
            public void run() {
               ChartFrame frame = new ChartFrame(clientGUI, client.getSubscribedInstruments());
               chartFrameMap.put(clientGUI.getChart(), frame);
               // Handle manual close - we need to call IClient.closeChart
               // for strategy to know that the chart is no more there
               frame.addWindowListener(new WindowAdapter() {
                  public void windowClosing(WindowEvent e) {
                     LOGGER.info("Chart manually closed, removing the chart from the strategy context");
                     client.closeChart(clientGUI.getChart());
                     chartFrameMap.remove(clientGUI.getChart());
                     if (chartFrameMap.isEmpty()) {
                        LOGGER.info("All charts closed, stopping the program");
                        System.exit(0);
                     }
                  }
               });
            }
         });
      }


Attachments:
MainOpenChart.java [16.65 KiB]
Downloaded 235 times
DISCLAIMER: Dukascopy Bank SA's waiver of responsability - Documents, data or information available on this webpage may be posted by third parties without Dukascopy Bank SA being obliged to make any control on their content. Anyone accessing this webpage and downloading or otherwise making use of any document, data or information found on this webpage shall do it on his/her own risks without any recourse against Dukascopy Bank SA in relation thereto or for any consequences arising to him/her or any third party from the use and/or reliance on any document, data or information found on this webpage.
 
 Post subject: Re: NPE with IChartPanelMouseListener in chart Post rating: 0   New post Posted: Wed 05 Oct, 2016, 10:57 
User avatar

User rating: 0
Joined: Fri 18 Sep, 2015, 14:32
Posts: 15
Location: Germany, Dresden
Additional Hint:

To create this exception, it is needed, to hover over the chart, of course. Or to click anywhere on the chart.


 
 Post subject: Re: NPE with IChartPanelMouseListener in chart Post rating: 0   New post Posted: Wed 12 Oct, 2016, 15:30 
User avatar

User rating: 0
Joined: Fri 18 Sep, 2015, 14:32
Posts: 15
Location: Germany, Dresden
Could you reproduce this?

Is it going to be fixed?

Or is there a workaround I could use now? I need to react to mouse inputs on the screen (on special bars, points etc.). What can I do?


 
 Post subject: Re: NPE with IChartPanelMouseListener in chart Post rating: 0   New post Posted: Thu 13 Oct, 2016, 15:19 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Please see the attached fixed class.


Attachments:
MainOpenChart_DC.java [21.13 KiB]
Downloaded 221 times
DISCLAIMER: Dukascopy Bank SA's waiver of responsability - Documents, data or information available on this webpage may be posted by third parties without Dukascopy Bank SA being obliged to make any control on their content. Anyone accessing this webpage and downloading or otherwise making use of any document, data or information found on this webpage shall do it on his/her own risks without any recourse against Dukascopy Bank SA in relation thereto or for any consequences arising to him/her or any third party from the use and/or reliance on any document, data or information found on this webpage.
 
 Post subject: Re: NPE with IChartPanelMouseListener in chart Post rating: 0   New post Posted: Thu 05 Jul, 2018, 10:30 
User avatar

User rating: 13
Joined: Mon 27 Jul, 2015, 16:30
Posts: 110
Location: Canada, Mission
Thank You! Your work is very much appreciated!


 

Jump to:  

  © 1998-2024 Dukascopy® Bank SA
On-line Currency forex trading with Swiss Forex Broker - ECN Forex Brokerage,
Managed Forex Accounts, introducing forex brokers, Currency Forex Data Feed and News
Currency Forex Trading Platform provided on-line by Dukascopy.com