2013-03-21 18 views
0

我想在我的應用程序中添加的ImageButton但是當我嘗試運行它,我得到這個錯誤:的ImageButton得到錯誤

03-21 14:57:41.936: E/AndroidRuntime(794): java.lang.RuntimeException: Unable to start activity ComponentInfo{br.com.facilit.target.app.android/br.com.facilit.target.app.android.LoginActivity}: android.view.InflateException: Binary XML file line #78: Error inflating class android.widget.ImageButton 

我的XML代碼:

<ImageButton 
      android:id="@+id/btnEntrar" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignRight="@+id/txtFieldSenha" 
      android:layout_below="@+id/txtFieldSenha" 
      android:layout_marginTop="25dp" 
      android:background="@style/AppTheme" 
      android:contentDescription="@string/btn_entrar_desc" 
      android:src="@drawable/login_btn_entrar" /> 

Java代碼:

public class LoginActivity extends Activity { 

    ImageButton btnEntrar; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     this.requestWindowFeature(Window.FEATURE_NO_TITLE); 
     setContentView(R.layout.activity_login); 

     addListenerOnButton(); 

    } 

    private void addListenerOnButton() { 

     btnEntrar = (ImageButton) findViewById(R.id.btnEntrar); 

     final EditText email = (EditText) findViewById(R.id.txtFieldLogin); 
     final EditText token = (EditText) findViewById(R.id.txtFieldSenha); 

     btnEntrar.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View v) { 

       Log.d(Constants.LOGIN_ACTIVITY, email.getText().toString().trim()); 
       Log.d(Constants.LOGIN_ACTIVITY, token.getText().toString().trim()); 

      } 
     }); 

    } 
+0

清潔您的項目,然後再試一次。 – razielsarafan 2013-03-21 15:07:56

回答

1

你可能不希望使用

android:background="@style/AppTheme" 

但是你的編輯器應該在XML中指出你的錯誤錯誤。嘗試一個乾淨的,如果它沒有構建。

+0

如果我不使用它,按鈕帶有邊框。我清理它,但問題仍然存在 – 2013-03-21 16:09:46

-1

您正在使用@ + IDlayout_alignRightlayout_below

嘗試清除+。 它應該看起來像這樣

<ImageButton 
      android:id="@+id/btnEntrar" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignRight="@id/txtFieldSenha" 
      android:layout_below="@id/txtFieldSenha" 
      android:layout_marginTop="25dp" 
      android:background="@style/AppTheme" 
      android:contentDescription="@string/btn_entrar_desc" 
      android:src="@drawable/login_btn_entrar" /> 
+0

不,它不應該。 – 2013-03-22 07:32:08

+0

@Stefan +信號用於創建新的ID。如果您正在對另一個視圖進行引用,那麼爲什麼要使用+?向我解釋請 – 2013-03-22 11:40:34

+0

如果你使用android:layout_below =「@ id/txtFieldSenha」,並且你的ImageButton下面定義了txtFieldSenha,它會崩潰,因爲還沒有這樣的id。使用+會防止這種情況。 – 2013-03-22 12:38:19