2012-03-21 34 views
2

他一直在推动我,我希望有人能为我揭示一些事情。Android:活动启动时奇怪的崩溃。关于XML布局的订购

我在我的xml文件中重复3次以下XML布局,并且一切正常,直到...我通过<ImageView>标记添加背景图像并将所述图像与SeekBar的底部对齐,然后更改@ + id的周围,所以imageview有+。 现在奇怪的是我可以做到这一点到最后一个布局组,但不是其他人。为了空间的缘故,我在这里包括了两个。后者是一种享受。然而,它会允许我把第二个(这在下面的第一个清单(recordBox)直接在seekbar上方,但不在linearlayout之上(并且我希望它在TextView之上,所以它在后面),那就是当崩溃开始时。我也试过把它从最后一个拿下来,只穿上这个,还没有快乐

我刚刚注意到的另一件事我也可以让playBackBox在playBackSeek上有@ + id引用。

任何想法了吗?

<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) 

的OnCreate的要求

@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);   

    } 
+1

你可以发布你的onCreate方法吗? – kishu27 2012-03-21 17:35:14

回答

3

尝试项目>清洁,如果你是在Eclipse中应该解决所有问题。如果不重新启动eclipse。在有人告诉我这是xml文件构建其组件的方式之前,我遇到过这样的问题。它可能混淆了。

+0

哦,我的上帝是多么riddiculus,我只是花了一小时的最好的一部分。是PROJECT> CLEAN做到了。我之前做过尝试重新启动Eclipse,但因为失败,我来到这里花10分钟填写问题。大声笑。非常感谢,将有一个项目>清理我认为的捷径 – Purplemonkey 2012-03-21 17:50:05