尝试打印对象时获得空指针异常

编程入门 行业动态 更新时间:2024-10-26 10:34:27
本文介绍了尝试打印对象时获得空指针异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

下面是相关的code:

Below is the relevant code:

WebPage obPage1 = new WebPage(null, null, 0); obPage1.setUrl(page1.substring(st + 4, en)); System.out.println(obPage1.toString());

这是给我一个空指针异常任何想法在那里我去错了吗?

This is giving me a nullpointer exception any idea where im going wrong?

推荐答案

是好康你写了一个自定义类?

Is WebPage a custom class you wrote?

即使你没有实现一个toString方法,它仍然应该返回有效的字符串,因为这将是扩大对象的ToString方法

Even if you didn't implement a toString method, it should still return valid string since it would be extend the Object's toString method

getClass().getName() + '@' + Integer.toHexString(hashCode())

最快捷的方法,以确定哪些code正在做的是运行它的调试器模式,这样你可以什么存储里面的网页。

The quickest way to determine what the code is doing is running it in debugger mode so you can whats being stored inside WebPage.

看起来也像是从您要的toString返回一个页面的URL的例子。如果多数民众赞成的情况下,只是做一个getter方法​​的URL。

Also looks like from the example that you want toString to return the url of a page. If thats the case, just make a getter for the url.

更多推荐

尝试打印对象时获得空指针异常

本文发布于:2023-11-15 22:54:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1598678.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:指针   异常   对象

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!