Solved

Chart creation

Posted on 2011-03-03
13
271 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 5
13 Comments
 
LVL 92

Expert Comment

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

Expert Comment

by:CEHJ
ID: 35032011
>>ChartCommander.getInstance().chartEURUSD(avg , outY);

Where is 'avg' initialized?
0
 

Author Comment

by:gbcbr
ID: 35032068
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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
LVL 92

Expert Comment

by:objects
ID: 35032091
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
ID: 35032102
               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
ID: 35032124
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
 
LVL 92

Expert Comment

by:objects
ID: 35032141
>     double[] avg;


should be:


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

Author Comment

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

Author Comment

by:gbcbr
ID: 35032162
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
ID: 35032196
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
ID: 35032210
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
ID: 35032282
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
ID: 35032298
thats a different problem, open a new q and I'll have a look at it for you
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This video teaches viewers about errors in exception handling.
Suggested Courses

752 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