0

avdで実行されている強制終了エラーを発生させているコードは次のとおりです

public class MainActivity extends Activity {


Button magic;
TextView display;
int random;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


    magic=(Button)findViewById(R.id.magic);
    display=(TextView)findViewById(R.id.textView1);
    magic.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            random = (int)Math.ceil(Math.random()*100);

            display.setText("your number is"+random);

        }
    });

    }
}

ランダム関数またはsettextが使用されていない場合でも、私が使用しているコードは次のとおりですアプリケーションの強制終了助けてください

activity_main.xml でエラーや警告が表示されない........

xml ファイル

<RelativeLayout 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="@drawable/magic8ball"
    android:gravity="center"
    tools:context=".MainActivity" >

    <android.widget.Space
        android:id="@+id/space1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_marginRight="144dp"
        android:layout_marginTop="192dp" />

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="131dp"
        android:layout_marginTop="171dp"
        android:orientation="vertical" >
    </LinearLayout>

    <Button
        android:id="@+id/magic"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/linearLayout1"
        android:layout_toRightOf="@+id/linearLayout1"
        android:text="@string/Magic" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/Magic"
        android:layout_alignParentRight="true"
        android:layout_marginBottom="64dp"
        android:layout_marginRight="74dp"
       android:text="@string/Ask"
android:textAppearance="?     android:attr/textAppearanceLarge"
        android:textColor="#EE5533" />

</RelativeLayout>

xml ファイルは、ハードコードされたときに単一の waring が textview1 に関連している場所に指定されています

テキストはstring.xmlに設定するか、ハードコードするのが良いかどうか変更されようとしているため?????

4

1 に答える 1

0

次のコードを使用している目的は何ですか。

**<android.widget.Space
        android:id="@+id/space1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_marginRight="144dp"
        android:layout_marginTop="192dp" />**

これは利用できないようです..ICSデバイスでは正常に動作します..しかし、Gingerbreadデバイスでは動作しません..それは使用できないコードだと思います...

于 2012-12-20T10:19:58.103 に答える