cannot implement rest webservice in android app - android

I want to implement rest webservice in android application
to do that
I create the class from this tutorial: here
but when I clcok on the matched button I have the error
unfortunetly, android app has stopped
I don't have anything in the Logcat
then I canno't know from which is the problem
here is the event code:
case R.id.btn_rest_test :
Log.d("method event get", "execite :)");
Rest r = new Rest();
r.get("http://www.cheesejedi.com/rest_services/get_big_cheese.php?puzzle=1");
r.getResponseString();
EditText etdit = (EditText) findViewById(R.id.rest_text);
EditText etdit2 = (EditText) findViewById(R.id.rest_error_text);
etdit.setText(r.getResponseText());
etdit2.setText(r.getError());
break;
how can I achieve that

This could be due to a lot of errors.
Are you sure it does not crash because of your two EditTexts not being found?
etdit.setText would cause NullPointerExceptions.

Did u try to check the response Its something like this:
[{"id":"755","level":"1","time_in_secs":"3","par":"0","initials":"KiB","quote":"Got'cha!","time_stamp":"2012-04-09 22:50:52"},{"id":"977","level":"1","time_in_secs":"3","par":"0","initials":"WJF","quote":"dats right numero uno","time_stamp":"2013-03-11 02:29:36"},{"id":"874","level":"1","time_in_secs":"3","par":"0","initials":"WJF","quote":"Look, Ma. No hands!","time_stamp":"2012-05-25 15:44:10"},{"id":"59","level":"1","time_in_secs":"4","par":"0","initials":"TMF","quote":"Hey hey ole ' hickery","time_stamp":"2012-03-03 04:36:15"},{"id":"61","level":"1","time_in_secs":"4","par":"0","initials":"WJF","quote":"I'm on a boat!","time_stamp":"2012-03-03 04:38:54"}]
As you can see its not ResponseString its a ResponseArray. Modify it accordingly.
Also check whether it type is POST or GET

Related

How to show custom validation message for username input?

I am trying to validate username input when creating new account.
I have these constrains:
^(?=.{3,14}$)(?![_.])(?!.*[_.]{2})[a-zA-Z0-9._]+(?<![_.])$
^(?=.{3,14}$) for username is 3-14 characters long
(?![_.]) username can`t start with . or _
(?!.*[_.]{2}) no __ or . or . or .. inside username
[a-zA-Z0-9._] allowed characters
(?<![_.])$ username can not end with
and other error messages also.
This is my method (Note that i use TextInputEditText object)
private boolean isUsernameValidated() {
String newUsername = et_Signup_username.getText().toString().trim();
if (newUsername.isEmpty()) {
etLayout_Signup_username.setError("Field can't be empty.");
return false;
} else {
etLayout_Signup_username.setError(null);
return true;
}
}
How can I show custom error message like if the username start with _ or . message popup Username cant start with _ or .
or other error message as shown above ?
So, I got your issue. Basically, you are trying to show different error messages for different type of errors .
Instead of writing all the long codes, you can use a simple library known as "AwesomeValidation". And you can simply put the following line of code, to make the library validate everything for you.
mAwesomeValidation.addValidation(activity, R.id.et_Signup_username, "(?![_.])", R.string.err_name);
You can import it by pasting this in your gradle
implementation 'com.basgeekball:awesome-validation:4.2'
For more details about this library, please check this link.

Getting "You cannot access body after reading from request's data stream" while using django-rest-framework

My first question here, & a newbie to everything including coding.
I am using django-rest-framework to call a rest api from an android app I am building.
I am calling another view's method from the api_view method of django-rest-framework.
This works great with the GET method, but fails while using the POST method.
Below is the code:
View 1:
#api_view(['GET', 'POST'])
def get_dos(request):
return View2.get_data(request)
View 2:
def get_data(request):
#if I print request.body, it goes through without problems
#print request.body
#but commenting it fails when I read from request.POST.get below:
var1 = int(request.POST.get('test', 0))
#fails in the above statement.
I have tried commenting all middleware classes in the settings file, but no luck :(. I keep getting "You cannot access body after reading from request's data stream" error.
Am I doing something silly? Any assistance appreciated. Thanks!

Place Autocomplete for autocomplete textview

I'm trying to give auto suggestion for places when user typing in auto complete text view in android. Right now i'm using the new Google play services libraries and sample code from the following link Place Auto complete . But When trying to give suggestion for the user typed text, I'm getting the following error
Error getting autocomplete prediction API call:
Status { statusCode = NETWORK_ERROR, resolution = null }
Any idea what may be the problem?
I have found this: "public static final int NETWORK_ERROR
A network error occurred. Retrying should resolve the problem.
Constant Value: 7 (0x00000007) " see here.

Filter Navision WebService in Android for ReadMultiple Method

I have called navision web service succesfully by authenticating it through the use of NTML authentication protocol. And i also got the full, Proper data for all the Method but i have issue in calling READ MULTIPLE METHOD with Filter. i have passed filter in below manner.
CustomerList_Filter customFilter = new CustomerList_Filter();
customFilter.field = CustomerList_Fields.Name;
customFilter.criteria = "B*";
VectorCustomerList_Filter vfilter = new VectorCustomerList_Filter();
vfilter.add(customFilter);
custService.ReadMultipleAsync(vfilter, null,0);
Eventhough i passes Filter to get Customer name Record starting with B letter still it shows all customer. & custService is an object of CustomerList_Service class.Please help.
It is said that first parameter of ReadMultiple is array. Is VectorCustomerList_Filter an array? Maybe you should write custService.ReadMultipleAsync(vfilter.ToArray(), null,0);
Also you can try to put code the way in this answer. salesOrdersService.ReadMultiple(new SalesOrders_Filter[] { filter }, null, 0);
If this not helps then try to catch output XML message that is sent as request to web service. You'll be able to find error by analyzing it.

getEntity call results in crash (using odata4j on a WCF service)

I am trying out odata4j in my android app to retrieve data from a DB that can be accessed from a WCF service.
ODataConsumer co = ODataConsumer.create("http://xxx.xx.xx.xxx:xxxx/Users");
for(OEntity user : co.getEntities("Users").execute())
{
// do stuff
}
However this crashes at the call to getEntities. I have tried a variety of other calls as well, such as
Enumerable<OEntity> eo = co.getEntities("Users").execute();
OEntity users = eo.elementAt(0);
However this also crashes at eo.elementAt(0).
The logcat doesn't tell me anything, and the callstack seems to be Suspended at ActivityThread.performLaunchActivity.
Entering "http://localhost:xxxx/Users" in my web browser on the other hand works as expected and returns the users in my DB in xml format.
Any ideas on how I can debug this?
To log all http requests/responses:
ODataConsumer.dump.all(true);
The uri passed to the consumer .create call should be the service root. e.g. .create("http://xxx.xx.xx.xxx:xxxx/"); Otherwise your code looks fine.
Note the Enumerable behaves like the .net type - enumeration is deferred until access. If you plan on indexing multiple times into the results, I'd suggest you call .toList() first.
Let me know what you find out.
Hope that helps,
- john
I guess the call should be:
ODataConsumer co = ODataConsumer.create("http://xxx.xx.xx.xxx:xxxx");
for(OEntity user : co.getEntities("Users").execute())
{
// do stuff
}
create defines service you want to connect but Users is the resource you want to query.
Can you try this way.
OEntity oEntity;
OQueryRequest<OEntity> oQueryRequest= oDataJerseyConsumer.getEntities(entityName);
List<OEntity> list= oQueryRequest.execute().toList();
for (OEntity o : list) {
List<OProperty<?>> props = o.getProperties();
for (OProperty<?> prop : props) {
System.out.println(prop.getValue().toString());
}
}

Categories

Resources