java - (Activity(context)).getIntent().getExtras() 返回 null

标签 java android kotlin

我正在尝试从上下文(在我的类的主构造函数中传递)获取包引用,以获取不同类中的参数。不幸的是我总是得到空指针异常。我不太确定为什么,因为我以相同的方式成功地引用了fragmentManager

enter image description here

这里是从 Fragment“Config”调用“Request”类。我已经查过了,那个上下文!!不为空

enter image description here

最佳答案

尝试在调试器下单步执行此操作:

public class Request {
   private Context context;
   ...
   public Request(Context context) {
      this.context = context;
      try {
         Intent intent = context.getIntent();
         Bundle extras = intent.getExtras();   // <-- I'll betcha' this is returning "null"
         this.arguments = new Arguments(extras);
         ...
      } catch (Exception e) {
         Log.i("output", "no arguments has been found " + e.toString());
      }
      ...

关于java - (Activity(context)).getIntent().getExtras() 返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56065127/

相关文章:

java - 我的应用程序(Java)做错了什么?

java - Android Studio 中的 Intent 问题

android - 由于错误,无法在Firestore中更新阵列

java - Kotlin 是否提供其集合接口(interface)的任何实现?

java - eclipse /Tomcat : tomcat home page is reachable but app is not

java - 如何避免在jsp中重新加载js和css

android - 关于删除级联android 2.2

java - Android Studio 和 Eclipse

android - 如何让我的智能家居应用在 Google Home 应用中显示为建议

android - Jetpack Compose DrawImage 编译错误