Click here to Skip to main content
15,887,477 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am assigning value to a bool value like

public bool Isoverhung=false;

and i am fetching the value like

class.Isoverhung=_presenter.Getthevalue();

But i am getting null reference exception how can i solve this?
Posted
Comments
Laiju k 7-Nov-14 4:39am    
Isoverhung=0;
Isoverhung=1;
Laiju k 7-Nov-14 4:43am    
what is the output of _presenter.Getthevalue();
chandra sekhar 7-Nov-14 4:45am    
True or false
Laiju k 7-Nov-14 4:49am    
it should be 1 or 0

_presenter.Getthevalue(); Must be return undefine Value.
Check like convert.tobool(_presenter.Getthevalue())
 
Share this answer
 
C#
class.Isoverhung=_presenter.Getthevalue();

in above line of code either class object may be null or _presenter may be null. if both not null, then there can be null object in Getthevalue method!
But we can't say exactly where, which object is null or what you can do with your given information, You can put break point before above line and check line by line which is causing this exception and then you can find solution for that. check below previous questions on codeproject for more information
[C#] NullReference Exception was unhandled[^]
 
Share this answer
 
Comments
chandra sekhar 7-Nov-14 5:06am    
The class object is null but how other bool values are working fine in the same class.
DamithSL 7-Nov-14 5:10am    
which one is working?
try this ternarry operator

bool outValue;
class.Isoverhung=bool.TryParse(_presenter.Getthevalue(),out outValue)?outValue:default(bool);
 
Share this answer
 
class.Isoverhung=_presenter.Getthevalue();
class.Isoverhung=0/1; //We should pass 1 or 0 to bool
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900