Android: buffer.toString() dosen't work - android

I trying to connect my Android application to a database on remote host.
I want to use the records of the DB, but there's a problem when i try to do this:
if(buffer.toString()=="OPEN")
{
button_signal.setText("OPEN");
}
else
{
button_signal.setText("CLOSE");
}
I have checked buffer.toString() using Logs, and it is equal to "OPEN", but the button_signal's text is printed "CLOSE". Why? Can you help me?

It might have some invisible characters or some letters might be in different case, so please try this:
buffer.toString().trim().equalsIgnoreCase("OPEN");

You can't compare String with the "==" Operator in Java. A String is an Object.
Try this buffer.toString().equals("OPEN");
EDIT:
Even better is if you compare it like this: "OPEN".equals(buffer.toString())
Because it won't throw an exception if buffer is null.

Related

python - Database fetch misses ids (u'1') and has extra ids (1), may be caused by a type incoherence in a previous request

I am making an android application on crm module of odoo 10 and I want to create quotation in odoo through my application and I am passing this various arguments to ORecordValues and after that I am calling the createRecord().So when I am clicking on save button I am calling python api and python api is giving me this error.
Database fetch misses ids (u'1') and has extra ids (1), may be caused by a type incoherence in a previous request
This is my code for inserting record in odoo.
ORecordValues values = new ORecordValues();
values.put("partner_id",resPartnerArrayList.get(idc).get_id());//parter id
values.put("date_order", binding.qOrderDate.getText().toString());
if(!expDate.isEmpty())
{
values.put("validity_date",
binding.qExpirationDate.getText().toString());
}
if(!paymentTerms.isEmpty())
{
values.put("payment_term_id",paymentTermArrayList.get(idP).get_id());//payment term id
}
if(!binding.qUntaxedAmount.getText().toString().isEmpty())
{
values.put("amount_untaxed",binding.qUntaxedAmount.getText().toString());
}
if(!binding.qTotal.getText().toString().isEmpty())
{
values.put("amount_total", binding.qTotal.getText().toString());
}
if(!binding.qTaxes.getText().toString().isEmpty())
{
values.put("amount_tax", binding.qTaxes.getText().toString());
}
return odoo.createRecord("sale.order", values);
I think you trying to pass unicode value to Many2one field. Perform a type conversion. I think in your case its payment_term_id.
Hope it will help you.
I found the Solution that work for me. I got error because i was passing the String in partner_id which odoo is taking as unicode so i parse the type of it and changed it like this. it worked for me.
values.put("partner_id",resPartnerArrayList.get(idc).get_id())
to
values.put("partner_id", Integer.parseInt
(resPartnerArrayList.get(idc).get_id()));

Calculator final output issue

I am creating a calculator app in android. It should calculate anonymously whatever is on textBox. For e.g. I enter 1+2.5-5*8 in textBox. But when I call addition method the app gets crashed. Because the input is in string format and answer I want is in numeric format. I used string buffer. I tried in java that when I enter (1+1+3-1) in stringBuffer and I display using println() method it give correct answer but same does not happen with string buffer when I take that value from editText.
You have to convert string into integer or float.
Use Integer.parseInt("") method to covert to integer and Float.parseFloat("") to convert to float.
First of all welcome to StackOverFlow
It might help if you add code and the error log in the question
So I am gonna cover all the possible things that might be happening wrong in your program:
NumberFormatException- you might not be converting the string "12" into int 12 to do so use Interger.parseInt(your string buffer with number only here);
Try using a stack and a queue for your solution (google it you will get details)
You might be making a mistake in getting string from edittext it sometimes give NullPointerException
if above is not enough comment and add your code asap

output text line by line

I write app for Android such gets data from server in JSON format. Now I get this value in string, but in my application it must look like:
Route:
1)first point
2)secon point
3).....
n) n point
I read that in Android in textView I can do it if string will be with html tags but I think it is not the best variant. After Android I must do it in iPhone now I don't know how to do that there. Send Routes as Array is not good variant too. Can you say what is the best way to decide this problem?
Have a look here you will have to find the good pattern .
Hence you have separated strings just use a list View with an ArrayAdapter.
I am not so good with regex but i think it should like : [1-9][0-9]) [[a-f][0-9]]+
I couldn't comment b/c of rep, sorry. Could you provide an example of returned JSON string. I think JSON format can be parsed with ease.
If this the case you can parse it in a loop (or another way. I'm not that good at it)
String[] parseIt (String JSON){
String[] list=JSON.split("\\d\\)");
String[] rlist=new String[list.length-1];
for(int i=0;i<list.length-1;i++){
rlist[i]=list[i+1].trim();
}
return rlist;
}
This might do trick. But you should edit result. I didn't test yet
Edit: I edited code. It simply return the address now with leading whitespace. You can get rid off them using. String trim() method like;
list[1].trim();
Do it in loop and don't care about first element (index 0).
Edit 2: Now it should work

exception in insert value in sqlite database android

i want to insert default value in database table
and i am using and put text string below:
INSERT INTO song_text VALUES(1,'Tell me girl, what's it gonna be I
want you, baby do you want me You got me going insane, I'm losing my
mind Is your love true, or am I wasting my time',1);
but it is giving exception:
12-02 14:11:37.860: ERROR/Database(568): Failure 1 (near "s": syntax
error) on 0x247be8 when preparing 'INSERT INTO song_text
VALUES(2,'Tell me girl, what's it gonna be
please give any solution..
thanks
You have to escape the apostrophes:
INSERT INTO song_text VALUES(1,'Tell me girl, what\'s it gonna be I want you, baby do you want me You got me going insane, I\'m losing my mind Is your love true, or am I wasting my time',1);
You should escape characters for your String, since for what's, it understands you have finished your String. Thus you should use: what\'s.
To be generic, you can use a method to replace all ' to \'. For example you may use:
private String convertString(String x) {
return x = x.replace("'","\'");
}
Hope this helps!

Android NumberFormatException error with a simple number input from EditText

So I have a simple Edit-text with number input.
User enters his phone number and it is saved into DB obviously that is the goal.
now every time i do
int contactNumber=Integer.parseInt(mContactNumber.getText().toString());
I get an error thrown saying NumberFormatException for some reason it doesn't like a string of number. I have made sure that mContactNumber field in the android input field has the
android:input="number"
now i also tried just to be sure
int contactNumber=Integer.parseInt(mContactNumber.getText().toString().trim());
still the same error
Guys any ideas?
Try putting the Type to ' long ' instead of ' int '. Hope that will work for you.
This might be because you are leaving the text field empty. Are you sure you are not parsing an empty string?
You need to put a simple condition:
if(mContactNumber.getText().length()>0)
{
int contactNumber=Integer.parseInt(mContactNumber.getText().toString().trim());
}
For phone Number you can not take it as Integer. try to take it as string only and after getting that string you can do the check for the numbers only by
TextUtils.isDigitsOnly(str);

Categories

Resources