2013-03-27 2 views
-1

저는 Android 개발을 처음 접했고이 책의 지침을 따르려고합니다. http://amzn.to/4nck80 그리고 나는 그걸 작동시킬 수 없습니다!루트 요소 다음에 나오는 문서의 마크 업은 올바른 형식이어야합니다.

<?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" ></LinearLayout> 



    <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!" /> 



</Button>LinearLayout> 

내가이 XML 파일에 몇 가지 오류가 있습니다 </Button>LinearLayout>

+0

GUI 디자이너를 사용하는 경우 XML을 삭제하고 다시 시작하십시오. 모든 위젯은 XML 태그 앞에 있어야합니다. – JustinDanielson

+0

[XML] (http://www.w3schools.com/xml/xml_whatis.asp) 및 [syntax] (http : /www.w3schools.com/xml/xml_syntax.asp)에서 Android 레이아웃 작업을 시작합니다. 기본 XML을 사용하여 이러한 종류의 응용 프로그램 리소스가 만들어지기 때문입니다.이 말은 안드로이드 질문이 아니기 때문에 말입니다. 오류 _ 루트 요소 다음에 오는 문서의 마크 업은 올바른 형식이어야합니다. _ 또한 Mike Christensen이 말한 구문 문제가 있습니다. –

+0

XML에 대해 조금씩 읽어보세요. 이것은 프로그래밍에 관한 나의 첫 번째 시도입니다. 어디서부터 시작해야 할 지 잘 모르겠습니다. 첫 번째 안드로이드 개발자 책을 얻었습니다. heh를 찾았습니다. – Serafino0797

답변

2

에 의해 최초의 텍스트 뷰 하여 오류

The markup in the document following the root element must be well-formed.

및 경고

Unexpected text found in layout file: "LinearLayout>"

을 얻고있다.

먼저 잘못된 XML 태그가 있습니다.

변경 :

</Button>LinearLayout> 

에 :

</Button></LinearLayout> 

또한 당신은 아마이 루트 요소를 종료하는 것을 의미하지 않았기 때문에, 위에서 마감 </LinearLayout>를 제거해야합니다.

마지막으로 제거 :

</Button> 

버튼 소자 /> 끝나는 따라서 이미 종료되기 때문이다.

최종 작업 버전는 :

<?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> 
+0

당신이 말한 것을 시도했는데 오류 : 지정된 이름과 일치하는 리소스가 없습니다 ('텍스트'에서 값 '@ 문자열/hello'). \t activity_fullscreen.xml \t/HelloWorld/res/layout \t 라인 7 \t Android AAPT 문제 및 [I18N] 하드 코드 된 문자열 "그리고 이것은 클릭 가능한 버튼입니다!", @string 리소스를 사용해야합니다. \t activity_fullscreen.xml \t/HelloWorld/res/layout \t line 20 \t Android Lint 문제 – Serafino0797

0

중간에있는 LinearLayout 태그는 필요하지 않습니다. 생성 한 각 뷰 요소에 대해 ID를 만들어야합니다. ID를 사용하여 주 활동 Java 클래스의 요소를 호출 할 수 있습니다. ID를 만드는 방법을 보여줍니다.

<Button 
android:id = "@+id/button1" 
android:layout_width="wrap_content" 
Etc......... 
/> 

<TextView 
android:id = "@+id/mytextview" 
Etc...... 
/> 

위의 사람으로 마지막 행의 LinearLayout 태그를 수정하십시오.

금전 등록기

관련 문제