【问题标题】:unsed import statement未使用的导入语句
【发布时间】:2015-07-07 23:03:22
【问题描述】:

我目前正在创建一个 meme 生成器,并且我不断收到此消息

未使用的导入语句

 import android.app.Activity;
 import android.support.v4.app.Fragment;
 import android.support.v4.app.FragmentManager;

这是什么意思,我该如何解决这个问题?

【问题讨论】:

  • 这意味着我们需要一个代码...
  • @404notfound- 我现在已经添加了代码
  • 可能BottomPictureFragment bottomFragment = (BottomPictureFragment) getFragmentManager().findFragmentById(R.id.fragment2); 行有问题所以添加BottomPictureFragment 代码(我认为导入和类声明就足够了)。
  • @404notfound- 当我运行代码时显示以下错误消息“找不到符号方法 getsupportFragmentManager”?
  • @404notfound- 我已经修改了代码

标签: android android-layout android-fragments android-activity


【解决方案1】:

com.exaample.curtis.memegenerator.Bottom pictureFragment 可能是从 android 支持库扩展而来的。

尝试使用

android.support.v4.app.Fragment.

将此包含在您的依赖项中:

compile 'com.android.support:appcompat-v7:22.2.0'

【讨论】:

  • @Jim-添加了上述内容但仍有问题?
  • 我现在看到您正在使用 android.support.v4.app.Fragment。获取支持片段管理器()。即BottomPictureFragment bottomFragment = (BottomPictureFragment) getSupportFragmentManager().findFragmentById(R.id.fragment2);
  • 还有问题吗?
  • 您可以尝试检查检索到的对象的片段类吗?您可能只是在检索错误的片段。片段 f = getSupportFragmentManager().findFragmentById(R.id.fragment2); System.out.println(f.getClass().getSimpleName());
  • 还有问题吗?
【解决方案2】:

好的,所以在一个地方回答: 您的片段需要扩展android.support.v4.app.Fragment 您的活动扩展AppCompatActivity 在gradle你需要有 compile 'com.android.support:appcompat-v7:22.2.0'compile 'com.android.support:appcompat-v7:+'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-02-04
    • 1970-01-01
    • 1970-01-01
    • 2020-10-25
    • 1970-01-01
    • 2015-09-06
    • 2018-04-15
    相关资源
    最近更新 更多