[英]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.