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

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

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.

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:

确定