0

Having some trouble with my app.

First some code:

package activities;

import prototype.R;

import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.LinearLayout;

public class Doodle extends Activity implements OnClickListener {
//buttons
private ImageButton colorBtn;
//dialogs
private Dialog brushDialog;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.doodle);

    //color button
    colorBtn = (ImageButton)findViewById(R.id.color_btn);
    colorBtn.setOnClickListener(this);

    //dialogs
    brushDialog = new Dialog(this);
    brushDialog.setTitle("Color chooser:");
    brushDialog.setContentView(R.layout.doodlepaintpalette);
    Log.i("<------------------------->", "Hello - 3");
}

@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;
}

//user clicked paint
public void paintClicked(View view){
    //Code here

    brushDialog.dismiss();
}

//Top bar buttons
@Override
public void onClick(View view){
    if(view.getId()==R.id.color_btn){
        brushDialog.show();
    }
}

"doodlepaintpalette" is a linear layout file containing various clickable imagebuttons with different colour codes. when I click the "color_btn" it correctly brings up the dialog, but when I click on one of the imagebuttons, the app crashes with this logcat:

E/AndroidRuntime(1486): java.lang.IllegalStateException: Could not find a method paintClicked(View) in the activity class android.view.ContextThemeWrapper for onClick handler on view class android.widget.ImageButton

The code worked fine when I had the image buttons in the "doodle" layout but since moving them to their own layout for use with the dialog, its created problems.

any help?

can post more code if need be

user2990037
  • 289
  • 4
  • 12

1 Answers1

0

You paintClicked() method is not found as the layout is inflated in the dialog, and it looks for the method in there, but your method is in your activity.

You'll find an answer here:

Using onClick attribute in layout xml causes a NoSuchMethodException in Android dialogs

Community
  • 1
  • 1
bgse
  • 7,474
  • 2
  • 32
  • 38