2013-08-24 123 views
-1

我正在學習此Java語言並試圖製作自己的應用程序,但每次輸入此方法時都會出現此錯誤。它怎麼會給我這個錯誤? 我下面從特拉維斯YouTube上的教程和他沒有得到這個errror,我不能想出解決辦法..Eclipse android中,findIdByView(int)方法未定義爲類型爲xxxxxxx

package com.nichlas.denfoerste; 


import android.app.Activity; 
import android.os.Bundle; 
import android.widget.EditText; 
import android.widget.RadioGroup; 
import android.widget.RadioGroup.OnCheckedChangeListener; 
import android.widget.TextView; 

public class TutorialOne extends Activity implements OnCheckedChangeListener{ 

TextView textOut; 
EditText textIn; 
RadioGroup gravityG, styleG; 


@Override 
protected void onCreate(Bundle savedInstanceState) { 
    // TODO Auto-generated method stub 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.tutorial1); 
    textOut = (TextView) findIdByView(R.id.tvChange); 

} 


@Override 
public void onCheckedChanged(RadioGroup arg0, int arg1) { 
    // TODO Auto-generated method stub 

} 
} 

我的XML文件

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" > 

<EditText 
    android:id="@+id/editText1" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:ems="10" > 
</EditText> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" > 

    <TextView 
     android:id="@+id/tvStyle" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="0.50" 
     android:gravity="center" 
     android:text="Style" 
     android:textSize="25sp" /> 

    <TextView 
     android:id="@+id/tvGravity" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="0.50" 
     android:gravity="center" 
     android:text="Gravity" 
     android:textSize="25sp" /> 

</LinearLayout> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" > 

    <RadioGroup 
     android:id="@+id/rgStyle" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="0.50" > 

     <RadioButton 
      android:id="@+id/rbNormal" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:checked="true" 
      android:text="Normal" /> 

     <RadioButton 
      android:id="@+id/rbItalic" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Italic" /> 

     <RadioButton 
      android:id="@+id/rbBold" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Bold" /> 
    </RadioGroup> 

    <RadioGroup 
     android:id="@+id/rgGravity" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="0.50" > 

     <RadioButton 
      android:id="@+id/rbLeft" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:checked="true" 
      android:text="Left" /> 

     <RadioButton 
      android:id="@+id/rbCenter" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Center" /> 

     <RadioButton 
      android:id="@+id/rbRight" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Right" /> 
    </RadioGroup> 
</LinearLayout> 

<TextView 
    android:id="@+id/tvChange" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:gravity="center" 
    android:text="Generate here" /> 

<Button 
    android:id="@+id/bGenerate" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="Generate" 
    android:textSize="25sp" /> 

</LinearLayout> 
+1

開玩笑它不是findIdByView ..它只是findViewById ...閱讀開始的Android http://developer.android.com/reference/android/widget/Button.html做節目 – Amsheer

回答

2

嘗試更換以下行。

textOut = (TextView) findIdByView(R.id.tvChange); 

textOut = (TextView) findViewById(R.id.tvChange); 
+0

謝謝你這麼多了。 。:D HAHA ..我有多愚蠢......有時候會有一些新的眼睛......;) – Niller

0
textOut = (TextView) findIdByView(R.id.tvChange); 

與波紋線替換此...

textOut = (TextView) findViewById(R.id.tvChange); 

和你做。

相關問題