This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes PHP and the fly likes Undefined index Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Languages » PHP
Bookmark "Undefined index" Watch "Undefined index" New topic
Author

Undefined index

Gil Carvalho
Ranch Hand

Joined: Dec 10, 2013
Posts: 75
Hello

I working in a small project and i'm having an error Undefined index;



In line 34 and 35



What's wrong please?

Thank you
Roel De Nijs
Sheriff

Joined: Jul 19, 2004
Posts: 7201
    
  29

Does this work?


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
OCAJP 7
Gil Carvalho
Ranch Hand

Joined: Dec 10, 2013
Posts: 75
Hi

No...

Now i have this in my logCat

02-20 14:43:43.704: E/Buffer Error(22965): Error converting result java.lang.NullPointerException: lock == null

Can't get what is wrong..

And this is my log from Android



Roel De Nijs
Sheriff

Joined: Jul 19, 2004
Posts: 7201
    
  29

Maybe you should first explain what you are trying to do... instead of posting some chuncks of code and let us guess about the purpose of the code
Gil Carvalho
Ranch Hand

Joined: Dec 10, 2013
Posts: 75
Hi

This is a login system for android.
It uses php, json e android.

Now the undefined index is resolved but i have other issues and i don't know why.

My php is this one after correcting the undefined index





And the error


The Json parse doesn't work....
Roel De Nijs
Sheriff

Joined: Jul 19, 2004
Posts: 7201
    
  29

But which json is invalid? I assume the var_dump of the user.
Gil Carvalho
Ranch Hand

Joined: Dec 10, 2013
Posts: 75
No

var_dump($user); prints the following data:



so the query works, the problem is here, response variable seem to be empty...because i don't receive any data in android app



so what i'm doing wrong?

Thank you
Roel De Nijs
Sheriff

Joined: Jul 19, 2004
Posts: 7201
    
  29

Based on the exception message Value array(6) of type java.lang.String cannot be converted to JSONObject, it seems to be about the var_dump of user, that's an array of 6 elements (and not a json object)
Gil Carvalho
Ranch Hand

Joined: Dec 10, 2013
Posts: 75
The var_dump was just to check the values, if i remove it i get this error in android app




org.json.JSONException: No value for user

So....i'm lost

Roel De Nijs
Sheriff

Joined: Jul 19, 2004
Posts: 7201
    
  29

And how does the json-object looks like that you are returning?
Gil Carvalho
Ranch Hand

Joined: Dec 10, 2013
Posts: 75
Json should return

Roel De Nijs
Sheriff

Joined: Jul 19, 2004
Posts: 7201
    
  29

Gil Carvalho wrote:Json should return

Does your php code returns this json?
Gil Carvalho
Ranch Hand

Joined: Dec 10, 2013
Posts: 75
No

Returns

{"tag":"login",
"success":1,
"error":0

}
Roel De Nijs
Sheriff

Joined: Jul 19, 2004
Posts: 7201
    
  29

That explains your error, because there is no user in the json-string and you try to retrieve the "user" key as a JSONObject.
 
Have you checked out Aspose?
 
subject: Undefined index
 
It's not a secret anymore!