奇怪的NullReferenceException [英] strange NullReferenceException
问题描述
我有一个包含与数据库交互的方法的单例类DataAccess
这很好但是当我在用户组件中使用这个单例类,然后将我的用户组件添加到一个表单,我得到一个带有null引用异常的警告框
我的用户组件中的
我有一个包含与数据库交互的方法的单例类DataAccess
st fine但是当我在usercomponent中使用这个singleton类然后将我的usercomponent添加到表单时,我得到一个带有null引用异常的alertbox
在我的用户组件中
展开 | 选择 | Wrap | 行号
我不确定你可以将无构造对象作为组件添加到表单中。
静态类是的我认为你可以,因为有一个公共构造函数。
我从来没有真正理解单例的设置方式而只支持静态类。
我从来没有真正理解单独设置的方式,只支持静态类。
当我能够在我的项目中的任何地方访问该类时,如果该类应该记住一些数据(可以改变),我使用单例
当我只有计算或做某事的方法并且不必记住数据时我使用静态类
我猜这是正确的方法,如果我错了,请纠正我:)
I have a singleton class DataAccess containing al methods that interact with the DB
This works just fine but when i use this singleton class in a usercomponent and then add my usercomponent to a form, i get an alertbox with a nullreference exception
in my user component
Expand|Select|Wrap|Line Numbers解决方案I have a singleton class DataAccess containing al methods that interact with the DB
This works just fine but when i use this singleton class in a usercomponent and then add my usercomponent to a form, i get an alertbox with a nullreference exception
in my user component
Expand|Select|Wrap|Line Numbers
I am not sure you can add contructorless objects to forms as components.
A static class yes I think you can, since there is a public constructor.
I never really understood the way singleton was setup in favor of just a static class.
I never really understood the way singleton was setup in favor of just a static class.I use a singleton when i shoud be able to access the class anywhere in my project and if the class shoud remember some data (that can change)
I use a static class when i just have methods that calculate or do something and don''t have to ''remember'' data
I guess this is the right approach, correct me if i''m wrong :)
这篇关于奇怪的NullReferenceException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文登录 关闭
扫码关注1秒登录发送“验证码”获取 | 15天全站免登陆