2017-01-16 106 views
2
  • 首先,我用的Android 2.3工作室Beta 2的創建具有抽屜式導航活動模板創建一個新的項目。

content_main.xml文件:錯誤:java.lang.IllegalArgumentException異常:意外的類型標籤67發現

<?xml version="1.0" encoding="utf-8"?> 
<android.support.constraint.ConstraintLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    tools:showIn="@layout/app_bar_main" 
    tools:context="com.waylanpunch.event.MainActivity"> 

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

</android.support.constraint.ConstraintLayout> 

enter image description here

時出錯:

Cannot resolve symbol 'parent' 

完整的日誌:

Information:Gradle tasks [:app:assembleDebug] 
D:\WORKGROUP\WORKSPACES\Android_Studio_WORKSPACE\Event\app\src\main\res\layout\content_main.xml 
Error:(16, 49) String types not allowed (at 'layout_constraintBottom_toBottomOf' with value 'parent'). 
Error:(17, 45) String types not allowed (at 'layout_constraintLeft_toLeftOf' with value 'parent'). 
Error:(18, 47) String types not allowed (at 'layout_constraintRight_toRightOf' with value 'parent'). 
Error:(19, 43) String types not allowed (at 'layout_constraintTop_toTopOf' with value 'parent'). 
D:\WORKGROUP\WORKSPACES\Android_Studio_WORKSPACE\Event\app\build\intermediates\res\merged\debug\layout\content_main.xml 
Error:(16, 49) String types not allowed (at 'layout_constraintBottom_toBottomOf' with value 'parent'). 
Error:(17, 45) String types not allowed (at 'layout_constraintLeft_toLeftOf' with value 'parent'). 
Error:(18, 47) String types not allowed (at 'layout_constraintRight_toRightOf' with value 'parent'). 
Error:(19, 43) String types not allowed (at 'layout_constraintTop_toTopOf' with value 'parent'). 
Error:Execution failed for task ':app:processDebugResources'. 
> com.android.ide.common.process.ProcessException: Failed to execute aapt 
Information:BUILD FAILED 
Information:Total time: 1.786 secs 
Information:9 errors 
Information:0 warnings 
Information:See complete output in console 

符號「父」的問題是什麼?

  • Sencond,我改變ConstraintLayout到的FrameLayout

content_main.xml文件:

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    tools:showIn="@layout/app_bar_main" 
    tools:context="com.waylanpunch.event.MainActivity"> 

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

</FrameLayout> 

BUILD的過程中,儘管下面的錯誤(第2線),BUILD成功。

Information:Gradle tasks [:app:generateDebugSources,:app:generateDebugAndroidTestSources, :app:mockableAndroidJar, :app:prepareDebugUnitTestDependencies] 
Error:java.lang.IllegalArgumentException: Unexpected type tag 67 found. 
Information:BUILD SUCCESSFUL 
Information:Total time: 2.523 secs 
Information:1 error 
Information:0 warnings 
Information:See complete output in console 

而且我不知道在哪裏的拋出:IllegalArgumentException問題是從哪裏來的。

任何人都可以幫到我嗎?謝謝!

+0

你能發佈完整的錯誤 – Redman

+0

你能顯示你的xml的行號嗎 – Noorul

+0

你的代碼對我來說工作正常。你確定你正確地複製了你的代碼嗎? – Divers

回答

3

我想你可能會使用舊版本的ConstraintLayout。請務必使用最新版本 - 測試版4或更新版本(我們在constraintlayout alpha 5中引入了父標籤支持...)。

+0

** 1.0.0-alpha4 **是** ConstraintLayout **的最新版本,請檢查https://bintray.com/ligboy/ maven/constraint-layout –

+0

嗯:-)我可以向你保證alpha 4不是最新版本的ConstraintLayout。請檢查http://tools.android.com/recent/constraintlayoutbeta4isnowavailable。您應該從SDK Manager獲得正式版本,而不是從bintray--我不知道是誰做的。 –

+0

哦,是的,有人這樣做,但是AS在第一時間提到了他的圖書館,這很奇怪。我會更新它並再次嘗試。謝謝@Nicolas Roard –