I'm creating a simple paint application that calls the `changeColor()` method in my main activity through an image button via `android:onClick="changeColor"` in my layout file. I have the image buttons in my main linear layout and in a layout that is displayed via a dialog box. The 2 layouts have the same code for the image buttons but it is crashing when I try to change color via the layout XML file from the dialog. The error I get says it can not find the `changeColor()` method. What is the best approach to take to solve my error.

**MainActivity.java**

```
public class MainActivity extends ActionBarActivity implements OnClickListener {
private PaintView pView;
private ImageButton currentColor;

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

    pView = (PaintView) findViewById(R.id.drawing);
    LinearLayout paintLayout = (LinearLayout) findViewById(R.id.paint_colors);
    currentColor = (ImageButton) paintLayout.getChildAt(0);
    currentColor.setImageDrawable(getResources().getDrawable(
            R.drawable.paint_pressed));

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {

    super.onCreateOptionsMenu(menu);
    MenuInflater menuInflater = getMenuInflater();
    menuInflater.inflate(R.menu.main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    switch (item.getItemId()) {
    case R.id.color:
        Toast.makeText(getApplicationContext(), "edit selected",
                Toast.LENGTH_SHORT).show();

        Dialog brushColorDialog = new Dialog(this);
        brushColorDialog.setTitle("Brush Color:");
        brushColorDialog.setContentView(R.layout.colors);
        brushColorDialog.show();
        return true;
    case R.id.brush:
        Dialog brushSizeDialog = new Dialog(this);
        brushSizeDialog.setTitle("Brush Size:");
        brushSizeDialog.setContentView(R.layout.brush_chooser);
        Toast.makeText(getApplicationContext(), "Brush Dialog goes here",
                Toast.LENGTH_SHORT).show();
        brushSizeDialog.show();
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }

}

public void changeColor(View view) {
    // use chosen color
    if (view != currentColor) {
        // update color
        ImageButton imgView = (ImageButton) view;
        String color = view.getTag().toString();
        pView.setColor(color);
        imgView.setImageDrawable(getResources().getDrawable(
                R.drawable.paint_pressed));
        currentColor.setImageDrawable(getResources().getDrawable(
                R.drawable.paint));
        currentColor = (ImageButton) view;
    }
}

@Override
public void onClick(View v) {
    // TODO Auto-generated method stub

}

}

```

**colors.xml**

```
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
 android:layout_height="400dp"
 android:gravity="center"
 android:orientation="vertical" >

<LinearLayout
    android:id="@+id/paint_colors"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <ImageButton
        android:layout_width="@dimen/large_tile"
        android:layout_height="@dimen/large_tile"
        android:layout_margin="0dp"
        android:background="#FFFF0000"
        android:contentDescription="@string/paint"
        android:onClick=""
        android:src="@drawable/paint"
        android:tag="#FFFF0000" />

    <ImageButton
        android:layout_width="@dimen/large_tile"
        android:layout_height="@dimen/large_tile"
        android:layout_margin="0dp"
        android:background="#FF800000"
        android:contentDescription="@string/paint"
        android:onClick="changeColor"
        android:src="@drawable/paint"
        android:tag="#FF800000" />

    <ImageButton
        android:layout_width="@dimen/large_tile"
        android:layout_height="@dimen/large_tile"
        android:layout_margin="0dp"
        android:background="#FFFFFF00"
        android:contentDescription="@string/paint"
        android:onClick="changeColor"
        android:src="@drawable/paint"
        android:tag="#FFFFFF00" />

    <ImageButton
        android:layout_width="@dimen/large_tile"
        android:layout_height="@dimen/large_tile"
        android:layout_margin="0dp"
        android:background="#FF808000"
        android:contentDescription="@string/paint"
        android:onClick="changeColor"
        android:src="@drawable/paint"
        android:tag="#FF808000" />
</LinearLayout>
<!-- Bottom Row -->

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <ImageButton
        android:layout_width="@dimen/large_tile"
        android:layout_height="@dimen/large_tile"
        android:layout_margin="0dp"
        android:background="#FF00FF00"
        android:contentDescription="@string/paint"
        android:onClick="changeColor"
        android:src="@drawable/paint"
        android:tag="#FF00FF00" />

    <ImageButton
        android:layout_width="@dimen/large_tile"
        android:layout_height="@dimen/large_tile"
        android:layout_margin="0dp"
        android:background="#FF008000"
        android:contentDescription="@string/paint"
        android:onClick="changeColor"
        android:src="@drawable/paint"
        android:tag="#FF008000" />

```

**activity\_main.xml**

```
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFCCCCCC"
android:orientation="vertical"
tools:context=".MainActivity" >

<net.soloq.paint4.PaintView
android:id="@+id/drawing"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_marginBottom="3dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="3dp"
android:layout_weight="1"
android:background="#FFFFFFFF" />
<!-- Top Row -->
<LinearLayout
android:id="@+id/paint_colors"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
   <ImageButton
android:layout_width="@dimen/large_brush"
android:layout_height="@dimen/large_brush"
android:layout_margin="2dp"
android:background="#FF660000"
android:contentDescription="@string/paint"
android:onClick="changeColor"
android:src="@drawable/paint"
android:tag="#FF660000" />

<ImageButton
android:layout_width="@dimen/large_brush"
android:layout_height="@dimen/large_brush"
android:layout_margin="2dp"
android:background="#FFFF0000"
android:contentDescription="@string/paint"
android:onClick="changeColor"
android:src="@drawable/paint"
android:tag="#FFFF0000" />

```

The image buttons from the activity\_main.xml work just fine but it crashes on colors.xml

Thanks in advance!