【问题标题】:illegal forward reference with labels带有标签的非法前向引用
【发布时间】:2015-11-02 09:38:42
【问题描述】:

我遇到了麻烦...

与我上次发布的帖子不同,我在 Google 上搜索过,但没有任何帮助。

为什么我在这里得到:非法前向引用错误,我该如何修复它?

   public class guihanging extends javax.swing.JFrame {

 int re;
 String [] A = new String[10];
 String word;
 String dash = "";
 int picture = 2;
 String letter = "qw";
 int startOver;
 int qq=0;
 int ww=0;
 int ee=0;
 int rr=0;
 int tt=0;
 int yy=0;
 int uu=0;
 int ii=0;
 int oo=0;
 int pp=0;
 int aa=0;
 int ss=0; 
 int dd=0;
 int ff=0;
 int gg=0;
 int hh=0;
 int jj=0;
 int kk=0;
 int ll=0;
 int zz=0;
 int xx=0;
 int cc=0;
 int vv=0;
 int bb=0;
 int nn=0;
 int mm=0;




public guihanging() {
    initComponents();

    { 
       A[0]="rob";
       A[1]= "welcome";
       A[2]= "carbohydrates";
       A[3]= "resiprocity"; 
       A[4]="fatty";
       A[5]="baggy";
       A[6]="laptop";
       A[7]="personalcomputer";
       A[8]="monitor";
       A[9]="mouse";
     }
}
public void letters()
{System.out.println("");}
{
 int wordleng = word.length();
    for (int i2 = 0; i2 < wordleng; i2++) 
    {

      int position = word.indexOf(letter);
      if (position >= 0)
      {
         String before = word.substring(0,position);
         String after = word.substring(position+1);
         word = before + "@" + after; 
         int dashPosition = position * 2;
         String dashBefore = dash.substring(0,dashPosition);
         String dashAfter = dash.substring(dashPosition + 1);
         dash = dashBefore + letter + dashAfter;
         lblWord.setText(dash);//error

      }
      else 
      {
         lblPicture.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pictures/"+picture+".png")));// error
         picture++;
         if (picture == 7)
         {
             JOptionPane.showConfirmDialog(rootPane, "Unluck, You just did a burpee!!"+"/n"+"do you want to start again?");

             if (true)
             {
               re = (int) (Math.random ()*10);
               word = "aaabcqdefghiqjklmnopqrstuvwxyz"; //A[re];
               for (int i1 = 0; wordleng < 10; i1++) 
                  {
                     dash = dash + "_ ";
                  }
              lblWord.setText(dash);/error
            }

         }
      }

    }
}    

错误都是由标签引起的

编辑留下这个

  private void btnStartActionPerformed(java.awt.event.ActionEvent evt) {                                         


    re = (int) (Math.random ()*10);
    word = A[re];
    int wordleng = word.length();
    for (int i1 = 0; i1 < wordleng; i1++) 
    {
       dash = dash + "_ ";
    }

    lblWord.setText(dash)

【问题讨论】:

  • 哪一行报错了?
  • 什么是错误以及从哪里...并为您共享代码 lblword...
  • 抱歉漏掉了,这是 lblWord 的唯一代码,它仍处于项目的开始阶段。我是个大菜鸟

标签: java netbeans jlabel


【解决方案1】:

“非法前向引用”表示您使用了未定义的变量。也许您错过了定义变量:dashlblWord

【讨论】:

  • 如何定义 lblWord?
  • 我不知道lblWord是哪个类,但是在使用这个对象之前你必须先做一个new &lt;classname&gt;
  • 它在我公开时有效,但在公共无效时无效。也适用于按钮
  • 那么你现在有什么问题?
  • 如何让它工作?我是 2 个月前开始学习 Java 的学生,不知道该怎么做
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-06-05
  • 2011-08-06
  • 2021-03-11
  • 2015-09-18
  • 1970-01-01
相关资源
最近更新 更多