0

ボタンをクリックすると、ロードした7つの画像のいずれかに画像がランダムに変化する基本的なアプリを実行しようとしています.png。私はいくつかの異なる方法を試しましたが、それを機能させることができないようです。これが今の私のコードです:

.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/RelativeLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity"
    android:background="@color/black" >

   <Button
       android:id="@+id/button1"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
       android:layout_alignParentBottom="true"
       android:layout_marginBottom="40dp"
       android:background="@color/white"
       android:text="@string/black" 
       android:onClick="onClick"/>

   <ImageView
        android:id="@+id/image1"
        android:layout_width="320dp"
        android:layout_height="250dp"
        android:scaleType="fitXY"
        android:contentDescription="@string/black" />

</RelativeLayout>

.java

public class Black extends Activity {

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.black);
    }

    public void onClick() {

        ImageView imageView = (ImageView)findViewById(R.id.image1);

        int[] picture={R.drawable.black,R.drawable.blackairplane,R.drawable.blackbear,R.drawable.blackcircle,R.drawable.blackkite,R.drawable.blacksquare,R.drawable.blacktriangle};
         Random r = new Random();
         int n=r.nextInt(7);
         imageView.setImageResource(picture[n]);
    }
}

Eclipse のエラー メッセージには次のように表示されます。

java.lang.RuntimeException: Unable to instantiate activity ComponentInfo

助けてくれてありがとう。

4

3 に答える 3