2017-08-04 3 views
2

Ich folge einem Kurs über das Herunterladen von Android Studio und wie man es einrichten, ich habe die richtigen Treiber für mein Handy heruntergeladen, aber wenn ich versuche, mein Hallo Weltprogramm zu laufen, habe ich Probleme.Nicht in der Lage zu Hallo Welt

Denken Sie daran, dass der Kurs selbst mich riet, eine Datei namens activity_main.xml zu aktualisieren. Das war der vorherige Inhalt der Datei:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.constraint.ConstraintLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/activity_main" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context="com.udacity.myapplication.MainActivity"> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Hello World!" 
    app:layout_constraintLeft_toLeftOf="@+id/activity_main" 
    app:layout_constraintTop_toTopOf="@+id/activity_main" 
    app:layout_constraintRight_toRightOf="@+id/activity_main" 
    app:layout_constraintBottom_toBottomOf="@+id/activity_main" /> 

    </android.support.constraint.ConstraintLayout> 

Dieser Codeabschnitt musste aktualisiert werden, um mit den Videos übereinzustimmen. Neues Segment:

<?xml version="1.0" encoding="utf-8"?> 
<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="com.udacity.myapplication.MainActivity"> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Hello World!" /> 
    </RelativeLayout> 

Wenn ich versuche, hier die App auf meinem Handy zu laufen ist, was ich bekommen:

Error:(7, 28) No resource found that matches the given name (at ‘paddingBottom’ with value ‘@dimen/activity_vertical_margin’). 
Error:(8, 26) No resource found that matches the given name (at ‘paddingLeft’ with value ‘@dimen/activity_horizontal_margin’). 
Error:(9, 27) No resource found that matches the given name (at ‘paddingRight’ with value ‘@dimen/activity_horizontal_margin’). 
Error:(10, 25) No resource found that matches the given name (at ‘paddingTop’ with value ‘@dimen/activity_vertical_margin’). 
Error:Execution failed for task ‘:app:processDebugResources’. 

Jede Hilfe?

+1

in Ihrer @dimen Datei, haben Sie * 5dp 1dp *? – yasin

Antwort

6

diese Zeilen aus RelativeLayout entfernen:

android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 

oder die Werte ändern:

android:paddingBottom="16dp" 
android:paddingLeft="16dp" 
android:paddingRight="16dp" 
android:paddingTop="16dp" 

@dimen/... sind Verweise auf Dimensionswerte in den res/Werte/dimens.xml Dateien. Sie haben wahrscheinlich keine Werte und deshalb erhalten Sie diesen Fehler.

4

Sie zwei Möglichkeiten haben:

One, erstellen Sie die resoureces wie folgt aus:

<resources> 
    <dimen name="activity_vertical_margin">10dp</dimen> 
    <dimen name="activity_horizontal_margin">10dp</dimen> 
</resources> 

Zwei Set benutzerdefinierte Werte wie folgt aus:

android:paddingBottom="10dp" 
android:paddingLeft="10dp" 
android:paddingRight="10dp" 
android:paddingTop="10dp" 
0

Mit Attributen wie diese finden Sie auf eine dimen Ressource namens activity_horizontal_margin:

android:paddingLeft="@dimen/activity_horizontal_margin" 

Diese Dimensionsressource wurde jedoch nicht deklariert und der Compiler schlägt fehl.

Sie können thi entweder reparieren die fehlenden Dimensionen in der res/values/dimens.xml-Datei zu erstellen:

<resources> 
    <dimen name="activity_vertical_margin">8dp</dimen> 
    <dimen name="activity_horizontal_margin">8dp</dimen> 
</resources> 

Oder Sie codieren die Werte wie folgt aus:

android:paddingBottom="8dp" 
android:paddingLeft="8dp" 
android:paddingRight="8dp" 
android:paddingTop="8dp"