java.lang.IllegalStateException:找不到方法的onClick处理程序id_button [英] java.lang.IllegalStateException : Could not find a method onClick handler with id_button
问题描述
我想请教一下我的项目。我创建一个类(RestoranView.class),其中有3个按钮:菜单,地图和等级。其中两个(地图和等级)的工作得很好,但是当我点击按钮菜单,它没有工作和表现出的logcat这些错误。我已经实现了同样的code。你能帮我解决这个错误吗?先谢谢了。
logcat的错误
01-12 22:04:28.543:E / AndroidRuntime(25625):致命异常:主要
01-12 22:04:28.543:E / AndroidRuntime(25625):java.lang.IllegalStateException:找不到在活动课com.example.hellojson.RestoranView对视图类的android onclick处理方法MenuClick(查看)。 widget.Button ID为'button_menu
01-12 22:04:28.543:E / AndroidRuntime(25625):在android.view.View $ 1.onClick(View.java:3685)
01-12 22:04:28.543:E / AndroidRuntime(25625):在android.view.View.performClick(View.java:4222)
RestoranView.java
ackage com.example.hellojson;
公共类RestoranView延伸活动{
@覆盖
保护无效的onCreate(包savedInstanceState){
// TODO自动生成方法存根
super.onCreate(savedInstanceState);
的setContentView(R.layout.restoran_view);
//意图从RestoranView.class到Map.class
公共无效MenuCLick(视图v){
意图菜单=新的意图(RestoranView.this,TabMenu.class);
menu.putExtra(Restoran.id_restoran_tags,resto.getId_restoran());
startActivity(菜单);
}
//意图从RestoranView.class到Map.class
公共无效MapsClick(视图v){
意向图=新的意图(RestoranView.this,Map.class);
maps.putExtra(Restoran.nama_tags,resto.getNama());
maps.putExtra(Restoran.latitude_tags,resto.getLatitude());
maps.putExtra(Restoran.longitude_tags,resto.getLongitude());
maps.putExtra(Restoran.desc_tags,resto.getDesc());
startActivity(图)
}
//意图从RestoranView.class到Rating.class
公共无效RatingClick(视图v){
意图等级=新的意图(RestoranView.this,Rating.class);
rating.putExtra(Restoran.id_restoran_tags,resto.getId_restoran());
rating.putExtra(Restoran.nama_tags,resto.getNama());
startActivity(等级);
}
}
RestoranView.xml
< XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:背景=@可绘制/背景
机器人:方向=垂直>
<滚动型
机器人:ID =@ + ID /滚动视图
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:fillViewport =假>
<的LinearLayout
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:方向=垂直>
<的TextView
机器人:ID =@ + ID / nama_restoran_view
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_gravity =center_horizontal
机器人:paddingBottom会=10dip
机器人:paddingTop =5dip
机器人:文本=那抹RESTORAN
机器人:文字颜色=@色/海军
机器人:TEXTSIZE =25sp
机器人:TEXTSTYLE =黑体/>
< ImageView的
机器人:ID =@ + ID / image_restoran_view
机器人:layout_width =275dp
机器人:layout_height =241dp
机器人:layout_gravity =center_horizontal
机器人:paddingTop =10dip
机器人:SRC =@可绘制/ ic_launcher/>
<的TextView
机器人:ID =@ + ID / alamat_restoran_view
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:paddingTop =10dip
机器人:文本=Alamat:
机器人:文字颜色=@色/海军
机器人:TEXTSIZE =20SP
机器人:TEXTSTYLE =黑体/>
<的TextView
机器人:ID =@ + ID / phone_restoran_view
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:paddingTop =10dip
机器人:文本=电话:
机器人:文字颜色=@色/海军
机器人:TEXTSIZE =20SP
机器人:TEXTSTYLE =黑体/>
<的TextView
机器人:ID =@ + ID / deskripsi_restoran_view
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:paddingTop =10dip
机器人:文本=Deskripsi
机器人:文字颜色=@色/海军
机器人:TEXTSIZE =20SP
机器人:TEXTSTYLE =黑体/>
<的LinearLayout
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT>
<按钮
机器人:ID =@ + ID / button_menu
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_weight =0.30
机器人:的onClick =MenuClick
机器人:文本=菜单/>
<按钮
机器人:ID =@ + ID / button_maps
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_weight =0.30
机器人:的onClick =MapsClick
机器人:文本=地图/>
<按钮
机器人:ID =@ + ID / button_rating
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_weight =0.30
机器人:的onClick =RatingClick
机器人:文本=评分/>
< / LinearLayout中>
< / LinearLayout中>
< /滚动型>
< / LinearLayout中>
AndroidManifest
< XML版本=1.0编码=UTF-8&GT?;
<舱单的xmlns:机器人=http://schemas.android.com/apk/res/android
包=com.example.hellojson
安卓版code =1
机器人:VERSIONNAME =1.0>
<用途-SDK
安卓的minSdkVersion =11
机器人:targetSdkVersion =17/>
<使用-权限的Android:名称=android.permission.INTERNET对/>
<使用-权限的Android:名称=android.permission.ACCESS_NETWORK_STATE/>
<使用-权限的Android:名称=android.permission.WRITE_EXTERNAL_STORAGE/>
<使用-权限的Android:名称=com.google.android.providers.gsf.permission.READ_GSERVICES/>
<应用
机器人:allowBackup =真
机器人:图标=@可绘制/ ic_launcher
机器人:标签=@字符串/ APP_NAME
机器人:主题=@风格/ AppTheme>
<活动
机器人:名称=com.example.hellojson.SplashScreen
机器人:标签=@字符串/ APP_NAME>
<意向滤光器>
<作用机器人:名称=android.intent.action.MAIN/>
<类机器人:名称=android.intent.category.LAUNCHER/>
&所述; /意图滤光器>
< /活性GT;
<活动机器人:名称=。MenuUtama>
< /活性GT;
<活动机器人:名称=。AboutMedan>
< /活性GT;
<活动机器人:名称=。AllVenue>
< /活性GT;
<活动机器人:名称=。TabMenu>
< /活性GT;
<活动机器人:名称=地图>
< /活性GT;
<活动机器人:名称=。RestoranView>
< /活性GT;
<活动机器人:等级NAME =>
< /活性GT;
<活动机器人:名称=搜索>
< /活性GT;
< /用途>
< /舱单>
找不到在活动课com.example.hellojson.RestoranView为onclick处理程序上的方法MenuClick(查看)视图类android.widget.Button ID为'button_menu
修改
公共无效MenuCLick(视图v)
到
公共无效MenuClick(视图v){// l小
因为你有
安卓的onClick =MenuClick//其MenuClick不MenuCLick
和作为tobor说:
@覆盖
保护无效的onCreate(包savedInstanceState){
// TODO自动生成方法存根
super.onCreate(savedInstanceState);
的setContentView(R.layout.restoran_view);
} //缺少}
I want to ask about my project. I create a class (RestoranView.class) which has 3 buttons: Menu, Maps and Rating. Two of them (Maps and Rating) work well but when I clicked button "Menu", it didn't work and the logcat showed those errors. I have implemented the same code. Could you help me to fix the error? Thanks in advance.
Logcat error
01-12 22:04:28.543: E/AndroidRuntime(25625): FATAL EXCEPTION: main
01-12 22:04:28.543: E/AndroidRuntime(25625): java.lang.IllegalStateException: Could not find a method MenuClick(View) in the activity class com.example.hellojson.RestoranView for onClick handler on view class android.widget.Button with id 'button_menu'
01-12 22:04:28.543: E/AndroidRuntime(25625): at android.view.View$1.onClick(View.java:3685)
01-12 22:04:28.543: E/AndroidRuntime(25625): at android.view.View.performClick(View.java:4222)
RestoranView.java
ackage com.example.hellojson;
public class RestoranView extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.restoran_view);
// intent from RestoranView.class to the Map.class
public void MenuCLick (View v) {
Intent menu = new Intent(RestoranView.this, TabMenu.class);
menu.putExtra(Restoran.id_restoran_tags, resto.getId_restoran());
startActivity(menu);
}
// intent from RestoranView.class to the Map.class
public void MapsClick(View v) {
Intent maps = new Intent(RestoranView.this, Map.class);
maps.putExtra(Restoran.nama_tags, resto.getNama());
maps.putExtra(Restoran.latitude_tags, resto.getLatitude());
maps.putExtra(Restoran.longitude_tags, resto.getLongitude());
maps.putExtra(Restoran.desc_tags, resto.getDesc());
startActivity(maps);
}
// intent from RestoranView.class to the Rating.class
public void RatingClick(View v) {
Intent rating = new Intent(RestoranView.this, Rating.class);
rating.putExtra(Restoran.id_restoran_tags, resto.getId_restoran());
rating.putExtra(Restoran.nama_tags, resto.getNama());
startActivity(rating);
}
}
RestoranView.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
android:orientation="vertical" >
<ScrollView
android:id="@+id/scrollView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="false" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/nama_restoran_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:paddingBottom="10dip"
android:paddingTop="5dip"
android:text="Nama Restoran"
android:textColor="@color/Navy"
android:textSize="25sp"
android:textStyle="bold" />
<ImageView
android:id="@+id/image_restoran_view"
android:layout_width="275dp"
android:layout_height="241dp"
android:layout_gravity="center_horizontal"
android:paddingTop="10dip"
android:src="@drawable/ic_launcher" />
<TextView
android:id="@+id/alamat_restoran_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="10dip"
android:text="Alamat :"
android:textColor="@color/Navy"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="@+id/phone_restoran_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="10dip"
android:text="Phone : "
android:textColor="@color/Navy"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="@+id/deskripsi_restoran_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="10dip"
android:text="Deskripsi"
android:textColor="@color/Navy"
android:textSize="20sp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<Button
android:id="@+id/button_menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.30"
android:onClick="MenuClick"
android:text="Menu" />
<Button
android:id="@+id/button_maps"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.30"
android:onClick="MapsClick"
android:text="Maps" />
<Button
android:id="@+id/button_rating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.30"
android:onClick="RatingClick"
android:text="Rating" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
AndroidManifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.hellojson"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.hellojson.SplashScreen"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MenuUtama" >
</activity>
<activity android:name=".AboutMedan" >
</activity>
<activity android:name=".AllVenue" >
</activity>
<activity android:name=".TabMenu" >
</activity>
<activity android:name=".Map" >
</activity>
<activity android:name=".RestoranView" >
</activity>
<activity android:name=".Rating" >
</activity>
<activity android:name=".Search" >
</activity>
</application>
</manifest>
Could not find a method MenuClick(View) in the activity class com.example.hellojson.RestoranView for onClick handler on view class android.widget.Button with id 'button_menu'
Change
public void MenuCLick (View v)
to
public void MenuClick (View v) { // l small
coz you have
android:onClick="MenuClick" // its MenuClick not MenuCLick
And as tobor said
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.restoran_view);
} // missing }
这篇关于java.lang.IllegalStateException:找不到方法的onClick处理程序id_button的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!