Hi
I am working on a android application, one like whatsapp. I am using SFS API 1.6.1. I need to upload files to share with other users so i looked into sfs docs and found this tutorial http://docs2x.smartfoxserver.com/Advanc ... le-uploads. when i am using the same java code mention in the official documentation, but my IDE cannot resolve the method getHttpUploadURL. Here is the screenshot of relevant code from my my application which is exactly same as the docx says.
one more thing to mention, client is already logged in to server before calling this method, and client can perform almost every other task except calling this method. can someone help me on this?
Cannot resolve method getHttpUploadURI
-
- Posts: 39
- Joined: 19 Sep 2012, 03:24
Re: Cannot resolve method getHttpUploadURI
Hi,
I don't know what the problem could be, but I have no problem with the method.
I downloaded the 1.6.1 Api from the website, created a new NetBeans project and it works as expected. See attached screenshot.
May try to download the library again?
http://smartfoxserver.com/download/sfs2x#p=client
I don't know what the problem could be, but I have no problem with the method.
I downloaded the 1.6.1 Api from the website, created a new NetBeans project and it works as expected. See attached screenshot.
May try to download the library again?
http://smartfoxserver.com/download/sfs2x#p=client
-
- Posts: 39
- Joined: 19 Sep 2012, 03:24
Re: Cannot resolve method getHttpUploadURI
thank you. that helped me. Deleting .jar files inside libs folder and re importing fixed the issue for me. now i wanna ask another thing about passing custom parameters with with my upload request to receive those parameters inside SFSEventType.FILE_UPLOAD.
what i am doing right now is passing parameters with upload URI separating by & sign.
which gives me
FATAL EXCEPTION: main
and everything works without passing parameter. like
by debugging i made sure that variables i am passing to HttpPost are not null. can u plz help me on this?
what i am doing right now is passing parameters with upload URI separating by & sign.
Code: Select all
new HttpPost(sfsClient.getHttpUploadURI() + "&__roomName=" + room.getName()+ "&__roomId=" + room.getId());
FATAL EXCEPTION: main
Code: Select all
Process: com.mgh.mghmessenger, PID: 9738
java.lang.RuntimeException: Unable to start service com.mgh.mghmessenger.services.FileUpload@3237179b with null: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Intent.getStringExtra(java.lang.String)' on a null object reference
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3457)
at android.app.ActivityThread.access$2200(ActivityThread.java:181)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1580)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6145)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Intent.getStringExtra(java.lang.String)' on a null object reference
at com.mgh.mghmessenger.services.FileUpload.onStartCommand(FileUpload.java:69)
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3440)
at android.app.ActivityThread.access$2200(ActivityThread.java:181)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1580)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6145)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
and everything works without passing parameter. like
Code: Select all
new HttpPost(sfsClient.getHttpUploadURI());
by debugging i made sure that variables i am passing to HttpPost are not null. can u plz help me on this?
Re: Cannot resolve method getHttpUploadURI
I recommend checking the docs here:
http://docs2x.smartfoxserver.com/Advanc ... le-uploads
custom parameters must be sent via POST, not via GET (e.g. as query string params)
Hope it helps
http://docs2x.smartfoxserver.com/Advanc ... le-uploads
custom parameters must be sent via POST, not via GET (e.g. as query string params)
Hope it helps
-
- Posts: 39
- Joined: 19 Sep 2012, 03:24
Re: Cannot resolve method getHttpUploadURI
yes, i checked these documents and i am passing these parameters in a HTTP POST not in GET as you mentioned. here is the statement i am using to create HTTP POST
but its not working for me.
Code: Select all
Room room = sfsClient.getLastJoinedRoom();
HttpPost httppost = new HttpPost(sfsClient.getHTTPUploadURI + "&__roomName=" + room.getName()+ "&__roomId=" + room.getId());
but its not working for me.
Re: Cannot resolve method getHttpUploadURI
Have you checked why the NullPointer exception is being thrown?
The error seems to be caused by this, in the wrapped exception:
What happens at line 69 of FileUpload.java?
The error seems to be caused by this, in the wrapped exception:
Code: Select all
at com.mgh.mghmessenger.services.FileUpload.onStartCommand(FileUpload.java:69)
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3440)
at android.app.ActivityThread.access$2200(ActivityThread.java:181)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1580)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6145)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
What happens at line 69 of FileUpload.java?
-
- Posts: 39
- Joined: 19 Sep 2012, 03:24
Re: Cannot resolve method getHttpUploadURI
in line number 69, i am receiving an intent extra. this is my line number 69.
and i tested this again, intent extra is passed and received properly. so filePath variable isn't null.
Code: Select all
filePath = i.getStringExtra("filePath");
and i tested this again, intent extra is passed and received properly. so filePath variable isn't null.
Re: Cannot resolve method getHttpUploadURI
I don't know... that's where the error you have posted is pointing to... unless you have changed your code after posting the error and we're looking at the wrong line.
I can only suggest to run your code again and if the same exception occurs go check the line that the stack trace indicate... maybe post it here too.
thanks
I can only suggest to run your code again and if the same exception occurs go check the line that the stack trace indicate... maybe post it here too.
thanks
-
- Posts: 39
- Joined: 19 Sep 2012, 03:24
Re: Cannot resolve method getHttpUploadURI
Hi
finally figured out what's going wrong. the problem is the parameter i am passing in post request contains a space.
see. there is a space between roomName which is 'Group 1'. if i remove space. 'Group1' works very well. so my question is how can i work with this space. there can be multiple space in room name like 'SFS Room 1'. so plz tell me how to deal with this issue. without space every thing works fine.
finally figured out what's going wrong. the problem is the parameter i am passing in post request contains a space.
Code: Select all
http://192.168.0.100:8080/BlueBox/SFS2XFileUpload?sessHashId=9a0162bfe3c2b7750ec2dfc9bc234523&__roomName=Group 1&__roomId=8
see. there is a space between roomName which is 'Group 1'. if i remove space. 'Group1' works very well. so my question is how can i work with this space. there can be multiple space in room name like 'SFS Room 1'. so plz tell me how to deal with this issue. without space every thing works fine.
Re: Cannot resolve method getHttpUploadURI
You need to url-encode the string so that special characters, such as spaces, get translated to the proper entities.
See here:
http://stackoverflow.com/questions/1078 ... parameters
cheers
See here:
http://stackoverflow.com/questions/1078 ... parameters
cheers
-
- Posts: 39
- Joined: 19 Sep 2012, 03:24
Re: Cannot resolve method getHttpUploadURI
this is how i am passing parameters now.
and it is working. thanks Lapo
Code: Select all
httppost = new HttpPost(uploadURI + "&__roomName=" + URLEncoder.encode(room.getName(), "UTF-8") + "&__roomId=" + room.getId());
and it is working. thanks Lapo
Return to “SFS2X Java / Android API”
Who is online
Users browsing this forum: No registered users and 31 guests