我不知道我做错了什么 - 但是在组合我拥有的两个不同文件的源代码并实现 AsyncTask 之后,我在编译以下代码时遇到了几个问题。任何关于可能导致这些问题的建议(作为一种学习经验)以及解决这些问题的方法是否不太复杂,我们都将不胜感激。
(提前致谢!)
问题:
说明 资源路径 位置 类型
The nested type AddEditCountry cannot hide an enclosing type AddEditCountry.java /Game Demo/src/com/nfc/gamedemo line 159 Java Problem
Syntax error, insert "AssignmentOperator Expression" to complete Expression AddEditCountry.java /Game Demo/src/com/nfc/gamedemo line 153 Java Problem
The left-hand side of an assignment must be a variable AddEditCountry.java /Game Demo/src/com/nfc/gamedemo line 153 Java Problem
附言
...从来没有出现在服务器上(我正在检查日志 - 在应用程序中单击提交时没有任何变化,应该发送上面的字符串 - 如果我将该 URL 粘贴到浏览器中,它会成功运行)
另外-它从未出现在服务器上的原因可能是由于我必须先按空格才能单击提交,因为在单击提交之前需要文本框-我想我可能需要完全消除文本框(我根本不需要它 - 我只想发送预定义的数据字符串)但我不确定我是否知道如何在不破坏源代码的情况下这样做。
爪哇:
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import android.app.Activity;
import android.opengl.Visibility;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
public class DeviceConfig extends Activity implements OnClickListener{
private EditText value;
private Button btn;
private ProgressBar pb;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.deviceconfig);
value=(EditText)findViewById(R.id.editText1);
btn=(Button)findViewById(R.id.button1);
pb=(ProgressBar)findViewById(R.id.progressBar1);
pb.setVisibility(View.GONE);
btn.setOnClickListener(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void onClick(View v) {
// TODO Auto-generated method stub
if(value.getText().toString().length()<1){
// out of range
Toast.makeText(this, "please enter something", Toast.LENGTH_LONG).show();
}else{
pb.setVisibility(View.VISIBLE);
new MyAsyncTask().execute(value.getText().toString());
}
}
private class MyAsyncTask extends AsyncTask<String, Integer, Double>{
@Override
protected Double doInBackground(String... params) {
// TODO Auto-generated method stub
postData(params[0]);
return null;
}
protected void onPostExecute(Double result){
pb.setVisibility(View.GONE);
Toast.makeText(getApplicationContext(), "command sent", Toast.LENGTH_LONG).show();
}
protected void onProgressUpdate(Integer... progress){
pb.setProgress(progress[0]);
}
public void postData(String valueIWantToSend) {
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://192.168.1.1/apply.cgi");
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("myHttpData", valueIWantToSend));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
}
}
}