I am trying to call a method of writing. It compiles except one row ...
Public class extends http activity {httpMethod (); // Public Zero will not compile httpMethod () {HttpClient httpclient = New DefaultHttpClient (); Http post httppost = new HTTP post ("http: // site / api /"); Try {// Add Your Data List & lt; NameValuePair & gt; NameValuePairs = New ArrayList & lt; NameValuePair & gt; (2); // Execute HTTP Post Request HTTP Response Response = httpclient.execute (httppost); String test = "hello"; TextView myTextView = (TextView) Find ViewById (R.id.myTextView); MyTextView.setText (test); } Catches (ClientProtocolException E) {// Todo Auto-Generated Catch Block} Catch (IOE EXPRESS E) {/ TODO Auto-Generated Catch Block}}} I'm not the best Java is a boy, but I think that will call the method as if there is a reaction. "Hello" though does not appear ...
How do I call the method properly?
Edit: To leave anyone in any doubt, this answer only tells you that Why are you getting an error in compile-time No find out which thread you are and what time you are doing in Android. Personally, I recommend that you keep Android for a moment, learn simple environment (like console apps) in Java and then, when you're relaxing with language, on Android Come back and learn all the requirements of Android development - which is clearly just more than just language.
You are trying to call a method directly in your class as a statement. You can not do this - it should be a constructor, initial block, another method, or a part of a static initiator. For example:
// TODO: Rename this class to comply with Java naming conventions Public class expands http activity {// Constructor method is capable of calling. .. or you can call it // any other method, eg OnCreate, public restart http () {httpMethod (); } Public Zero httpMethod () {....}} Note that I have given this example to show you a valid Java class only . It does not mean that you should actually call the method from your constructor.
Comments
Post a Comment