Solved

NPE for outY

Posted on 2011-03-03
4
344 Views
Last Modified: 2012-05-11
Please advice why I have null for outY if it's initialized  
public class SelectData extends TimerTask {

    private LionFXConnect conn;
    ArrayConverter aConverter;
    double outY[] = new double[10];
    double[] avg = new double[10];
    String sql;

    /**
     * @throws SQLException
     * @throws ClassNotFoundException
     * @throws IllegalAccessException
     * @throws InstantiationException
     * @throws NotDefinedException
     * @throws FieldNotFound
     * @throws Exception
     */
    public SelectData() throws SQLException, ClassNotFoundException,
                               IllegalAccessException, InstantiationException,
                               FieldNotFound, NotDefinedException, Exception {

        conn = new LionFXConnect();
        aConverter = new ArrayConverter();
    }

    public void run() {
        
//      System.out.println(new java.util.Date() + "        SelectData");
        
        try {
            ResultSet rs =
                conn.select("SELECT * FROM RBF_DATA_60 where timest = ( select max( timest ) from RBF_DATA_60 ) and rownum = 1");

            while (rs.next()) {

                outY[0] = rs.getDouble("OUTY0");
                outY[1] = rs.getDouble("OUTY1");
                outY[2] = rs.getDouble("OUTY2");
                outY[3] = rs.getDouble("OUTY3");
                outY[4] = rs.getDouble("OUTY4");
                outY[5] = rs.getDouble("OUTY5");
                outY[6] = rs.getDouble("OUTY6");
                outY[7] = rs.getDouble("OUTY7");
                outY[8] = rs.getDouble("OUTY8");
                outY[9] = rs.getDouble("OUTY9");

//                System.out.println(new java.util.Date() +
//                                   " ###################### SD   outY[0]   " + outY[0] + "     outY[1]   " + outY[1]);
                equals(rs);
                System.out.println("SD1    = " + outY[0]);
                aConverter.arrayConverter(outY);
                System.out.println("SD2    = " + outY[0]);
                ChartCommander.getInstance().chartEURUSD(avg , outY);
              System.out.println("SD3    = " + outY[0]);
                
            }
            rs.close();

        } catch (Exception ex) {
            Logger.getLogger(SelectData.class.getName()).log(Level.SEVERE,
                                                             null, ex);
        }

    }
}

Open in new window

04.03.2011 1:09:08 connect.PMDS parseMarketDataSnapshot
SEVERE: null
java.lang.NullPointerException
	at charts.ChartCommander.chartEURUSD(ChartCommander.java:23)
	at connect.PMDS.parseMarketDataSnapshot(PMDS.java:89)
	at connect.DBFXConnect$1.messageArrived(DBFXConnect.java:133)
	at com.fxcm.internal.transport.FXCMGateway.update(FXCMGateway.java:828)
	at com.fxcm.messaging.util.fix.FIXUserSession$BackToUserQueue.run(FIXUserSession.java:675)
	at java.lang.Thread.run(Thread.java:680)
SD1    = 0.13682981
SD2    = 0.13682981
CC    = 0.13682981
SD3    = 0.13682981
SD1    = 0.13682981
SD2    = 0.13682981
CC    = 0.13682981
SD3    = 0.13682981

Open in new window

          at charts.ChartCommander.chartEURUSD(ChartCommander.java:23)=>     System.out.println("CC    = " + outY[0]);
package charts;


public class ChartCommander {

    AlgochartEURUSD acEURUSD;

    private static ChartCommander instance = new ChartCommander();

    public static ChartCommander getInstance() {
        return instance;
    }

    public ChartCommander() {

        acEURUSD = new AlgochartEURUSD();
    }

    public void chartEURUSD(double[] avg, double[] outY) {

              if (avg[0] != 0 || outY[0] != 0){
                  
                System.out.println("CC    = " + outY[0]);

        acEURUSD.doEvent(avg, outY);
              }
    }
}

Open in new window

0
Comment
Question by:gbcbr
  • 2
  • 2
4 Comments
 
LVL 92

Expert Comment

by:objects
ID: 35032354
>       at connect.PMDS.parseMarketDataSnapshot(PMDS.java:89)

thats being called from PMDS, make sure you have assigned your array there correctly
0
 

Author Comment

by:gbcbr
ID: 35032377
I suppose it's ok
public class PMDS {

    DecisionCenterControl dcc;
    IGateway mFxcmGateway;
    MarketDataSnapshot incomingQuote;
    ITransportable message;

    public PMDS() {
        this.mFxcmGateway = DBFXConnect.getGateway();
        incomingQuote = (MarketDataSnapshot)message;
    }

    String symbol;
    double[] bidPx = new double[10];
    double[] askPx = new double[10];
    double[] avg = new double[10];
    double[] outY;
    String eurusd_bid;
    String eurusd_ask;
    String eurchf_bid;
    String eurchf_ask;
    String eurgbp_bid;
    String eurgbp_ask;
    String usdchf_bid;
    String usdchf_ask;
    String gbpusd_bid;
    String gbpusd_ask;
    String gbpchf_bid;
    String gbpchf_ask;
    String eurjpy_bid;
    String eurjpy_ask;
    String usdjpy_bid;
    String usdjpy_ask;
    String gbpjpy_bid;
    String gbpjpy_ask;
    String chfjpy_bid;
    String chfjpy_ask;

    public void parseMarketDataSnapshot(ITransportable message) 
    throws SQLException,
                                                                        ClassNotFoundException,
                                                                        InstantiationException,
                                                                        IllegalAccessException,
                                                                        FieldNotFound,
                                                                        Exception {

        if (message instanceof MarketDataSnapshot) {

            incomingQuote = (MarketDataSnapshot)message;
            symbol = incomingQuote.getInstrument().getSymbol();
            double bPx = incomingQuote.getBidOpen();
            double aPx = incomingQuote.getAskOpen();


            try {

                if ("EUR/USD".equalsIgnoreCase(symbol.trim())) {
                    
                    BorderControl.getInstance().borderControl(bidPx,
                                                              askPx);
                    bidPx[0] = bPx;
                    eurusd_bid = String.valueOf(bidPx[0]);
                    DCC.getInstance().setEURUSD_bid(eurusd_bid);
                    askPx[0] = aPx;
                    eurusd_ask = String.valueOf(askPx[0]);
                    DCC.getInstance().setEURUSD_ask(eurusd_ask);
                    avg[0] = (bidPx[0] + askPx[0])/2;
                    ChartCommander.getInstance().chartEURUSD(avg, outY);
                }

Open in new window

0
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
ID: 35032381
>     double[] outY;


should be:


    double[] outY = new double[10];


:)
0
 

Author Closing Comment

by:gbcbr
ID: 35032399
Thank you for the lession
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now