java.lang.IllegalStateException:找不到带有 id_button 的 onClick 处理程序方法

2024-03-23

我想问一下我的项目。我创建了一个类 (RestoranView.class),它有 3 个按钮:菜单、地图和评级。其中两个(地图和评级)运行良好,但当我单击“菜单”按钮时,它不起作用,并且 logcat 显示了这些错误。我已经实现了相同的代码。你能帮我解决这个错误吗?提前致谢。

日志错误

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>

Android清单

<?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

因为你有

 android:onClick="MenuClick" // its MenuClick not MenuCLick

正如托博尔所说

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.restoran_view);
} // missing }
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

java.lang.IllegalStateException:找不到带有 id_button 的 onClick 处理程序方法 的相关文章

随机推荐

  • 在 EasyPHP{WAMP} 中设置 root 密码后无法从 phpMyAdmin 访问 MySQL

    首次启动 MySQL 成功设置后 出于安全原因 页面提示我设置 ROOT 密码 设置密码后 我无法再访问 MySQL 错误是 1045 Access denied for user root localhost using password
  • Asift 和 openCV?

    opencv 允许使用 ASIFT 吗 http www ipol im pub algo my affine sift http www ipol im pub algo my affine sift 作者发布了c 所以我相信将其实现到o
  • 弹性框文本项溢出

    谁能解释一下为什么包含文本的列的宽度没有正确计算以完全包含每列中的文本 在 Firefox 和 Chrome 上 第一列和第三列中的文本不适合这些框 但令人惊讶的是 这些框在 IE 11 中的大小正确 这是浏览器错误吗 box displa
  • Windows 服务 + Windows 窗体应用程序。一个数据库。关于并发的建议

    我有包含文件信息的 SQL Server 数据库 我正在谈论自定义属性 这些是每个文件的类别和描述 Windows 窗体应用程序是供用户使用的 但我还将创建一个 Windows 服务来跟踪文件的任何更改 如果发生更改 重命名 移动 删除 服
  • ASP.NET Core 1.0 中的 AWS Elastic Beanstalk 环境变量

    如何将环境变量从 Elastic beanstalk 获取到 asp net core mvc 应用程序中 我添加了一个 ebextensions 文件夹 其中包含 app config 文件 其中包含以下内容 option setting
  • 将值添加到弧

    我正在尝试向 arc 添加值并为此目的制定了一种方法 然而 即使 for 循环给出了不同的坐标 它们看起来也都在一个地方 可能是什么问题 this RangeEnd 是 float 200 这是添加值的方法 private void OnD
  • 利用浏览器缓存,在 apache 或 .htaccess 上如何?

    在这里做什么 我有一个巨大的文件列表 Google Speed Page 说 利用浏览器缓存 但我不知道如何 我是否会弄乱或更改 Apache 配置文件 如下 或者是否在 htaccess 页面中放置了某些内容
  • 从 Node.js 中的 Array 对象中删除特定属性

    例如我有这个数组 如果我对它进行字符串化 它会是这样的 car Toyota ID 1 Doors 4 price 20 000 car Chevrolet ID 2 Doors 2 price 15 000 我该如何从两辆车中取出 门和价
  • NGramTokenizer 未按预期工作

    我有一个简单的 R 代码 可以从文件中读取文本并在条形图上绘制重复出现的短语 由于某种原因 条形图仅显示单个单词而不是多词短语 我哪里出错了 install packages xlsx install packages tm install
  • 使用自定义字体 pdfmake 进行角度

    我正在关注这个文档 https github com bpampuch pdfmake wiki Custom Fonts client side的自定义字体pdfmake 我无法理解我该如何遵循 Angular 4 的这个例子 因为我的p
  • Clearscript Javascript“需要”功能

    我正在尝试为 Twilio 可编程聊天工具编写 C 包装器 提供的库适用于 JS 客户端 我认为使用像 ClearScript V8 这样的工具可以让我根据需要包装 js 网站上的示例代码是 const Chat require twili
  • 为什么不鼓励接受引用 &String、&Vec 或 &Box 作为函数参数?

    我写了一些 Rust 代码 需要 String作为一个论点 fn awesome greeting name String println Wow you are awesome name 我还编写了接受对 a 的引用的代码Vec or B
  • Gnuplot:将按行和命名的数据绘制为不同颜色和标题的线束

    我正在尝试绘制当前存储的一组图表 我的文件 txt ID01 1 2 3 4 5 ID02 3 4 5 6 7 8 9 ID03 4 3 1 2 3 4 例如 有一行标题为 ID01 仅显示第一行 另一行标题为 ID02 依此类推 如果线条
  • LazyColumn 比垂直滚动的 Column 慢

    我有一个产品单元格 我想在列表中显示 我使用了 LazyColumn 但性能很糟糕 我找不到为什么它这么慢 然后我将 LazyColumn 切换为 Column 突然间滚动变得超级平滑 LazyColumn 版本 LazyColumn it
  • 具有多个环境的 Azure 管道

    My 点网核心应用程序每个环境都有一个 appsettings json 应用程序设置 json and appsettings Development json例如 我想在我的管道中利用这一点 我看到管道有两个选项 Build Artif
  • 使用 Post 数据重定向 URL

    我想使用一些 POST 数据将用户从 page1 重定向到 page2 Page1 和 page2 已打开两个不同的域我可以控制both of them Page 1 我想将字符作为帖子数据提交并重定向到第 2 页 然后第 2 页我想使用
  • Angular 2 - ngOnDestroy 是否在刷新时或仅在离开组件时被调用?

    我想弄清楚 Angular 2 中的 ngOnDestroy 是在刷新时运行还是在有人离开页面时运行 刷新时或当您离开当前页面时 路由除外 然后ngOnDestroy不会被调用 该应用程序将被浏览器销毁 仅当 Angular2 因为您离开或
  • 更改 DotNet 6 入站请求超时

    我需要确保同步请求保持活动状态超过 60 分钟 有没有办法更改 DotNet 6 中的默认入站请求超时 我找到了这个 serverOptions Limits KeepAliveTimeout TimeSpan FromMinutes 60
  • cplex 用于 if-else 语句

    我是 cplex 的新手 在我的 ilp 中 我有几个 if else 语句 我想使用 cplex 使用 java API 来解决我的问题 我不知道如何在 cplex 中制定 if else 例子 if x gt 0 then a 1 el
  • java.lang.IllegalStateException:找不到带有 id_button 的 onClick 处理程序方法

    我想问一下我的项目 我创建了一个类 RestoranView class 它有 3 个按钮 菜单 地图和评级 其中两个 地图和评级 运行良好 但当我单击 菜单 按钮时 它不起作用 并且 logcat 显示了这些错误 我已经实现了相同的代码