Solved

Chart creation

Posted on 2011-03-03
13
268 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
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
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
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…
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…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

831 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