发生在使用 Android Safe Args 时的类和包冲突问题。

huangapple go评论86阅读模式
英文:

Clashing class and package when using Android Safe Args

问题

  1. 我在处理一个在AndroidJava)中使用Safe Args时遇到的非常烦人的问题。
  2. 我的项目结构如下:
  3. com.myapp/
  4. ├── activites/
  5. ├── ActivityA.java
  6. | | ├── FragmentA1
  7. | └── FragmentA2
  8. └── ActivityB.java
  9. ├── view/
  10. | └── ...
  11. └── model/
  12. └── ...
  13. 这里重要的部分是包 **com.myapp.activities.ActivityA**。
  14. 当为导航图添加一些导航路径时,Safe Args 生成的结构如下:
  15. com.myapp/
  16. └── activites/
  17. ├── ActivityA/
  18. | ├── FragmentA1Directions
  19. └── FragmentA2Directions
  20. └── ...
  21. 在这种情况下,我无法编译我的项目,因为我得到了错误:
  22. >错误:类ActivityA与同名包冲突。
  23. 对我来说,这完全有意义,因为类 *com.myapp.activities.ActivityA* 生成到了包 *com.myapp.activities.ActivityA*,但不知何故我不明白我应该如何避免这个问题。
  24. 我的文件夹结构有什么完全错误的地方吗?
英文:

I'm struggling with a really annoying problem with Safe Args in Android (Java).

I have a project structure like this:

  1. com.myapp/
  2. ├── activites/
  3. ├── ActivityA.java
  4. | | ├── FragmentA1
  5. | └── FragmentA2
  6. └── ActivityB.java
  7. ├── view/
  8. | └── ...
  9. └── model/
  10. └── ...

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:

  1. com.myapp/
  2. └── activites/
  3. ├── ActivityA/
  4. | ├── FragmentA1Directions
  5. └── FragmentA2Directions
  6. └── ...

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.

huangapple
  • 本文由 发表于 2020年10月2日 06:35:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/64164034.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定