Long.getLong()失败,返回null到有效的字符串 [英] Long.getLong() failing, returning null to valid string

查看:1019
本文介绍了Long.getLong()失败,返回null到有效的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经花了近两年的调试时间什么似乎极不可能。我已经剥离辅助机器人活动的方法,正是这一点:

I've spent the past two hours debugging what seems extremely unlikely. I've stripped the method of a secondary Android Activity to exactly this:

public void onClick(View v) {
        String str = "25";
        long my_long = Long.getLong(str);
} // onClick (v)

,是的,我得到了良好的醇崩溃NullPointerException异常:

And yeah, I get a crash with the good ol' NullPointerException:

二月九号至11号:02:50.444:ERROR / AndroidRuntime(1588):未捕获的处理程序:螺纹主力退出,由于未捕获的异常 二月九号至11日:02:50.464:ERROR / AndroidRuntime(1588):显示java.lang.NullPointerException

09-11 02:02:50.444: ERROR/AndroidRuntime(1588): Uncaught handler: thread main exiting due to uncaught exception 09-11 02:02:50.464: ERROR/AndroidRuntime(1588): java.lang.NullPointerException

它看起来像(其它测试)的Long.getLong(str)返回NULL,这是推动我疯狂。我在想什么?

It looks like (from other tests) that Long.getLong(str) returns NULL, which is driving me bonkers. WHAT AM I MISSING?

在此先感谢。我好与愚蠢缺少明显的,但我的神智就行了。

Thanks in advance. I'm okay with stupidly missing the obvious, but my sanity is on the line.

推荐答案

您丢失的事实, Long.getLong(字符串str)是不是应该分析字符串一个长,而是返回一个系统属性按该字符串psented重新$ P $的长期价值。正如其他人所说,你真正需要的是的Long.parseLong(字符串str)

You are missing the fact that Long.getLong(String str) is not supposed to parse a String to a long, but rather to return a long value of a system property represented by that string. As others have suggested, what you actually need is Long.parseLong(String str).

这篇关于Long.getLong()失败,返回null到有效的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆