Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8632219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:19:19+00:00 2026-06-12T09:19:19+00:00

Code: final String nome = nm.getText().toString(); final String telefone = tlf.getText().toString(); if(nome.length() != 0

  • 0

Code:

    final String nome = nm.getText().toString();
            final String telefone = tlf.getText().toString();
            if(nome.length() != 0 && telefone.length() != 0){
                if(mIndex.equals("")) {                 
                    ContentValues valor = new ContentValues();
                    valor.put("nome", nome);
                    valor.put("telefone", telefone);
                    db.insert("contatos", null, valor);
                    ShowMessage("Sucesso","O Contato " + nome + " foi salvo com sucesso");
                }
                else {
                    String[] whereArgs = {"nome", "telefone"};

                    ContentValues dataToInsert = new ContentValues();                          
                    dataToInsert.put("nome", nome);
                    dataToInsert.put("telefone", telefone);

                    db.update("contatos", dataToInsert, "nome='"+nomeant+"' and telefone='"+foneant+"' ", whereArgs);
                    ShowMessage("Sucesso","O Contato " + nome + " foi editado com sucesso");
                }
            }

So, mIndex is the index of the Contacts in the previous acitvity(which i selected and clicked the item/contact and then passed the index to the new activity) so, if the EditTexts are already BLANK it will ADD a new contact, if the EditTexts have a value and get changed it will Alter the Clicked Contacts value (name/telephone). But when i hit the button SAVE it crashes my app but the error is in the db.update line.

db.update("contatos", dataToInsert, "nome='"+nomeant+"' and telefone='"+foneant+"' ", whereArgs); so therefore i guess the whereClause or the whereArgs is wrong, but as i dont have high intelligence in Android programming.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T09:19:19+00:00Added an answer on June 12, 2026 at 9:19 am

    You don’t need the whereArgs here since you are attaching the arguments in the where clause itself. Just supply null to in place of whereArgs –

     db.update("contatos", dataToInsert, "nome='"+nomeant+"' and telefone='"+foneant+"'", null);
    

    But it is always better to use the arguments. It prevents sql injection and also takes care of escaping special characters. In your case –

    db.update("contatos", dataToInsert, "nome=? and telefone=?", whereArgs);
    

    Also, your whereArgs is wrong. It should be –

    String[] whereArgs = new String[] {nomeant, foneant};
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Whi with this code public final String[] array_titoli_serie_prima = new String[]{ getResources().getString(R.string.titolo_p1), getResources().getString(R.string.titolo_p2), getResources().getString(R.string.titolo_p3),
This is my code [...] final String[] top_spinner_items = new String[35]; for (int i
here is the code public static final String DATE_TIME_FORMAT = yyyy-MM-dd kk:mm:ss; public static
The code snippet: C2DMessaging.java public class C2DMessaging { public static final String EXTRA_SENDER =
I have the following code: public void post(String message) { final String mess =
This code is invalid: interface Foo { public void foo(final String string); } public
I found a code where it declared code like private final static String API_RTN_SUCCESS
I have a code to concatenate strings. However, for some reason, the final string
I have the following code: private static final Set<String> allowedParameters; static { Set<String> tmpSet
I have the following Java code: final Future future = exeService.submit( new Runnable() {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.