2015-08-28 65 views
1

我想要爲Android 4.2設備編程,但我擁有的書是教Android 4.0叫Beginning Android App Development 4。所以,我有針對性運行於Android 4.2的第一個程序問題:Android 4.0 vs 4.2 API差異

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

    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/hello" /> 

    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="This is my first Android Application!" /> 

    <Button 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="And this is a clickable button!" /> 

</LinearLayout> 

error: Error: No resource found that matches the given name (at 'text' with value '@string/hello'). activity_main.xml /HelloWorld/res/layout line 7 Android AAPT Problem

[I18N] Hardcoded string "And this is a clickable button!", should use @string resource activity_main.xml /HelloWorld/res/layout line 20 Android Lint Problem

[I18N] Hardcoded string "This is my first Android Application!", should use @string resource activity_main.xml /HelloWorld/res/layout line 15 Android Lint Problem

我想我在哪裏可以找到從4.2 4.0 API之間的差異?我應該繼續閱讀這本書嗎?

回答

1

那麼,第一個錯誤是因爲您尚未在您的strings.xml中創建一個名爲hello的資源。另外兩個警告只是因爲Android Lint希望您使用字符串資源(如第一個),而不是硬編碼字符串。

但是,這些與Android 4.0和4.2之間的任何差異都沒有任何關係。

如果您仍然對這些API級別的差異感到好奇,Android文檔提供了大量信息。

https://developer.android.com/sdk/api_diff/21/changes.html https://developer.android.com/sdk/api_diff/22/changes.html

+0

謝謝,看起來這本書假定你是一個專業版而不是一個初學者,它充斥着大量的代碼,幾乎沒有任何解釋,任何關於更改本書的建議? – user963241

+0

我個人沒有閱讀任何有關Android的書,所以我無法幫助你。是通過提供的教程和文檔,因爲它們實際上很徹底。https://developer.android.com/training/index.html –

1

您的問題IST不是真的有問題API'S它只是因爲你使用的字符串,是不是在strings.xml檔案(硬編碼字符串)。你可以忽略它(應該只是一個建議而不是一個錯誤),或者只是創建一個字符串(只有當你不止一次地使用該字符串時)