2015-09-26 62 views
0

任何人都可以幫助我解決此問題嗎?在onClick(視圖視圖)方法中無法解析int

public class Pin extends ActionBarActivity implements View.OnClickListener { 

    Button btn_pin; 
    EditText input_pin; 
    int Pin; 

    UserLocalStore userLocalStore; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_login); 

     btn_pin = (Button) findViewById(R.id.btn_pin); 
     int Pin = Integer.parseInt(input_pin.getText().toString()); 
     input_pin = (EditText) findViewById(R.id.input_pin); 

     btn_pin.setOnClickListener(this); 

     userLocalStore = new UserLocalStore(this); 
    } 

    @Override 
    public void onClick(View view) { 
     switch (view.getId()) { 
      case R.id.btn_pin: 
       int Pin = Integer.parseInt(input_pin.getText().toString()); 
       User user = new User(Pin); 

       authenticate(user); 
       break; 
     } 
    } 

該行與int Pin有錯誤。我不知道如何解決這個問題可以幫助我嗎?

錯誤:(42,29)誤差:找到用戶(INT)沒有合適的構造 構造User.User(字符串,字符串)是不適用 (實際和正式的參數列表的長度不同) 構造用戶。用戶(字符串,字符串,int,int,字符串,字符串)不適用 (實際和正式參數列表長度不同)

其錯誤:(41,38)錯誤:找不到符號變量Pin可以找到它並使其正確。

+1

請你張貼在該行 – iagreen

+0

我@iagreen同意所得到的錯誤。那個錯誤是一個'NumberFormatExceptionError'?如果是這樣,那麼'input_pin.getText()。toString()'返回的字符串不是數字。 –

回答

1
btn_pin = (Button) findViewById(R.id.btn_pin); 
int Pin = Integer.parseInt(input_pin.getText().toString()); 
input_pin = (EditText) findViewById(R.id.input_pin); 

你應該findViewById後使用input_pin,或者你會得到一個NullPointerException

+0

我編輯我的帖子先生.. thx –

+0

它說'用戶'類沒有構造函數'User(int)',檢查'用戶'執行? –

0
Error:(42, 29) error: no suitable constructor found for User(int) constructor User.User(String,String) is not applicable (actual and formal argument lists differ in length) constructor User.User(String,String,int,int,String,String) is not applicable (actual and formal argument lists differ in length) 

這意味着當你想使用int時你需要改變你的用戶。並且您聲明爲

int Pin; 

作爲全局變量。那麼你必須在其他源代碼中使用它,而不需要輸入「int」。例如:

變化

int Pin = Integer.parseInt(input_pin.getText().toString()); 

Pin = Integer.parseInt(input_pin.getText().toString()); 
+0

thx先生,工作... –

相關問題