Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Chart creation

Posted on 2011-03-03
13
Medium Priority
?
274 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Suggested Courses

705 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