Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

hot to find network provide

 
sam liya
Ranch Hand
Posts: 1243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wrote below codes to fine network provide in my phone.it gives me nullpointer exception.please see the attachment.

 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sameera,

I believe we have asked you before to please copy and paste the exact error message you get into the forums - don't use screenshots. It will be easier for us to troubleshoot that way.
 
sam liya
Ranch Hand
Posts: 1243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have removed the screenshot, and was about to post exactly what Steve said :-)
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which line of the our code is executed when that exception occurs? It doesn't have anything that points to a "Commom" class.
 
sam liya
Ranch Hand
Posts: 1243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry for above error message.it was a mistake.correct error message is below.



26 th line in my code is below

 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there other code that would set "context" to a non-null value? Because the code you posted does not.
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A null pointer occurs for exactly one reason: you are using a reference variable which has not been assigned a reference to an Object, so the variable holds null - not an Object. The code that generates the error uses only one variable which could be null. Which variable is that? What do you think you have to do to make it not null?
 
sam liya
Ranch Hand
Posts: 1243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank Ulf Dittmer and Steve Luke.Anyway how to set the context variable.I don't know how to assign value to it.please advise.
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're in luck: an Activity is a Context, and since this code runs as part of an Activity, you don't need that object instance to call the getSystemService method.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic