这个java方法有什么问题?I';我一开始就出错了
我有错误 方法声明无效,需要返回类型 缺少方法体这个java方法有什么问题?I';我一开始就出错了,java,android-studio,Java,Android Studio,我有错误 方法声明无效,需要返回类型 缺少方法体 private void AutomaticServerConnect() { new Thread(new Runnable() { public void run() { response = Get(HttpCommandToSend(iptouse, 8098, "nothing")); text = (TextView) findViewById(R.id.text
private void AutomaticServerConnect()
{
new Thread(new Runnable() {
public void run() {
response = Get(HttpCommandToSend(iptouse, 8098, "nothing"));
text = (TextView) findViewById(R.id.textView2);
if (response != null)
{
try
{
final String a = new String(response, "UTF-8");
text.post(new Runnable()
{
@Override
public void run()
{
text.setText(a + " On \n" + ipaddresses[counter]);
status1.setText("Connected");
String successconnected = null;
successconnected = "Successfully connected";
textforthespeacch = successconnected;
MainActivity.this.initTTS();
}
});
iptouse = ipaddresses[i].substring(0, ipaddresses[i].lastIndexOf("=") + 1);
connectedtoipsuccess = true;
connectedSuccess = true;
Logger.getLogger("MainActivity(inside thread)").info(a);
if (!iptouse.isEmpty())
{
}
} catch (UnsupportedEncodingException e)
{
e.printStackTrace();
Logger.getLogger("MainActivity(inside thread)").info("encoding exception");
}
Logger.getLogger("MainActivity(inside thread)").info("test1");
}
else
{
text.post(new Runnable()
{
@Override
public void run()
{
text.setText("Connection Failed");
status1.setText("Connection Failed");
String successconnected = null;
successconnected = "connection failed";
textforthespeacch = successconnected;
MainActivity.this.initTTS();
}
});
}
}).start();
});
我在线路上遇到错误:
}).start();
方法声明无效,需要返回类型缺少方法体
private void AutomaticServerConnect()
{
new Thread(new Runnable() {
public void run() {
response = Get(HttpCommandToSend(iptouse, 8098, "nothing"));
text = (TextView) findViewById(R.id.textView2);
if (response != null)
{
try
{
final String a = new String(response, "UTF-8");
text.post(new Runnable()
{
@Override
public void run()
{
text.setText(a + " On \n" + ipaddresses[counter]);
status1.setText("Connected");
String successconnected = null;
successconnected = "Successfully connected";
textforthespeacch = successconnected;
MainActivity.this.initTTS();
}
});
iptouse = ipaddresses[i].substring(0, ipaddresses[i].lastIndexOf("=") + 1);
connectedtoipsuccess = true;
connectedSuccess = true;
Logger.getLogger("MainActivity(inside thread)").info(a);
if (!iptouse.isEmpty())
{
}
} catch (UnsupportedEncodingException e)
{
e.printStackTrace();
Logger.getLogger("MainActivity(inside thread)").info("encoding exception");
}
Logger.getLogger("MainActivity(inside thread)").info("test1");
}
else
{
text.post(new Runnable()
{
@Override
public void run()
{
text.setText("Connection Failed");
status1.setText("Connection Failed");
String successconnected = null;
successconnected = "connection failed";
textforthespeacch = successconnected;
MainActivity.this.initTTS();
}
});
}
}).start();
});
还有一个线路上的错误
});
}期望
正确的缩进将帮助您找到无效的大括号:
private void AutomaticServerConnect()
{
new Thread(new Runnable() {
public void run() {
...
}).start();
});
您关闭了run
方法,但没有关闭匿名Runnable
实例
应该是:
private void AutomaticServerConnect()
{
new Thread(new Runnable() {
public void run() {
...
} // added }
}).start();
} // removed );
数一数你的花括号。您在某个地方丢失了一个右大括号。由于涉及到的所有大括号的波动性,如果有人在我的编辑中看到缩进疏忽,请务必修复它。