Solved

Chart creation

Posted on 2011-03-03
13
265 Views
Last Modified: 2012-05-11
Please help to find mistake into the code.
I other case it works perfect, but now I have NPE.
Maybe I see at this code too much and blind mistake.
Please advice
 
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");
........;
                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

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

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

SD1    = 0.0123864515
SD2    = 0.0123864515
03.03.2011 23:57:47 connect.SelectData run
SEVERE: null
java.lang.NullPointerException
	at charts.ChartCommander.chartEURUSD(ChartCommander.java:21)
	at connect.SelectData.run(SelectData.java:71)
	at java.util.TimerThread.mainLoop(Timer.java:512)
	at java.util.TimerThread.run(Timer.java:462)

Open in new window

at charts.ChartCommander.chartEURUSD(ChartCommander.java:21)=>              if (avg[0] != 0 || outY[0] != 0){
0
Comment
Question by:gbcbr
  • 7
  • 5
13 Comments
 
LVL 92

Expert Comment

by:objects
Comment Utility
avg appears to e null, make sure you are setting it correctly (or test for null)
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
>>ChartCommander.getInstance().chartEURUSD(avg , outY);

Where is 'avg' initialized?
0
 

Author Comment

by:gbcbr
Comment Utility
It's initialized into PMDS class which has to forward it to this chart:
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;
    ..............
                    avg[0] = (bidPx[0] + askPx[0])/2;
                    ChartCommander.getInstance().chartEURUSD(avg, outY);
                }

Open in new window

0
 
LVL 92

Expert Comment

by:objects
Comment Utility
you also need to initialise it for your run() method (in the first snippet)
thats whats causing the NPE
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
               System.out.println("SD1    = " + outY[0]);
                aConverter.arrayConverter(outY);
                System.out.println("SD2    = " + outY[0]);
                ChartCommander.getInstance().chartEURUSD(avg , outY);    <---- its null here
0
 

Author Comment

by:gbcbr
Comment Utility
I see that is null, but it's initialized into SelectData class also
public class SelectData extends TimerTask {

    private LionFXConnect conn;
    ArrayConverter aConverter;
    double outY[] = new double[10];
    double[] avg;
    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]);

Open in new window

0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 92

Expert Comment

by:objects
Comment Utility
>     double[] avg;


should be:


    double[] avg = new double[10];
0
 

Author Comment

by:gbcbr
Comment Utility
now I'm not zero level, I'm already 0.001 level, so, I can understand some things:-)
0
 

Author Comment

by:gbcbr
Comment Utility
but I don't create new avg in this class, just declare.
please explain why I have to create new avg here.
0
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
Comment Utility
double[] avg;

is the same as:

double[] avg = null;

you need to define the actual array that avg references
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
Same as you did in the PMDS class (the two are entirely seperate variables/arrays, they just have the same name)
0
 

Author Comment

by:gbcbr
Comment Utility
Now it's ok with avg but appear problem with outY.
But it's initialized into SelectData
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]);

Open in new window

SD1    = 0.038359333
SD2    = 0.038359333
SD3    = 0.038359333
SD1    = 0.038359333
SD2    = 0.038359333
SD3    = 0.038359333
04.03.2011 0:55:02 connect.PMDS parseMarketDataSnapshot
SEVERE: null
java.lang.NullPointerException
	at charts.AlgochartEURUSD.doEvent(AlgochartEURUSD.java:47)
	at charts.ChartCommander.chartEURUSD(ChartCommander.java:25)
	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)

Open in new window

at charts.AlgochartEURUSD.doEvent(AlgochartEURUSD.java:47)=>  s2.addOrUpdate(new FixedMillisecond(new Date().getTime() + 5000), new Float(outX[0]));
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
thats a different problem, open a new q and I'll have a look at it for you
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
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 learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…

762 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

9 Experts available now in Live!

Get 1:1 Help Now