日期:2014-05-20  浏览次数:20814 次

"非法向前引用",这是什么错误????
package   jibagent.classic.HAUt;
import   jibagent.classic.MathService;
//                         Membership
class   FuzzyReasoning
{
        FuzzyReasoning()
        {
        }

        public   static   float   getD1(float   P,   float   CP,   float   C)
        {
                float   a[]   =   new   float[RULES_I.length];
                float   sum   =   0.0F;
                float   D   =   0.0F;
                for(int   i   =   0;   i   <   RULES_I.length;   i++)
                        a[i]   =   MathService.min(Membership.SIM_PR(P,   RULES_I[i][0]),   Membership.SIM_PR(CP,   RULES_I[i][1]),   Membership.SIM_PC(C,   RULES_I[i][2]));

                for(int   i   =   0;   i   <   a.length;   i++)
                        sum   +=   a[i];

                for(int   i   =   0;   i   <   a.length;   i++)
                        D   +=   a[i]   *   D1[i];

                D   /=   sum;
                return   D;
        }

        public   static   float   getD2(float   P,   float   C,   float   CC)
        {
                float   a[]   =   new   float[RULES_II.length];
                float   sum   =   0.0F;
                float   D   =   0.0F;
                for(int   i   =   0;   i   <   RULES_II.length;   i++)
                        a[i]   =   MathService.min(Membership.SIM_PR(P,   RULES_II[i][0]),   Membership.SIM_PC(C,   RULES_II[i][1]),   Membership.SIM_PC(CC,   RULES_II[i][2]));
编译是出现 "非法向前引用 ",不明白了??????

------解决方案--------------------
float a[]是定义在方法getD1中的局部变量,不能在getD2中引用。将其定义为成员变量就可以了
------解决方案--------------------
这个是Membership??别的包里面的么,你要用import的指向这个包的这个类,
------解决方案--------------------
对于类中的变量,如果是同层次的,java是按照从上到下,从前向后的顺序编译的,
你的t[]定义在引用它的变量编译之后定义,所以抱错,尝试把
private static final String t[] = {
"low ", "medium ", "high ", "slow ", "quick ", "not-quick ", "not-high ", "not-slow ", "not-low ", "NULL "