2012-03-21 121 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