为何一个Button使用setOnClickListener()方法会出错
为什么一个Button使用setOnClickListener()方法会出错。
这个问题很诡异。
声明了一个Button控件
private Button locationButton;
在布局文件中已经布局好了。
在activity里
locationButton=(Button)findViewById(R.id.location);
这一步不会出错,程序在模拟器上能运行,当然仅仅这一步,点击location按钮没有反应
但是到这一步locationButton.setOnClickListener(this);的时候程序就无法运行了
不知道与没有人遇见过这样的问题请求帮助啊。
------解决方案--------------------
无码无真相,发详细代码,以及LotCat里面的详细错误上来看看。
------解决方案--------------------
好吧,问题找到了,main.xml里面
<Button
android:name="@+id/location"
android:layout_width="wrap_content"
android:layout_height="80px"
android:layout_toRightOf="@id/send"
android:layout_alignTop="@id/send"
android:text="位置"/>
改为
<Button
android:id="@+id/location"
android:layout_width="wrap_content"
android:layout_height="80px"
android:layout_toRightOf="@id/send"
android:layout_alignTop="@id/send"
android:text="位置"/>
------解决方案--------------------
定义布局文件最后一个Button出错了,应该为android:id = "@+id/location"
------解决方案--------------------
这个问题很诡异。
声明了一个Button控件
private Button locationButton;
在布局文件中已经布局好了。
在activity里
locationButton=(Button)findViewById(R.id.location);
这一步不会出错,程序在模拟器上能运行,当然仅仅这一步,点击location按钮没有反应
但是到这一步locationButton.setOnClickListener(this);的时候程序就无法运行了
不知道与没有人遇见过这样的问题请求帮助啊。
------解决方案--------------------
无码无真相,发详细代码,以及LotCat里面的详细错误上来看看。
------解决方案--------------------
好吧,问题找到了,main.xml里面
<Button
android:name="@+id/location"
android:layout_width="wrap_content"
android:layout_height="80px"
android:layout_toRightOf="@id/send"
android:layout_alignTop="@id/send"
android:text="位置"/>
改为
<Button
android:id="@+id/location"
android:layout_width="wrap_content"
android:layout_height="80px"
android:layout_toRightOf="@id/send"
android:layout_alignTop="@id/send"
android:text="位置"/>
------解决方案--------------------
定义布局文件最后一个Button出错了,应该为android:id = "@+id/location"
------解决方案--------------------