2012-09-24 24 views
1

我是JAva和Android的新手,我正在開發我的第一個測試應用程序。VariableDeclaratorId和錯位

我有這樣的代碼(這是整個代碼):

package test.test; 

import android.os.Bundle; 
import android.app.Activity; 
import android.view.Menu; 
import android.widget.TextView; 

public class MainActivity extends Activity { 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     getMenuInflater().inflate(R.menu.activity_main, menu); 
     return true; 
    } 

    int num_seeds = 15 ; 
    int num_coins = 100 ; 
    int seed_buy_price = 10 ; 
    int seed_sell_price = 8 ; 
    String S_num_seeds = Integer.toString(num_seeds) ; 

    TextView textView_seeds_current_display = (TextView) findViewById(R.id.textView_seeds_current_display) ; 

    textView_seeds_current_display.setText(S_num_seeds) ; 

} 

但是Eclipse顯示我的最後一行的錯誤:在該行 多個標誌 - 令牌「S_num_seeds」語法錯誤,VariableDeclaratorId 令牌 - 令牌上的語法錯誤,錯位的構造(s)

我是新來的Java,我仍然無法理解這一點。請問有人能指點我做錯了什麼?我想我下從這裏忠告:

How to display the value of a variable on the screen

感謝

回答

1

此行的程序代碼:

textView_seeds_current_display.setText(S_num_seeds); 

出現在你的類定義。它需要出現在方法中。它可能需要在構造函數中。

+0

謝謝。這是我第一個Java項目,我不太明白。你解釋得很好。 – Envite

+0

歡迎來到StackOverflow社區期望的一部分在於,如果它可以幫助你,那麼你「接受」你的問題的答案。爲此,請點擊大綱綠色複選標記。 –

+0

完成。非常感謝。 – Envite

-1

代碼接縫要罰款......

有些時候,我有日食表示在將線條類似的錯誤沒問題。嘗試以下操作:將光標定位在行上,按ctrl d(刪除行),然後按ctrl z(恢復刪除的行)。如果這是一個「假」的錯誤,它會消失。

好運

+0

有人倒投了答案,但我可以保證信息是正確的。您可以在Eclipse中選擇「項目」菜單然後選擇「清理」,但需要更長的時間。 – Luis

相關問題