2013-05-19 15 views
5

W tym pliku są moje layouty następujące błędy wyświetlania w tym kodzieBłąd: Brak zasobów okazało się, że pasuje do podanej nazwie

error: Error: No resource found that matches the given name (at 'id' with value '@id/question_text_view'). 
error: Error: No resource found that matches the given name (at 'id' with value '@id/next_button'). 

jest to plik układ

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:gravity="center" 
    android:orientation="vertical" > 

    <TextView 
     android:id="@id/question_text_view" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:padding="24dp" 
     /> 
    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:gravity="center" 
     android:orientation="horizontal" > 
     <Button 
      android:id="@+id/true_button" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/true_button" 
     /> 
     <Button 
      android:id="@+id/false_button" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/false_button" 
     /> 
    </LinearLayout> 
     <Button 
     android:id="@id/next_button" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/next_button" 
     /> 
</LinearLayout> 

To jest moje struny. xml

<?xml version="1.0" encoding="utf-8"?> 
    <resources> 

     <string name="app_name">GeoQuiz</string> 
     <string name="true_button">True</string> 
     <string name="false_button">False</string> 
     <string name="correct_toast">Correct</string> 
     <string name="next_button">Next</string> 
     <string name="incorrect_toast">Incorrect</string> 
    <string name="action_settings">Settings</string> 
    <string name="question_founder">Frank Reed Horton Founded APO on december 25 1947</string> 
    <string name="question_chief">Willy Wonka was known as a cheif</string> 
    <string name="question_lady">The first lady that became president in APO was Mary Katz</string> 
    <string name="question_president">Our current President of the Delta Rho chapter is john dolan</string> 
<string name="question_alphabets">Alpha, Beta, Gamma, Delta, Epsilon, Eta, Zeta</string> 
</resources> 

wiem, że tam jest wiedzieć question_text_view na strunach, ale popełniła tablicę w mojej działalności który bierze wszystkie pytania mQuestionTextView = (TextView) findViewById (R.id.question_text_view); int question = mQuestionBank [mCurrentIndex] .getQuestion(); mQuestionTextView.setText (pytanie); mQuestionBank jest tablicą wszystkich pytań, które zadaję getQuestion() jest moja metoda getter dla uzyskania pytanie

a drugi błąd dla next_button Nie wiem co zrobiłem źle, odkąd włączyła ją na strings.xml Czy ktoś może mi pomóc

+1

android id = "@ id/question_text_view" należy android id = "@ + Id/question_text_view" jednakowa dla przycisku android : id = "@ + id/next_button" – Raghunandan

+1

plz zobacz [Więcej typów zasobów] (h ttp: //developer.android.com/guide/topics/resources/more-resources.html#Id) do definiowania identyfikatorów dla widoków w xml. będziesz musiał użyć '' zamiast '' do umieszczenia id's w pliku strings.xml lub możesz stworzyć osobny plik dla niego jak ids.xml –

Odpowiedz

7

android id = "@ id/question_text_view" należy android id = "@ + Id/question_text_view" jednakowa dla przycisku android id = "@ id/next_button" powinny być android: id = "@ + id/next_button"

TextView

<TextView 
    android:id="@+id/question_text_view" // missing + in your xml code 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:padding="24dp" 
    /> 

Przycisk

<Button 
    android:id="@+id/next_button" // missing + in your xml code 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/next_button" 
    /> 

ID

Każdy obiekt View może mieć powiązany z nim identyfikator integer, aby jednoznacznie zidentyfikować widok w drzewie. Gdy aplikacja jest kompilowana, ten identyfikator jest identyfikowany jako liczba całkowita, ale identyfikator jest zwykle przypisywany w pliku XML układu jako ciąg znaków w atrybucie id. Jest to atrybut XML wspólny dla wszystkich obiektów View (zdefiniowanych przez klasę View) i będziesz go używać bardzo często. Składnia identyfikatora wewnątrz znacznika XML to:

Symbol at (@) na początku łańcucha wskazuje, że analizator składni XML powinien przeanalizować i rozwinąć resztę ciągu znaków ID i zidentyfikować go jako Zasób ID. Symbol plus (+) oznacza, że ​​jest to nowa nazwa zasobu, którą należy utworzyć i dodać do naszych zasobów (w pliku R.java).

W twoim przypadku twój identyfikator to przycisk android: id = "@ id/next_button". Odwołujesz się do identyfikatora zasobów Androida (zakłada). To nie istnieje. To samo dotyczy widoku tekstowego. W związku z tym pojawi się błąd Resource not found.

Aby uzyskać więcej informacji sprawdź poniżej

http://developer.android.com/guide/topics/ui/declaring-layout.html

0

Powinieneś być ostrożny z identyfikatorami widoków. W widoku TextView, a także w widoku przycisku, zapominasz o znaku "+" w atrybucie ID. O ile wiem, próbujesz odwołać się do innego widoku z identyfikatorem. Jeśli używasz znaku "+", utwórz nowy identyfikator dla tego widoku.

wersja wynoszą:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:gravity="center" 
    android:orientation="vertical" > 

    <TextView 
     android:id="@+id/question_text_view" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:padding="24dp" 
     /> 
    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:gravity="center" 
     android:orientation="horizontal" > 
     <Button 
      android:id="@+id/true_button" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/true_button" 
     /> 
     <Button 
      android:id="@+id/false_button" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/false_button" 
     /> 
    </LinearLayout> 
     <Button 
     android:id="@+id/next_button" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/next_button" 
     /> 
</LinearLayout> 
0

link może folderu ścieżka jest zbyt długa takie jak moje „E: \ Project \ Komórka \ SixworldGit \ sixworld \ Projects \ sixworld \ SW_Vietnam \ 2.3. 2.0.20160711_Android_MoboSDKAll_lucgioi_20160711_1805 \ 2.3.2.0.20160711_Android_MoboSDKAll \ MoboSDK \ odniesienia \ MoboSDKAll \ Res \ odkształcalny”

Powiązane problemy