2014-01-24 11 views
0

두 개의 이미지 버튼 (EditButton, SaveButton) 중 하나에 충돌 할 때마다 내 응용 프로그램이 충돌합니다.ImageButton 응용 프로그램이 충돌합니다.

오류는 동일한마다입니다 :

java.lang.IllegalStateException :보기 에 온 클릭 처리기에 대한 활동 클래스 com.example.groceryrunner.MainActivity의 방법 onSaveClicked (보기)를 찾을 수 없습니다 id가 'SaveButton'인 이미지 버튼입니다.

내 XML의 어떤 이벤트에서도 onSaveClicked (view) 메소드가 없습니다. 단추를 클릭 할 때 (onCreateLGClick) 이동 해야하는 실제 메서드를 모든 종류의 조합을 시도했지만 내 애플 결코 거기에 도착하기 때문에 아무것도 영향을주지 않습니다. 또한 작업을 수행하는 유일한 버튼은 일관성이 없으며 이전에 작동 했음에도 불구하고 (CreateLG 버튼) 이벤트가 발생하지 않도록 10 번 클릭하거나 아무 일도 일어나지 않습니다.

createlgmenu (XML)

<?xml version="1.0" encoding="utf-8"?> 
    <menu xmlns:android="http://schemas.android.com/apk/res/android" > 
    <item 
     android:id="@+id/Create_List" 
     android:title="@string/Create_List"/> 

    <item 
     android:id="@+id/Create_Food_Group" 
     android:title="@string/Create_Food_Group"/> 
    </menu> 

메뉴 (XML)

<menu xmlns:android="http://schemas.android.com/apk/res/android" > 
<item 
    android:id="@+id/action_settings" 
    android:orderInCategory="100" 
    android:showAsAction="never" 
    android:title="@string/action_settings"/> 
</menu> 

주요 활동 (XML)

<TextView 
    android:id="@+id/GetStarted" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignTop="@+id/ListName" 
    android:layout_centerHorizontal="true" 
    android:layout_marginTop="86dp" 
    android:text="Select or Create a list to get started!" 
    android:textSize="20sp" /> 

<ImageButton 
    android:id="@+id/EditButton" 
    android:layout_width="50dp" 
    android:layout_height="50dp" 
    android:layout_alignRight="@+id/SaveButton" 
    android:layout_alignTop="@+id/ListName" 
    android:layout_marginRight="32dp" 
    android:background="@null" 
    android:scaleType="centerInside" 
    android:src="@drawable/edit_button" 
    android:onClick="onCreateLGClick" /> 

<Button 
    android:id="@+id/CreateLG" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignTop="@+id/ListName" 
    android:layout_toRightOf="@+id/ListsButton" 
    android:background="@null" 
    android:text="+" 
    android:textSize="40sp" 
    android:onClick="onCreateLGClick" /> 

<TextView 
    android:id="@+id/ListName" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:layout_centerHorizontal="true" 
    android:layout_marginTop="26dp" 
    android:text="Grocery Runner" 
    android:textSize="22sp" 
    android:onClick="onCreateLGClick" /> 

<Button 
    android:id="@+id/ListsButton" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignBottom="@+id/EditButton" 
    android:layout_alignLeft="@+id/GetStarted" 
    android:background="@null" 
    android:text="≡" 
    android:textSize="40sp" /> 

<ImageButton 
    android:id="@+id/SaveButton" 
    android:layout_width="50dp" 
    android:layout_height="50dp" 
    android:layout_alignRight="@+id/GetStarted" 
    android:layout_below="@+id/EditButton" 
    android:background="@null" 
    android:onClick="onCreateLGClick" 
    android:scaleType="centerInside" 
    android:src="@drawable/save_disk" /> 

</RelativeLayout> 

MainActivity.java :

package com.example.groceryrunner; 

import android.os.Bundle; 
import android.app.Activity; 
import android.app.AlertDialog; 
import android.view.Menu; 
import android.view.MenuItem; 
import android.view.View; 
import android.widget.Button; 
import android.widget.EditText; 
import android.widget.PopupMenu; 
import android.widget.TextView; 
import android.app.ActionBar; 
import android.content.DialogInterface; 
import android.graphics.Bitmap; 
import android.graphics.BitmapFactory; 

public class MainActivity extends Activity { 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    //Button Save = (Button) this.findViewById(R.id.SaveButton); 
} 


@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.main, menu); 
    return true; 
} 

public void onCreateLGClick(View v) { 
    final int id = v.getId(); 
    /*switch (id) { 
    case R.id.CreateLG: 
     findViewById(R.id.GetStarted).setVisibility(View.INVISIBLE); 
     createLGMenu(v); 
     break; 
    case R.id.ListsButton: 
     findViewById(R.id.GetStarted).setVisibility(View.INVISIBLE); 
     createLGMenu(v); 
     break; 
    }*/ 
} 


public void createLGMenu(View v) { 
    PopupMenu LGMenu = new PopupMenu(this, v); 
    LGMenu.getMenuInflater().inflate(R.menu.createlgmenu, LGMenu.getMenu()); 
    LGMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { 

     @Override 
     public boolean onMenuItemClick(MenuItem item) { 
      String choice = new String((String) item.getTitle()); 
      if (choice == "Create_List") { 
       createListDialog(); 
      } 
      else if (choice == "Create_Group") { 
       createListDialog(); 
      } 
      return false; 
     } 
    }); 
    LGMenu.show(); 
} 

public AlertDialog.Builder dialogBuilder; 
private void createListDialog() { 
    dialogBuilder = new AlertDialog.Builder(this); 
    EditText textInput = new EditText(this); 

    dialogBuilder.setTitle("Create list"); 
    dialogBuilder.setMessage("Name your list: "); 
    dialogBuilder.setView(textInput); 
    dialogBuilder.setPositiveButton("Create", new DialogInterface.OnClickListener() { 

     @Override 
     public void onClick(DialogInterface dialog, int which) { 
      findViewById(R.id.ListName).setVisibility(View.INVISIBLE); 
      //Toast.makeText(getApplicationContent(), "List has been created.", toast.LENGTH_SHORT); 
      // add list to ListsButton 
      //findViewById(R.id.ListName). -> Change ListName text to created list 
     } 
    }); 
    dialogBuilder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { 

     @Override 
     public void onClick(DialogInterface dialog, int which) { 
      //Toast.makeText(getApplicationContent(), "List has been created.", toast.LENGTH_SHORT); 
     } 
    }); 
    // Output 
    AlertDialog dialogue = dialogBuilder.create(); 
    dialogue.show(); 

    } 

} 
0 당신의

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.main, menu); 
    return true; 
} 

에서

+0

게시하여 createLGMenu.xml를 내장 내 xml 파일

3

)을 다시 시작하십시오 이클립스 &을 인식하는 나에게 오류를 제공하고, 또한 main.xml에 – Ogen

+0

모두 게시라는 메뉴 XML을 게시 할 수 있습니다. 감사. – user2100364

+0

프로젝트 정리를 시도 했습니까? – Ogen

답변

0

좋아요, 수정되었습니다. 첫째, 다른 오류가 발생했기 때문에 코드를 저장하고 이클립스를 삭제 한 다음 다시 설치하거나 Android 사이트에서 추출했습니다. 버튼이 더 이상 내 앱을 크래킹하지 않습니다.

또한, 내가 ADAMM의 도움으로 고정 또 다른 큰 장애물이었다 인식되지 않은 xml 파일 : 행을 주석 나는 R 가져 오기

이 삭제

1))이 모든

1

당신은 main.xml 메뉴를 팽창했다. 당신이 팽창 할 필요가있는 createlgmenu.xml이 아닌가?

0

내 측면에서 잘 작동하는지 아래에서 시도해보십시오. 희망은 또한 당신을 위해 일할 것입니다.

public class MainActivity extends Activity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     // Button Save = (Button) this.findViewById(R.id.SaveButton); 
    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.main, menu); 
     return true; 
    } 

    public void onCreateLGClick(View v) { 
     final int id = v.getId(); 

     switch (v.getId()) { 
     case R.id.CreateLG: 
      findViewById(R.id.GetStarted).setVisibility(View.INVISIBLE); 
      createLGMenu(v); 
      break; 
     case R.id.ListsButton: 
      findViewById(R.id.GetStarted).setVisibility(View.VISIBLE); 
      createLGMenu(v); 
      break; 
     } 

    } 

    public void createLGMenu(View v) { 
     PopupMenu LGMenu = new PopupMenu(this, v); 
     LGMenu.getMenuInflater().inflate(R.menu.createmenu, LGMenu.getMenu()); 
     LGMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { 

      @Override 
      public boolean onMenuItemClick(MenuItem item) { 
       switch (item.getItemId()) { 
       case R.id.Create_List: 
        createListDialog(); 
        break; 
       case R.id.Create_Food_Group: 
        createListDialog(); 
        break; 

       default: 
        break; 
       } 
       /* 
       * String choice = new String((String) item.getTitle()); if 
       * (choice.equalsIgnoreCase("Create_List")){ createListDialog(); 
       * } else if (choice.equalsIgnoreCase("Create_Group")) { 
       * createListDialog(); } 
       */ 
       return true; 
      } 
     }); 
     LGMenu.show(); 
    } 

    public AlertDialog.Builder dialogBuilder; 

    private void createListDialog() { 
     dialogBuilder = new AlertDialog.Builder(this); 
     EditText textInput = new EditText(this); 

     dialogBuilder.setTitle("Create list"); 
     dialogBuilder.setMessage("Name your list: "); 
     dialogBuilder.setView(textInput); 
     dialogBuilder.setPositiveButton("Create", 
       new DialogInterface.OnClickListener() { 

        @Override 
        public void onClick(DialogInterface dialog, int which) { 
         findViewById(R.id.ListName).setVisibility(
           View.INVISIBLE); 
         // Toast.makeText(getApplicationContent(), 
         // "List has been created.", toast.LENGTH_SHORT); 
         // add list to ListsButton 
         // findViewById(R.id.ListName). -> Change ListName text 
         // to created list 
        } 
       }); 
     dialogBuilder.setNegativeButton("Cancel", 
       new DialogInterface.OnClickListener() { 

        @Override 
        public void onClick(DialogInterface dialog, int which) { 
         // Toast.makeText(getApplicationContent(), 
         // "List has been created.", toast.LENGTH_SHORT); 
        } 
       }); 
     // Output 
     AlertDialog dialogue = dialogBuilder.create(); 
     dialogue.show(); 

    } 

} 
+0

불행히도 이클립스는 bin/resource.ap_가 "존재하지 않는다"때문에 아무 것도 시도하지 못하게하면 이것을 시도 할 것이다. 나는 모든 종류의 솔루션을 시도하고 있지만 아직 해결하지 못했습니다. 나는 이클립스를 재설치 하겠지만 문제가되는 파일이없는 폴더는 내 폴더 다. – user2100364

관련 문제