我正在尝试从上下文(在我的类的主构造函数中传递)获取包引用,以获取不同类中的参数。不幸的是我总是得到空指针异常。我不太确定为什么,因为我以相同的方式成功地引用了fragmentManager
这里是从 Fragment“Config”调用“Request”类。我已经查过了,那个上下文!!不为空
最佳答案
尝试在调试器下单步执行此操作:
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/