简体   繁体   中英

Strange behaviour of Eclipse to access variable in the same method

hy!

I added a library to my project and i want to use it in my class

Code:

import com.jjoe64.graphview.*;
import com.jjoe64.graphview.GraphView.GraphViewSeries;
import com.jjoe64.graphview.GraphView.GraphViewData;
import greendroid.app.GDActivity;

public class StatisticActivity extends GDActivity {

    GraphViewSeries exampleSeries = new GraphViewSeries(new GraphViewData[] {
              new GraphViewData(1, 2.0d)
              , new GraphViewData(2, 1.5d)
              , new GraphViewData(3, 2.5d)
              , new GraphViewData(4, 1.0d)
    });

    GraphView graphView = new LineGraphView(
          this // context
          , "GraphViewDemo");

    graphView.addSeries(exampleSeries); // can't access that variable

    //LinearLayout layout = (LinearLayout) findViewById(R.id.layout);
    //layout.addView(graphView);
}

My problem is that i can't get access to the variables. when i type in "graphView." and see what the auto-suggest says no variables from my class are in it.

GraphView Class:

http://www.sourcepod.com/dknqvl76-5923

Please help

The first and third commented-out lines are invalid syntax, and that's probably the issue here. Only member declarations can appear at the top level of the class. Statements like

graphView.addSeries(exampleSeries);

can only appear inside a method or initialization block. Eclipse won't recognize graphView as a variable at that point in your code; only a class name would be valid, so that's how it is interpreted.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM