-6

我知道我已经问过这个问题但是在第一个答案之后没有人回答我改变了他告诉我的内容仍然没有结果

主页.java

package com.example.decrypter;

import android.os.Bundle;
import android.app.Activity;
import android.app.Application;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.AdapterView.OnItemSelectedListener;

public class Home extends Activity implements OnItemSelectedListener {

Button btn_start,btn_about,btn_exit;
@Override 
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.home);

btn_start = (Button) findViewById(R.id.btn_start);
 btn_about = (Button) findViewById(R.id.btn_about);
 btn_exit = (Button) findViewById(R.id.btn_exit);



btn_start.setOnClickListener( new View.OnClickListener() 
{ 



   public void onClick(View v) {
       Intent start = new Intent(Home.this, MainPage.class);
       Home.this.startActivity(start);


}
 });
 btn_about.setOnClickListener( new View.OnClickListener() 
 { 



   public void onClick(View v) {
    // TODO Auto-generated method stub
      Intent about = new Intent(Home.this, about.class);
       Home.this.startActivity(about);


}
  });
 btn_exit.setOnClickListener( new View.OnClickListener() 
 { 



   public void onClick(View v) {
    // TODO Auto-generated method stub
    System.exit(0);

}
 });
 }












 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.layout.home, menu);
    return true;



 }

@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
        long arg3) {
    // TODO Auto-generated method stub

}

@Override
public void onNothingSelected(AdapterView<?> arg0) {
    // TODO Auto-generated method stub

}

}

主页.java

package com.example.decrypter;

import android.os.Bundle;
import android.app.Activity;
import android.graphics.Color;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.SpinnerAdapter;
import android.widget.TextView;

 public class MainPage extends Activity implements OnItemSelectedListener {
double random1,random2,random3,random4,random5;
int check1,check2,check3,check4,check5;

EditText textbox;
int guess;
String s1,s2,s3,s4,s5;
Spinner spinner1,spinner2,spinner3,spinner4,spinner5;
TextView display1,display2,display3,display4,display5;
Integer[] numbers = {1,2,3,4,5,6,7,8,9};


   @Override
   public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    ArrayAdapter <Integer> adapter1 = new ArrayAdapter <Integer>(this,  
      android.R.layout.simple_spinner_item, numbers);

    setContentView(R.layout.activity_main_page);

    spinner1 =(Spinner) findViewById(R.id.spinner01);
    spinner2= (Spinner) findViewById(R.id.spinner02);
    spinner3= (Spinner) findViewById(R.id.spinner03);
    spinner4= (Spinner) findViewById(R.id.spinner04);
    spinner5= (Spinner) findViewById(R.id.spinner05);


     display1 = (TextView) findViewById(R.id.txtdisplay1);
     display2 = (TextView) findViewById(R.id.txtdisplay2);
     display3 = (TextView) findViewById(R.id.txtdisplay3);
     display4 = (TextView) findViewById(R.id.txtdisplay4);
     display5 = (TextView) findViewById(R.id.txtdisplay5);
    Button btnrandom = (Button) findViewById(R.id.btnrandom);
    Button btn1 = (Button) findViewById(R.id.btn1);






    spinner1.setAdapter(adapter1);
    spinner1.setOnItemSelectedListener(this);
    spinner2.setAdapter(adapter1);
    spinner2.setOnItemSelectedListener(this);
    spinner3.setAdapter(adapter1);
    spinner3.setOnItemSelectedListener(this);
    spinner4.setAdapter(adapter1);
    spinner4.setOnItemSelectedListener(this);
    spinner5.setAdapter(adapter1);
    spinner5.setOnItemSelectedListener(this);





    btnrandom.setOnClickListener( new View.OnClickListener() 
   { 



       public void onClick(View v) {
        // TODO Auto-generated method stub
        random1 = Math.floor(Math.random()*10);
        random2 = Math.floor(Math.random()*10);
        random3 = Math.floor(Math.random()*10);
        random4 = Math.floor(Math.random()*10);
        random5 = Math.floor(Math.random()*10);
        //display.setText("random:" + random1);



        /*check1 = Integer.parseInt(spinner1.getSelectedItem().toString()) ;

        */


    }
   });


    btn1.setOnClickListener( new View.OnClickListener() 
   { 



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




        if(check1==random1){
            display1.setTextColor(Color.GREEN);
            s1= Integer.toString(check1);
            display1.setText(s1);
        }
        else{
            display1.setTextColor(Color.RED);
            s1= Integer.toString(check1);
            display1.setText(s1);
            }

        if(check2==random2){
            display2.setTextColor(Color.GREEN);
            s2= Integer.toString(check2);
            display2.setText(s2);
            }
        else{
            display2.setTextColor(Color.RED);
            s2= Integer.toString(check2);
            display2.setText(s2);
            }

        if(check3==random3){
            display3.setTextColor(Color.GREEN);
            s3= Integer.toString(check3);
            display3.setText(s3);
            }
        else{
            display3.setTextColor(Color.RED);
            s3= Integer.toString(check3);
            display3.setText(s3);
            }

        if(check4==random4){
            display4.setTextColor(Color.GREEN);
            s4= Integer.toString(check4);
            display4.setText(s4);
            }
        else{
            display4.setTextColor(Color.RED);
            s4= Integer.toString(check4);
            display4.setText(s4);
            }

        if(check5==random5){
            display5.setTextColor(Color.GREEN);
            s5= Integer.toString(check5);
            display5.setText(s5);
            }
        else{
            display5.setTextColor(Color.RED);
            s5= Integer.toString(check5);
            display5.setText(s5);
            }

    }
   });


















}





 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.layout.activity_main_page, menu);
    return true;



}





@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
        long arg3) {
    // TODO Auto-generated method stub


    check1 = Integer.parseInt(spinner1.getSelectedItem().toString());


    check2 = Integer.parseInt(spinner2.getSelectedItem().toString()) ;


    check3 = Integer.parseInt(spinner3.getSelectedItem().toString()) ;

    check4 = Integer.parseInt(spinner4.getSelectedItem().toString()) ;


    check5 = Integer.parseInt(spinner5.getSelectedItem().toString()) ;

    }







@Override
public void onNothingSelected(AdapterView<?> arg0) {
    // TODO Auto-generated method stub

}





}

飞溅.java

 package com.example.decrypter;

 import android.app.Activity;
 import android.content.Intent;
 import android.media.MediaPlayer;
 import android.os.Bundle;

      public class Splash extends Activity {
MediaPlayer splashSong;
@Override
protected void onCreate(Bundle splashpage) {
    // TODO Auto-generated method stub
    super.onCreate(splashpage);
    setContentView(R.layout.splash);
    splashSong = MediaPlayer.create(Splash.this, R.raw.splashsound);
    splashSong.start();


    Thread timer = new Thread(){
        public void run(){
            try{
                sleep(5000);
            } catch (InterruptedException e){
                e.printStackTrace();
            } finally {
                Intent openHome = new Intent  
                                                  ("com.example.decrypter.HOME");
                startActivity(openHome);
            }
        }
    };
    timer.start();

}

@Override
protected void onPause() {
    // TODO Auto-generated method stub
    super.onPause();
    //splashSong.release();
    finish();
}




  }

安卓清单.xml

 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.example.decrypter"
 android:versionCode="1"
   android:versionName="1.0" >

 <uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="15" />

 <application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".Splash"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".Home"
        android:label="@string/title_activity_home" >
        <intent-filter>
            <action android:name="com.example.decrypter.HOME" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
     <activity
        android:name=".about"
        android:label="about" >
        <intent-filter>
            <action android:name="com.example.decrypter.ABOUT" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
     <activity
        android:name=".MainPage"
        android:label="MainPage" >
        <intent-filter>
            <action android:name="com.example.decrypter.MAINPAGE" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
     </activity>
 </application>

 </manifest>

LOGCAT 错误

12-11 11:36:27.182: D/dalvikvm(336): GC_EXTERNAL_ALLOC freed 55K, 53% free 2570K/5379K, external 2131K/2137K, paused 53ms
12-11 11:36:27.271: D/AndroidRuntime(336): Shutting down VM
12-11 11:36:27.271: W/dalvikvm(336): threadid=1: thread exiting with uncaught exception (group=0x40015560)
12-11 11:36:27.291: E/AndroidRuntime(336): FATAL EXCEPTION: main
12-11 11:36:27.291: E/AndroidRuntime(336): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.decrypter/com.example.decrypter.Home}: java.lang.ClassCastException: android.widget.RelativeLayout
12-11 11:36:27.291: E/AndroidRuntime(336):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
12-11 11:36:27.291: E/AndroidRuntime(336):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
12-11 11:36:27.291: E/AndroidRuntime(336):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
12-11 11:36:27.291: E/AndroidRuntime(336):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
12-11 11:36:27.291: E/AndroidRuntime(336):  at android.os.Handler.dispatchMessage(Handler.java:99)
12-11 11:36:27.291: E/AndroidRuntime(336):  at android.os.Looper.loop(Looper.java:123)
12-11 11:36:27.291: E/AndroidRuntime(336):  at android.app.ActivityThread.main(ActivityThread.java:3683)
12-11 11:36:27.291: E/AndroidRuntime(336):  at java.lang.reflect.Method.invokeNative(Native Method)
12-11 11:36:27.291: E/AndroidRuntime(336):  at java.lang.reflect.Method.invoke(Method.java:507)
12-11 11:36:27.291: E/AndroidRuntime(336):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
12-11 11:36:27.291: E/AndroidRuntime(336):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
12-11 11:36:27.291: E/AndroidRuntime(336):  at dalvik.system.NativeStart.main(Native Method)
12-11 11:36:27.291: E/AndroidRuntime(336): Caused by: java.lang.ClassCastException: android.widget.RelativeLayout
12-11 11:36:27.291: E/AndroidRuntime(336):  at com.example.decrypter.Home.onCreate(Home.java:23)
12-11 11:36:27.291: E/AndroidRuntime(336):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
12-11 11:36:27.291: E/AndroidRuntime(336):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
12-11 11:36:27.291: E/AndroidRuntime(336):  ... 11 more
4

2 回答 2

2

首先,尝试清理您的项目(例如,Eclipse 主菜单中的 Project > Clean)。如果这没有帮助,显然你有一个错误的RelativeLayout值。它使用的 ID 将基于您班级的第 23 行,无论是哪一行。activity_main_page.xmlandroid:idHome.java

于 2012-12-11T19:44:55.760 回答
1

你不值得,但是:

   12-11 11:36:27.291: E/AndroidRuntime(336): Caused by: java.lang.ClassCastException: android.widget.RelativeLayout
   12-11 11:36:27.291: E/AndroidRuntime(336):  at com.example.decrypter.Home.onCreate(Home.java:23)

这意味着......在 com.example.decrypter.Home.OnCreate 上,在第 23 行,您将某些内容投射到 RelativeLayout,它不是相对布局!

学习阅读,你必须,年轻的帕万!

于 2012-12-11T19:45:36.780 回答