问题标签 [null-pointer]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
3254 浏览

c++ - 是否打印空指针未定义行为?

在研究这个问题的示例代码时,我假设它是未定义的行为,它阻止了后续使用的std::cout打印。但事实证明,尝试打印空指针会导致std::ios_base::badbit并将std::ios_base::failbit其设置为流状态,这是导致其无法运行的真正原因。因此,我现在很好奇(尝试)打印空指针是否真的是未定义的行为。所以这是我的问题:

  1. 打印空指针是未定义的行为吗?如果是这样,导致这种情况的流插入器是什么?我很确定插入器足够聪明,不会取消引用空指针。

  2. 我还想知道为什么插入器在此上下文中遇到空指针时设置其错误掩码(特别是badbit)。为什么不将其视为字符串文字的终止?

我手边没有标准,到目前为止,我只发现了一个不幸导致死链接的来源。

0 投票
0 回答
194 浏览

java - 为什么重新排列嵌套列会导致 NPE?

如果我有一个带有两列的 TableView,分开(不是嵌套),那么当我尝试重新排列它们时一切都很好。但是,即使存在一个嵌套列,当我尝试重新排列某些内容时它也会崩溃。

这是我的xml:

这是我在控制器类中用来设置 tableview 的内容:

有谁知道如何解决这一问题?重新排列列是必须的,我需要克服这个障碍。任何帮助,将不胜感激!

0 投票
1 回答
29 浏览

java - 通过他的路径阅读 pdf

我已经在我的 java 类的同一个地方放置了一个 pdf 文档,但我仍然得到一个 NullPointer 错误。我需要将 pdf 文档放在班级的同一个地方。这是我的代码:

sourcePath 是 pdf 文档的名称。

谢谢

0 投票
2 回答
692 浏览

python - 使用 Try 和 except 块时出现“NoneType”错误

我在尝试和 except 块时遇到了一个奇怪的问题,我用它来捕捉无效数据输入到我正在写的一个简单的黑杰克游戏.....

然后我有一个方法 GameStart() 启动许多方法调用:

当我运行代码并输入正确的值(一个有效的整数)时,没有问题。当我第一次输入无效数字(字符串或字符)时,我收到相应的消息“尝试输入有效数字,然后当我输入有效整数时,我收到错误 -

任何想法?

0 投票
3 回答
1608 浏览

java - Using StringUtils.isEmpty without losing compiler warnings about null pointers

Instead of the usual if (myString == null || myString.equals("")) I tend to prefer using the org.apache.commons.lang.StringUtils class and do if (StringUtils.isEmpty(myString)).

However this - at least the way I'm doing it - comes with a gigantic downside: because FindBugs - or the compiler warning mechanism, f. ex. from Eclipse - will no longer see the explicit null-check, it will no longer consider myString as potentially null, so it will no longer raise the warnings about potential (or sure) null pointers on it, and those warnings are extremely useful in my view.

Example (ADDED):

So I'm just trying to make sure that there is no way to eliminate or minimize this downside so that one can use StringUtils.isEmpty and still get the null pointer warnings. Maybe some annotation like @Nullcheck to add to the isEmpty method or something else ?

ADDED: For ex., would it be feasible to create a custom annotation like @Nullcheck, add it to the arg of isEmpty like public static boolean isEmpty(@Nullcheck String str) just to indicate that the method does a null-check on that arg, and make so that the compiler warning mechanism or FindBugs treat a if (StringUtils.isEmpty(myString)) just like an explicit null-check ?

0 投票
1 回答
135 浏览

c - cholmod 长版本函数返回空指针 - c 编程

我正在使用通过 macports 安装的 SuiteSparse @4.2.1_3 并希望分配一个 cholmod_dense 结构。考虑以下代码:

我得到以下输出:

这意味着长版本中的分配cholmod_dense结构不起作用,但整数版本效果很好。有谁知道发生这种情况的原因?

0 投票
0 回答
206 浏览

android - 这个微调器项目怎么可能是空的?

我有一个从 ArrayAdapter 获取数据的微调器。数组对象有一个 toString() 方法,它由微调器使用。

在这种情况下,我在数组中只有一项时设置适配器。数组中的对象返回一个非空字符串,但虽然微调器中有一项,但它是空的。为什么微调器中没有有效的 TextView 作为项目。这是在设置适配器后立即设置断点的程序:

断点

这是问题所在:

表达式

这是 MolData 类

Abd 这是有问题的代码:

进一步澄清:我遇到的问题是 getChildAt(0) 在 OnItemSelected 侦听器中返回 null 。但是,在正常启动时调用此代码时,虽然在设置适配器后 getChildCount 显示为零,但当随后立即设置侦听器时,由其添加引起的侦听器调用具有有效的 getChildAt(0) !但是,当由于屏幕已旋转而调用此代码时,getChildAt(0) 在侦听器因已添加而触发时为空。在正常启动时,从用户与 UI 的交互中调用此代码,但在重新启动屏幕后,从 onResume() 调用此代码(在片段中)。[它是从 onCreate 调用的,但我在生命周期的后期移动了它以查看它是否有帮助,但没有成功。]

0 投票
2 回答
455 浏览

android - 从数据库中获取行数据并在 Android 中检索它

我正在处理一个有很多表并且一个表包含多行的项目。如何从数据库中获取数据并使用SimpleAdapter?

我曾尝试使用游标,但我只获取存储在数据库中的最后一行值。

尝试使用时,ArrayList<Hashmap<String, String>>我得到一个NullPointerException,即使使用 try catch 块也无法解决。

这是获取它的代码

现在,如果我错了,请帮助我获取数据并将其显示在 SimpleAdapter 中。

0 投票
1 回答
657 浏览

c++ - Is deleting a null pointer in C++ considered undefined behaviour?

Consider the following piece of code:

Questions:

  1. Is deleting a null pointer considered undefined behaviour?
  2. Did something changed in C++11 or C++14?
0 投票
1 回答
137 浏览

android - kinvey客户端调用的onsuccess方法如何同步

我正在开发一个使用 Kinvey 作为后端的应用程序。我遇到的问题是,当我调用 kinvey appData 请求时,控件不会进入 kinvey 调用的 onsuccess 方法并返回到调用方法的位置。这是我的主类,我正在调用一个函数,该函数具有 kinvey 客户端调用来获取数据。

现在这是我的 GetAllCategories 函数

但是在执行 kinvey 调用后控制权会返回到 oncreate 方法,并且不要转到 onSuccess 方法。执行整个 oncreate 方法后,它会返回到 onSuccess。但在此之前,由于 NUll 指针异常,应用程序崩溃了。

请原谅我的格式不好,请问您是否需要我解释更多。预先感谢