2012-08-26 12 views
-2

我在舊帖子上經歷了類似的問題..糾正了它們。仍然收緊力量關閉問題。請幫忙。Android應用程序部隊即將關閉,因爲我在模擬器上打開它

以下哪項是正確的?

Button continueButton = (Button) findViewById(R.id.continue_button); 

View continueButton = findViewById(R.id.continue_button);

,什麼是它們之間的區別?


package org.example.sudoku; 

import android.os.Bundle; 


import android.view.View.OnClickListener; 
import android.app.Activity; 
import android.view.Menu; 
import android.widget.Button; 

public class Sudoku extends Activity { 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 

     super.onCreate(savedInstanceState);  
     setContentView(R.layout.main); 

     Button continueButton = (Button) findViewById(R.id.continue_button); 
     continueButton.setOnClickListener((OnClickListener) this); 

     Button aboutButton = (Button)findViewById(R.id.about_button); 
     aboutButton.setOnClickListener((OnClickListener) this); 

     Button newButton = (Button)findViewById(R.id.new_game_button); 
     newButton.setOnClickListener((OnClickListener) this); 

     Button exitButton = (Button)findViewById(R.id.exit_button); 
     exitButton.setOnClickListener((OnClickListener) this); 


    } 


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

} 

+1

你有關於力量關閉的堆棧跟蹤? –

+0

查看'LogCat'確切的例外情況,這將有助於查明問題。以上兩點都是正確的,取決於你想做什麼(通常是第一個)。 –

+0

檢查logcat是否拋出異常。 –

回答

0

無論是正確的,因爲ButtonView一個子類。但是您通常必須使用Button,因此您可以添加聽衆和其他內容。

你應該真的看看你的應用程序的logcat輸出。在那裏你會發現一個堆棧跟蹤,可以幫助你識別問題。

0

我認爲問題來自您在按鈕上設置點擊偵聽器的方式。你使用這個,但是你的activity類沒有實現這個接口。我建議你這樣做,而不是:

View.OnClickListener clickHandler = new View.OnClickListener() { 
    public void onClick(View v) { 

    } 
    } 

    Button continueButton = (Button) findViewById(R.id.continue_button); 
    continueButton.setOnClickListener(clickHandler);+- 
相關問題