2013-03-11 57 views
1

這是我第一次嘗試創建一個android應用程序,所以我一直在犯很多惱人的初學者錯誤!現在我只是想創建一個非常簡單的登錄/註冊系統。但是,我似乎誤解了如何處理用戶輸入的輸入。 從以前的文章中我已經看到了這裏,我試圖做這樣的事情:Android SDK:findViewById(int)未定義類型

//in Register class 
public void submission(View view){ 
    //Call User Constructor based on info received from Registration Activity 
    EditText enteredUser = (EditText)findViewbyId(R.id.enteredUser); 
    //then use the input from this field to do other stuff  

} 

但是出於某種原因,我不斷收到錯誤findViewById(INT)是未定義的類型註冊(我目前所在班級的名字)。有人能告訴我我做錯了什麼嗎?我很確定我在頂部有正確的導入語句(android.widget.EditText)。

這裏是相應的XML代碼:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
tools:context=".Register" > 

<TextView 
    android:id="@+id/textView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Enter New UserName:" /> 

<EditText 
    android:id="@+id/enteredUser" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignLeft="@+id/textView1" 
    android:layout_below="@+id/textView1" 
    android:ems="10" > 

    <requestFocus /> 
</EditText> 

...more input buttons etc... 

<Button 
    android:id="@+id/button1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignLeft="@+id/confirmPass" 
    android:layout_alignParentBottom="true" 
    android:layout_marginBottom="64dp" 
    android:onClick = "submission" <----- Used to call the submission function after 
    android:text="Submit" />    all inputs have been filled 

</RelativeLayout> 

對不起,我有點長篇大論的問題,但我將不勝感激任何幫助。

謝謝!

+0

是的,即公共類Register擴展Activity {}(它包含我定義的java函數) – 2013-03-11 00:24:48

+0

嘗試清理你的項目。我也很好奇,這是IDE唯一說你有錯誤的東西嗎?或任何Android相關@HoanNguyen這是一個編譯時錯誤,findViewById()是Activity的一部分。 – 2013-03-11 00:26:32

+0

不,我一直關注的教程沒有說明我是否應該這樣做。我在哪裏打電話給這個? – 2013-03-11 00:27:59

回答

2

你編譯時錯誤是由於輸入錯誤的:

findViewbyId 

需求是

findViewById 

然後確保調用super.onCreate(savedInstanceState)之後調用setContentView()。我強烈建議遵循Building Your First App教程,並明確注意代碼。

和往常一樣,familiarize yourself with the documentation。如果您有編譯時錯誤,請先檢查它,您可能只是有一個錯字!

+0

哇,就是這樣。如此愚蠢! – 2013-03-11 00:29:38

+0

非常感謝,我接下來的教程有b作爲小寫以及... – 2013-03-11 00:29:58

+1

@WakkaWakkaWakka看起來像寫了它的人一心一意的努力。構建您的第一個應用程序是一個很好的來源,以及Vogella教程。 – 2013-03-11 00:31:59

相關問題