java - list add error without activity in android -
When the code is run without extended activity and returns the error by calling the method:
Public class RequestActivity {// Extends activity {// Create protected at zero (Android bundle saved instenestate) {// super. Casket (alert instant state); // HTTP client is creating HTTP client httpClient = new DefaultHttpClient (); // HTTP Post HttpPost httpPost = New HttpPost ("http://www.example.com/login"); // Building Post Parameters / / Key and Price Couple List & lt; NameValuePair & gt; NameValuePair = New ArrayList & lt; NameValuePair & gt; (2); // The following errors in the following 2 lines: / ======== Errors: ================= // Many markers on this line // - Syntax Error Token "Add", = expected after this token - Syntax error on / token, incorrect creation (names) Name ValpPair.add (New BasicNameValuePair ("email", "user@gmail.com")); NameValuePair.add (New BasicNameValuePair ("Message", "Hi, Android! HTTP Post!")); // =============================================== Url Encoding POST parameter {httpPost.setEntity (new UrlEncodedFormEntity (nameValuePair) tries to; } Hold (unsupported encoding exception e) {// log e.printstackscases for login error; } // Create an HTTP request {HttpResponse response = httpClient.execute (httpPost); // Writing feedback to log logs log ("HTPP response:", response.toString ()); } Catch (ClientProtocolException E) {// log e Write an exception for the exception. } Hold (IOException e) {// log e Write an exception for the exception. }}}
When the class is expanded with activity and the code is kept in the Subscriber method, then it works well. So why is it not working in the previous case.
Errors are marked as comments inside the code.
Abstract for full code:
I doubt the problem that when you comment on the onCreate ()
method, your code Now is not valid Java. Remember that the code should go inside the Some method. There can be any name you want, not necessarily onCreate
.
Comments
Post a Comment