There is a request

String s = "qwerty"; VKParameters p = new VKParameters(); p.put(VKApiConst.OWNER_ID,-119852848); p.put(VKApiConst.POST_ID,4); p.put(VKApiConst.TEXT,s); p.put(VKApiConst.SORT,"desc"); p.put(VKApiConst.COUNT,20); VKRequest r = VKApi.wall().addComment(p); 

Error 100 comes that the text parameter is not passed but if done so

 p.put(VKApiConst.TEXT,"qwerty"); 

A comment is successfully added. Why is it that simple text in quotes is added, but the String variable is not?

  • And if you use getString (s), then everything will be fine? - Vyacheslav Martynenko
  • and how to use it? - antonin14d
  • and the declaration of the variable "String s =" qwerty ";" - is this exactly right? And call her through just s. I skimmed through the dock, but didn't find anything like that. - Crystal
  • And what do you suggest? String s = new Srting (); s = "qwerty"; - antonin14d
  • In the studies vk api on github tried to ask? - Alexander Lomovskiy

5 answers 5

It makes no difference what you do:

 p.put(VKApiConst.TEXT, s); 

What do you do:

 p.put(VKApiConst.TEXT, "qwerty"); В VKsdk VKParameters = Map<String, Object>. 

In fact, to enter the hardcode "qwerty" , that String s = "qwerty" in memory is an object of type String.

Look for an error in the code.

  • Where in the code? I brought the most abstract piece that would demonstrate the problem. Or did you mean vk sdk code? - user186301
  • In your code, of course. Add a literal description of the error, straight. how comes from the server. - Chaynik

I created a minimal test application with authorization and a comment sending button - everything works.

I also want to note that for the addComment method, the sort and count parameters are not required.

 public class MainActivity extends AppCompatActivity { private static final String TAG = "VKApiDemo"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); VKSdk.login(this, VKScope.WALL); Button button = (Button) findViewById(R.id.button); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String s = "qwerty"; VKParameters p = new VKParameters(); p.put(VKApiConst.OWNER_ID, -42536065); p.put(VKApiConst.POST_ID, 2454); p.put("text", "some text from app"); // p.put(VKApiConst.SORT, "desc"); // p.put(VKApiConst.COUNT, 20); VKRequest r = VKApi.wall().addComment(p); r.executeWithListener(new VKRequest.VKRequestListener() { @Override public void onComplete(VKResponse response) { super.onComplete(response); Log.e(TAG, "onComplete: response is" + response.json.toString()); } @Override public void onError(VKError error) { super.onError(error); Log.e(TAG, "onError: " + error.toString()); } }); } }); } } 

Used version of the library vk sdk android: com.vk:androidsdk:1.6.7

  • Did you connect the library with the project? And it is not clear that you would pass String s - user186301
  • @ user186301 not connected as a dependency. Sources did not extort, did not compile them and connect to the main project. - TheNorthon
  • You can lead connection code dependencies. Well compile ... - user186301
  • @ user186301 added a version of the library in response. Transmitted as an object of type String also tried, both methods work - TheNorthon

I do not see TEXT in the list of VKApiConst fields . I suggest to try

 p.put(VKApiConst.MESSAGE,s); 
  • I tried, it does not help. And I myself inserted the TEXT constant. public static final String TEXT = "text"; I did it with other constants, which are not, always worked. So that’s not the problem - user186301

Try this

 p.put(VKApiConst.TEXT,""+s); 

or experiment with encoding something like this

 // Данные в кодировке КОИ-8 byte[] koi8Data = ...; // Преобразуем из КОИ-8 в Unicode String string = new String(koi8Data,"KOI8_R"); // Преобразуем из Unicode в Windows-1251 byte[] winData = string.getBytes("Cp1251"); 

    That's right, you will receive an error 100. you are using an object.

     s.toString() 

    use

    or

     String.valueOf(s); 
    • Tried, does not help - user186301