安卓系统:活动启动时出现奇怪的崩溃.与XML布局排序有关



他一直在让我发疯,我希望有人能为我阐明这一点。

我在XML文件中重复了以下XML布局3次,一切都很好,直到。。。我通过<ImageView>标签添加了一个背景图像,并将所述图像与SeekBar的底部对齐,我更改了周围的@+id,使imageview具有+。现在奇怪的是,我可以对最后一个布局组这样做,但不能对其他任何一个进行。为了篇幅起见,我在这里包括了两个。后一种效果不错。然而,它允许我将第二个(在下面的第一个列表(recordBox)中)直接放在搜索栏上方,但不放在linearlayout上方(我希望它在TextView上方,所以它在后面),这就是崩溃开始的时候。我也试着把上一个摘下来,只穿上这个,仍然没有快乐。

我刚刚注意到的另一件事是,我也可以使用在两个playBackSeek引用上都有@+id的playBackBox。

有什么想法吗?

 <RelativeLayout
       android:id="@+id/recordBox"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:layout_below="@id/intervalBox"
       android:orientation="vertical"
        >
    <ImageView android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:scaleType="fitXY"
      android:src="@drawable/background"    
      android:layout_alignBottom="@+id/recordSeek"
        />    
          <TextView  android:id="@+id/recordHeader"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Record Duration"
            android:gravity="left"
            android:paddingTop="10dp"
            android:layout_marginLeft="70dp"
            android:textColor="#000000"
            />    
           <LinearLayout  android:id="@+id/record2ndBox"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:layout_below="@id/recordHeader"
            android:layout_alignLeft="@id/recordHeader"
            >
                <EditText
                    android:id="@+id/recordValue"
                    android:layout_width="75dp"
                    android:layout_height="40dp"
                    android:text="50"
                    android:textSize="14sp"
                    android:gravity="center"
                    android:inputType="number" 
                    android:layout_marginRight="10dp" 
                    />    
                <Spinner android:id="@+id/recordType"
                    android:layout_width="140dp"
                    android:layout_height="40dp"
                    android:drawSelectorOnTop="false"
                    android:layout_marginTop="1dp"
                    /> 
            </LinearLayout>  
          <SeekBar android:id="@id/recordSeek"
               android:layout_width="fill_parent"
               android:layout_height="wrap_content"
               android:max="100"
               android:progress="50"
               android:layout_below="@id/record2ndBox"
               android:layout_alignLeft="@id/recordHeader"
               android:paddingBottom="20dp"
               android:paddingRight="20dp"
           /> 

    </RelativeLayout> 
   <RelativeLayout
       android:id="@+id/playBackBox"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:layout_below="@id/recordBox"
       android:orientation="vertical"
        >

     <ImageView android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:scaleType="fitXY"
      android:src="@drawable/background"    
      android:layout_alignBottom="@+id/playBackSeek"
        />

              <TextView  android:id="@+id/playBackHeader"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Play Back Duration"
            android:gravity="left"
            android:paddingTop="10dp"
            android:layout_marginLeft="70dp"
            android:textColor="#000000"
            />    
           <LinearLayout  android:id="@+id/playBack2ndBox"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:layout_below="@id/playBackHeader"
            android:layout_alignLeft="@id/playBackHeader"
            >
                <EditText
                    android:id="@+id/playBackValue"
                    android:layout_width="75dp"
                    android:layout_height="40dp"
                    android:text="50"
                    android:textSize="14sp"
                    android:gravity="center"
                    android:inputType="number" 
                    android:layout_marginRight="10dp" 
                    />    
                <Spinner android:id="@+id/playBackType"
                    android:layout_width="140dp"
                    android:layout_height="40dp"
                    android:drawSelectorOnTop="false"
                    android:layout_marginTop="1dp"
                    /> 
            </LinearLayout>  
          <SeekBar android:id="@id/playBackSeek"
               android:layout_width="fill_parent"
               android:layout_height="wrap_content"
               android:max="100"
               android:progress="50"
               android:layout_below="@id/playBack2ndBox"
               android:layout_alignLeft="@id/playBackHeader"
               android:paddingBottom="20dp"
               android:paddingRight="20dp"
           /> 
    </RelativeLayout>  

这是错误转储。

    03-21 17:26:26.934: E/AndroidRuntime(621): FATAL EXCEPTION: main
03-21 17:26:26.934: E/AndroidRuntime(621): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mediabar.timelapse/com.mediabar.timelapse.TimeLapseCalculator}: java.lang.ClassCastException: android.widget.Spinner
03-21 17:26:26.934: E/AndroidRuntime(621):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
03-21 17:26:26.934: E/AndroidRuntime(621):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
03-21 17:26:26.934: E/AndroidRuntime(621):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
03-21 17:26:26.934: E/AndroidRuntime(621):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
03-21 17:26:26.934: E/AndroidRuntime(621):  at android.os.Handler.dispatchMessage(Handler.java:99)
03-21 17:26:26.934: E/AndroidRuntime(621):  at android.os.Looper.loop(Looper.java:123)
03-21 17:26:26.934: E/AndroidRuntime(621):  at android.app.ActivityThread.main(ActivityThread.java:4627)
03-21 17:26:26.934: E/AndroidRuntime(621):  at java.lang.reflect.Method.invokeNative(Native Method)
03-21 17:26:26.934: E/AndroidRuntime(621):  at java.lang.reflect.Method.invoke(Method.java:521)
03-21 17:26:26.934: E/AndroidRuntime(621):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
03-21 17:26:26.934: E/AndroidRuntime(621):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
03-21 17:26:26.934: E/AndroidRuntime(621):  at dalvik.system.NativeStart.main(Native Method)
03-21 17:26:26.934: E/AndroidRuntime(621): Caused by: java.lang.ClassCastException: android.widget.Spinner
03-21 17:26:26.934: E/AndroidRuntime(621):  at com.mediabar.timelapse.TimeLapseCalculator.onCreate(TimeLapseCalculator.java:154)
03-21 17:26:26.934: E/AndroidRuntime(621):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-21 17:26:26.934: E/AndroidRuntime(621):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)

按要求创建

   @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState); //anim is coming in, going out
        overridePendingTransition(R.anim.pull_right_in, R.anim.push_left_out);
        setContentView(R.layout.calculator);
        HDDResults = (TextView)findViewById(R.id.HDDResults);
        timeResults = (TextView)findViewById(R.id.TimeResults);      
        extraResults = (TextView)findViewById(R.id.ExtraResults);  
        HDDResults.setText("HDD:");
        timeResults.setText("time Results Area:");
        extraResults.setText("Extra Results Area:");
        radioGroup = (RadioGroup) findViewById(R.id.calcBy);
        rb1 = (RadioButton) findViewById(R.id.byInterval);
        rb2 = (RadioButton) findViewById(R.id.byRecord);
        rb3 = (RadioButton) findViewById(R.id.byPlayBack);
        radioGroup.setOnCheckedChangeListener(this);
        intSeek = (SeekBar)findViewById(R.id.intervalSeek);
        intSeek.setOnSeekBarChangeListener(this);
        intTextValue = (EditText)findViewById(R.id.intervalValue);
        intTextValue.setOnFocusChangeListener(this);
        intTextValue.addTextChangedListener(this);
        intType=(Spinner)findViewById(R.id.intervalType); 
        intType.setOnItemSelectedListener(this);
        ArrayAdapter<String> intTypelist=new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,intTypeItems);
        intTypelist.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        intType.setAdapter(intTypelist); 
        recSeek = (SeekBar)findViewById(R.id.recordSeek);
        recSeek.setOnSeekBarChangeListener(this);
        recTextValue = (EditText)findViewById(R.id.recordValue);
        recTextValue.setOnFocusChangeListener(this);
        recTextValue.addTextChangedListener(this);
        recType=(Spinner)findViewById(R.id.recordType);        
        recType.setOnItemSelectedListener(this);
        ArrayAdapter<String>    recTypelist=new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,recTypeItems);        
        recTypelist.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);   
        recType.setAdapter(recTypelist);    
        playSeek = (SeekBar)findViewById(R.id.playBackSeek);
        playSeek.setOnSeekBarChangeListener(this);
        playTextValue = (EditText)findViewById(R.id.playBackValue);
        playTextValue.setOnFocusChangeListener(this);
        playTextValue.addTextChangedListener(this);
        playType=(Spinner)findViewById(R.id.playBackType);
        playType.setOnItemSelectedListener(this);   
        ArrayAdapter<String>    playTypelist=new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,playTypeItems);              
        playTypelist.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);     
        playType.setAdapter(playTypelist);         
    }

Try projects>Clean如果您在eclipse上,应该可以解决所有这些问题。如果不重新启动eclipse。在有人告诉我这是xml文件在其组件上构建的方式之前,我遇到了这样的问题。它可能混淆了。