I have no idea what I've done wrong - but I'm having several issues with compiling the following code after combining the source code from two different files I had and implementing AsyncTask. Any suggestions as to what could be causing these issues (as a learning experience) and if it's not too complicated a way to resolve them is appreciated.
(Thanks in advance!)
PROBLEMS:
Description Resource Path Location Type
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
P.S.
I've been able to come up with the source code below with the help of several users however I'm still having several problems (listed below) and the string of data: http://gamedemo.hostzi.com/apply.cgi?submit_button=Wireless_MAC&change_action=&action=Apply&wl_macmode=allow&wl_maclist=32&wait_time=3&wl_mac_filter=1&start=&wl_macmode1=allow&m0=00%3A1E%3A33%3AFE%3A0D%3A38&m16=00%3A00%3A00%3A00%3A00%3A00&m1=00%3A00%3A00%3A00%3A00%3A00&m17=00%3A00%3A00%3A00%3A00%3A00&m2=00%3A00%3A00%3A00%3A00%3A00&m18=00%3A00%3A00%3A00%3A00%3A00&m3=00%3A00%3A00%3A00%3A00%3A00&m19=00%3A00%3A00%3A00%3A00%3A00&m4=00%3A00%3A00%3A00%3A00%3A00&m20=00%3A00%3A00%3A00%3A00%3A00&m5=00%3A00%3A00%3A00%3A00%3A00&m21=00%3A00%3A00%3A00%3A00%3A00&m6=00%3A00%3A00%3A00%3A00%3A00&m22=00%3A00%3A00%3A00%3A00%3A00&m7=00%3A00%3A00%3A00%3A00%3A00&m23=00%3A00%3A00%3A00%3A00%3A00&m8=00%3A00%3A00%3A00%3A00%3A00&m24=00%3A00%3A00%3A00%3A00%3A00&m9=00%3A00%3A00%3A00%3A00%3A00&m25=00%3A00%3A00%3A00%3A00%3A00&m10=00%3A00%3A00%3A00%3A00%3A00&m26=00%3A00%3A00%3A00%3A00%3A00&m11=00%3A00%3A00%3A00%3A00%3A00&m27=00%3A00%3A00%3A00%3A00%3A00&m12=00%3A00%3A00%3A00%3A00%3A00&m28=00%3A00%3A00%3A00%3A00%3A00&m13=00%3A00%3A00%3A00%3A00%3A00&m29=00%3A00%3A00%3A00%3A00%3A00&m14=00%3A00%3A00%3A00%3A00%3A00&m30=00%3A00%3A00%3A00%3A00%3A00&m15=00%3A00%3A00%3A00%3A00%3A00&m31=00%3A00%3A00%3A00%3A00%3A00&end=
...never appears to hit the server (I'm checking the logs - no changes when clicking submit in the app which is supposed to send the string above - and if I paste that URL in a browser it works successfully)
Also - the reason it never appears on the server might be being caused by the fact I have to hit space before I can click submit because the text box is required before clicking submit - I think I may need to eliminate the text box entirely (I don't need it at all - I just want to send the predefined string of data) but Im not sure I know how to do so without butchering the source code.
JAVA:
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
}
}
}
}