locked
Error when testing without SIM Card / NullReferenceExeption RRS feed

  • General discussion

  • Hello Folks, i have a Problem with my App and I couldn´t figure it out- now i need your help. My App is simple App that reads some Values from the Device. There ist a Value called "CellularMobileOperator" (Microsoft.Phone.Net.NetworkInformation.DeviceNetworkInformation.CellularMobileOperator). Whe a SIMCard is inserted everything is fine and I get the Name of my mobileOperator (for ex. "T-Mobile") Whe i test the App without the SIM Card and the Code try to get the Value above the Routine crashes and i get this error: "NullReferenceExeption".. this is tha line of Code: ------------------------------------------------------------------------------------------------------------------ myNET.MobileOperator = Microsoft.Phone.Net.NetworkInformation.DeviceNetworkInformation.CellularMobileOperator.ToString(); ------------------------------------------------------------------------------------------------------------------ "myNET.MobileOperator" is a String 2 Questions: ----------------- 1. how can I prevent the Routinben to chrashes? 2. How can I determine if a SIM Card ist insertet, bevor I try to read the "CellularMobileOperator"-Value? Thanx a lot for your help Greetinx from Germany DARKO
    Sunday, February 12, 2012 11:04 AM

All replies

  • 1. Use exception handling
    2. AFAIK, you can't. Again, exception handling is your friend.
    Sunday, February 12, 2012 1:23 PM
  • there's a very handy static method exposed by string called String.IsNullOrEmpty use that and yes like Jim said, use exception handling. try catch finally are your friends
    Sunday, February 12, 2012 1:39 PM
  • Hi I just try this and it seem to work: myNET.MobileOperator = Microsoft.Phone.Net.NetworkInformation.DeviceNetworkInformation.CellularMobileOperator; instead of this myNET.MobileOperator = Microsoft.Phone.Net.NetworkInformation.DeviceNetworkInformation.CellularMobileOperator.ToString(); and my Routine did not crash anymore hhmmmm;) strange - isn´t it ? ;-) thanx a lot PS: I use exaption Handling. This exaption handling is the module that returns the error. When I disalbe the Exaption Handler the entire App crashes;))
    there's a very handy static method exposed by string called String.IsNullOrEmpty use that and yes like Jim said, use exception handling. try catch finally are your friends
    Sunday, February 12, 2012 2:00 PM