簡體   English   中英

Android:版面配置錯誤

[英]Android: layout-land error

我正在嘗試為我的一個較舊的項目添加單獨的縱向-橫向布局(基本上我顯示2個Fragments :一個帶有google-map,另一個包含一些OpenGL繪圖)。 我創建了一個名為layout-land的布局資源文件夾,其中包含我的景觀布局,並且在Android Studio中出現錯誤:

Error:Execution failed for task ':MapDemoActivity:mergeDebugResources'.
> java.lang.NullPointerException (no error message)

在我的Gradle控制台中:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':MapDemoActivity:mergeDebugResources'.
> java.lang.NullPointerException (no error message)

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option
to get more log output.

我是一個初學者,我不知道如何Run with --stacktrace option to get the stack trace或類似內容。

這是我的縱向布局( activity_main.XML ),當我沒有layout-land文件夾時,它可以正常工作:

<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"
tools:context=".MainActivity"
android:animateLayoutChanges="true"
>

<fragment
    android:id="@+id/map"
    class="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="wrap_content"
    android:layout_height="350dp"
    android:layout_alignParentBottom="true"/>
<fragment
    android:id="@+id/openGL"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    class="com.example.mapdemo.OpenGLES20ActivityFrag"
    android:layout_above="@id/map"/>

</RelativeLayout>

我的layout-land文件夾中具有相同名稱的layout-land (當我添加此文件夾時,出現上述錯誤,我嘗試使用簡單的HelloWorld風格的布局,但它仍然無法正常工作,因此我認為它沒有與其中包含的任何內容有關):

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:animateLayoutChanges="true"
android:baselineAligned="false"
android:orientation="horizontal"
tools:context=".MainActivity">

<fragment
    android:id="@+id/map"
    android:layout_width="400dp"
    android:layout_height="match_parent"

    class="com.google.android.gms.maps.SupportMapFragment" />

<fragment
    android:id="@+id/openGL"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    class="com.example.mapdemo.OpenGLES20ActivityFrag" />

</LinearLayout>

如果需要附加代碼,我會發布它,但是我認為這不是必需的。 我確實有最新的SDK和IDE版本。

我認為如果可以找出我的代碼中NullPointerException錯誤的位置,我可以解決它,但是我不知道如何找到它

請注意是否仍然需要此答案。 但是我遇到了這個確切的問題,並在StackOverflow上進行了更多搜索,在這篇Android Studio帖子中找到了答案-mergeDebugResources異常

“只有在修改項目上的XML文件時,這種情況才會發生。如果在運行之前重建整個項目(“構建”>“重建項目”),它將不再顯示。

之后,我重新構建了項目,此問題消失了,可以運行我的應用程序,並使用不同的縱向和橫向布局。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM