2012-05-16 42 views
0

我是Android新手。我只是用一個按鈕和'onClickListener'創建了一個簡單的應用程序。但使用以下兩行:Android中的classcastexception

button=(Button) findViewById(R.id.button1); 
button.setOnClickListener(this); 

onCreate()方法導致ClassCastException。但沒有這兩行,該應用程序工作正常。問題是什麼?

+2

把你的全代碼爲N的XML – waqaslam

+1

你在XML佈局中使用什麼類型的按鈕? – L7ColWinters

+0

請發佈您的佈局XML。 – MByD

回答

0

//如果您在xml中使用ImageButton或ImageView,並且聲明如下所示的代碼,那麼您的例外情況將爲ClassCastException

button=(Button) findViewById(R.id.button1); 

//爲您需要在您的ImageView或ImageButton的變更到按鈕的代碼申報相應的插件

+0

@manivannan thanq ... :-)解決了它 – rampireram

相關問題