2

What mean Non-static method 'put(java.lang.String, java.lang.String)' cannot be referenced from a static context in android studio?

Bhaven Shah
  • 692
  • 1
  • 5
  • 18
  • Next time you have that type of question, also remember to add the relevant code in the body of the question itself, rather than just a print screen. So other can copy/paste your code in their own Visual Studio and help you even more efficiently – β.εηοιτ.βε Aug 13 '19 at 23:09

2 Answers2

4

Use

contentValues.put("name",name);

instead of

ContentValues.put("name",name);
Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
  • Hi @mhmd if this or any answer has solved your question please consider [accepting it](https://meta.stackexchange.com/q/5234/179419) by clicking the check-mark. This indicates to the wider community that you've found a solution and gives some reputation to both the answerer and yourself. There is no obligation to do this. – Gabriele Mariotti Aug 13 '19 at 21:07
  • okay done! @Gabriele Mariotti –  Aug 13 '19 at 21:13
  • @mhmd what the message means, now is that you used the method on the class itself (starting with a capital) and not on the variable called `contentValues` (staring with a lower-cased letter) that you instantiated on the line above. – β.εηοιτ.βε Aug 13 '19 at 23:05
0

It means exactly that, you are calling put as a static method and it is not static. Yo are doing:

ContentValues contentValues = new ContentValues();

but in the next line you are calling:

ContentValues.put("name", name)

You see... If not... what you have to do is:

contentValues.put("name", name)

and that solves the problem

charli3B
  • 56
  • 6