2014-01-12 3 views
0

Я хочу спросить о моем проекте. Я создаю класс (RestoranView.class), который имеет 3 кнопки: меню, карты и рейтинг. Два из них (Карты и Рейтинг) работают хорошо, но когда я нажал кнопку «Меню», это не сработало, и лог-код показал эти ошибки. Я реализовал тот же код. Не могли бы вы помочь мне исправить ошибку? Заранее спасибо.java.lang.IllegalStateException: Не удалось найти метод обработчика onClick с id_button

ошибка 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> 

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> 

ответ

4
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' 

Изменить

public void MenuCLick (View v) 

в

public void MenuClick (View v) { // l small 

сог у вас есть

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

И как Tobor сказал

@Override 
protected void onCreate(Bundle savedInstanceState) { 
// TODO Auto-generated method stub 
super.onCreate(savedInstanceState); 
setContentView(R.layout.restoran_view); 
} // missing } 
+0

О, Боже мой, только буква L вызывает ошибки, которые я не могу исправить в течение нескольких дней. Спасибо за исправление ...^_^ –

+1

@ user3187074 кроме того, что вы пропустили '}' для 'onCreate', или вы пропустили во время публикации здесь. – Raghunandan

+0

@WulanRahmadiny, так как ваш новый для stackoverflow посмотреть на это http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work – Raghunandan

1

Вы не закроете OnCreate метод ... добавить недостающие} перед тем MenuClick.

+0

Спасибо @ Тобор, я уже пробовал предложение, и ошибка в том, что я ошибаюсь в письме «l» с большой буквы «L». –

+0

Добро пожаловать. Я не заметил L ...;) –

0

В моем случае я не был добавив вид параметра в функции OnClick

изменил

public void sendMessage() 

в

public void sendMessage(View v) 
0

В моем случае на андроид палочке, удалить атрибут темы из xml и поместить тему в манифест андроида. Он должен начать работать.

Смежные вопросы