我有一个登录布局,我想将其添加到“ layout-ldrtl”文件夹中,但是当我这样做时,应用程序崩溃。当我把它放回“布局”时,它变得固定了。我认为android无法检测到此目录。 stacktrace显示了我的onCreate
,setContentView()
方法。我该如何解决?
我的onCreate方法:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
}
错误:
12-18 12:06:07.957 26220-26220/com.project.amas.layoutdesign E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.project.amas.layoutdesign, PID: 26220
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.project.amas.layoutdesign/com.project.amas.layoutdesign.MainActivity}: android.content.res.Resources$NotFoundException: Resource ID #0x7f09001c
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2858)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2933)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1612)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6710)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:770)
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f09001c
at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:223)
at android.content.res.Resources.loadXmlResourceParser(Resources.java:2146)
at android.content.res.Resources.getLayout(Resources.java:1151)
at android.view.LayoutInflater.inflate(LayoutInflater.java:421)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at com.project.amas.layoutdesign.MainActivity.onCreate(MainActivity.java:13)
at android.app.Activity.performCreate(Activity.java:6982)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2811)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2933)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1612)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6710)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:770)
我刚刚遵循了Google文档
假设您要添加特定的布局文件以支持RTL脚本,例如希伯来语,阿拉伯语和波斯语。为此,请在res /目录中添加layout-ldrtl /目录,如以下示例所示:
res/
layout/
main.xml This layout file is loaded by default.
layout-ldrtl/
main.xml This layout file is loaded for languages using an
RTL text direction, including Arabic, Persian, and Hebrew.