简体   繁体   English

Eclipse奇怪的行为以相同的方法访问变量

[英]Strange behaviour of Eclipse to access variable in the same method

hy! 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." 当我输入“ graphView”时。 and see what the auto-suggest says no variables from my class are in it. 并查看自动提示的内容,该类中没有变量。

GraphView Class: GraphView类别:

http://www.sourcepod.com/dknqvl76-5923 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; Eclipse graphView不会在您的代码graphView识别为变量。 only a class name would be valid, so that's how it is interpreted. 只有一个类名才有效,所以这就是它的解释方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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