英文:
Clashing class and package when using Android Safe Args
问题
我在处理一个在Android(Java)中使用Safe Args时遇到的非常烦人的问题。
我的项目结构如下:
com.myapp/
├── activites/
│ ├── ActivityA.java
| | ├── FragmentA1
| │ └── FragmentA2
│ └── ActivityB.java
├── view/
| └── ...
└── model/
└── ...
这里重要的部分是包 **com.myapp.activities.ActivityA**。
当为导航图添加一些导航路径时,Safe Args 生成的结构如下:
com.myapp/
└── activites/
├── ActivityA/
| ├── FragmentA1Directions
│ └── FragmentA2Directions
└── ...
在这种情况下,我无法编译我的项目,因为我得到了错误:
>错误:类ActivityA与同名包冲突。
对我来说,这完全有意义,因为类 *com.myapp.activities.ActivityA* 生成到了包 *com.myapp.activities.ActivityA*,但不知何故我不明白我应该如何避免这个问题。
我的文件夹结构有什么完全错误的地方吗?
英文:
I'm struggling with a really annoying problem with Safe Args in Android (Java).
I have a project structure like this:
com.myapp/
├── activites/
│ ├── ActivityA.java
| | ├── FragmentA1
| │ └── FragmentA2
│ └── ActivityB.java
├── view/
| └── ...
└── model/
└── ...
The important part here is the package com.myapp.activities.ActivityA.
When adding some navigation paths to the nav graph, Safe Args generates the structure as following:
com.myapp/
└── activites/
├── ActivityA/
| ├── FragmentA1Directions
│ └── FragmentA2Directions
└── ...
In this case I cannot compile my project because I get the error
>error: class ActivityA clashes with package of same name.
This makes totally sense to me as the class com.myapp.activities.ActivityA gets generated to package com.myapp.activities.ActivityA but somehow I don't understand how I should avoid this problem.
Is there something completely wrong my folder structure?
答案1
得分: 0
在Activity中使用Fragment似乎真的不起作用。
我将这些Fragment放入单独的文件中,按照@ianhanniballake的建议使其工作起来。
英文:
The usage of Fragments in an Activity seems really not to work.
I put the Fragments into separate files to make it work like suggested by @ianhanniballake.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论