Ниже приведен код моего действия, который я использую для отправки HTTP-запроса на сервер в новом потоке. Однако есть синтаксическая ошибка, которую я не могу понять.Выполнение HTTP-запроса внутри потока - Ошибка
Ниже ошибка я получаю
Multiple markers at this line
- Syntax error, insert ")" to complete ClassInstanceCreationExpression
- Syntax error, insert ";" to complete BlockStatements
Я новичок в Java. Пожалуйста помоги.
public class RegisterActivity extends Activity {
private static final String TAG = "RegisterActivity";
/*
* Event listener for registration button. This will load the loading view and fire up the HTTP request to the server
*/
public OnClickListener registrationBtnListener = new OnClickListener() {
public void onClick(View v) {
Thread trd = new Thread(new Runnable(){
@Override
public void run(){
String urlParameters = "";
try {
urlParameters = "fName=" + URLEncoder.encode("John", "UTF-8") +
"&lName=" + URLEncoder.encode("Smith", "UTF-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Http.post("http://192.168.1.101/project/test.php", urlParameters);
}
}
trd.run();
}
};
РЕДАКТИРОВАТЬ:
Фиксированный путем добавления); перед trd.run(). Но теперь, я получаю другую ошибку:
Multiple markers at this line
- The method run() of type new Runnable(){} must override a superclass
method
- implements java.lang.Runnable.run
Ниже приводится код:
Thread trd = new Thread(new Runnable(){
@Override
public void run(){
String urlParameters = "";
try {
urlParameters = "fName=" + URLEncoder.encode("yash", "UTF-8") +
"&lName=" + URLEncoder.encode("desai", "UTF-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Http.post("http://192.168.1.101/bworld/test.php", urlParameters);
}
});
Ошибка в этой строке:
public void run(){
Какая строка относится к этой ошибке? – Hassan
строка перед trd.run(); –