几天来,我一直在整理帖子,试图弄清楚这一点。我无法让我的 Android 表单应用程序发布到谷歌文档的电子表格,寻求帮助有人可以查看编码并告诉我是否遗漏了什么我做错了什么这是代码:
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpEntity;
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.os.AsyncTask;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
public class SubmitForm extends AsyncTask<URL, Object, Object> implements OnClickListener{
EditText arrivalText;
EditText assignmentText;
EditText clientText;
EditText departureText;
Spinner employeeSpinner;
EditText jobDateText;
Spinner jobTypeSpinner;
EditText notesText;
Button submitButton;
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(3);
public void onClick(View v) {
// TODO Auto-generated method stub
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("https://docs.google.com/spreadsheet/ccc?key=0AsEKRuGCDAg_dE01ZXlyR2VoTHFrWUdTNUVwdnN0R0E#gid=0");
try{
nameValuePairs.add(new BasicNameValuePair("entry.0.single",
employeeSpinner.getSelectedItem().toString()));
nameValuePairs.add(new BasicNameValuePair("entry.1.single",
jobTypeSpinner.getSelectedItem().toString()));
nameValuePairs.add(new BasicNameValuePair("entry.2.single",
clientText.getText().toString()));
HttpResponse response = httpclient.execute(httppost);
Log.d("RESPONSE", "info: ");
HttpEntity entity = response.getEntity();
InputStream inputstream = entity.getContent();
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
Log.d("YOUR_TAG", "An error has occurred", e);
e.printStackTrace();
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
Log.d("YOUR_TAG", "client protocol exception", e);
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
Log.d("YOUR_TAG", "io exception", e);
e.printStackTrace();
} finally {
}
}
protected Object doInBackground(URL... params) {
// TODO Auto-generated method stub
return null;
}
}
日志猫:
10-29 20:03:44.583: D/CLIPBOARD(28779): Hide Clipboard dialog at Starting input: finished by someone else... !
10-29 20:03:57.636: W/dalvikvm(28779): threadid=1: thread exiting with uncaught exception (group=0x40bef1f8)
10-29 20:03:57.646: E/AndroidRuntime(28779): FATAL EXCEPTION: main
10-29 20:03:57.646: E/AndroidRuntime(28779): java.lang.IllegalStateException: Could not find a method onClick(View) in the activity class com.matrixapps.assignmenttracker.AssignmentTracker for onClick handler on view class android.widget.Button with id 'submitButton'
10-29 20:03:57.646: E/AndroidRuntime(28779): at android.view.View$1.onClick(View.java:3087)
10-29 20:03:57.646: E/AndroidRuntime(28779): at android.view.View.performClick(View.java:3627)
10-29 20:03:57.646: E/AndroidRuntime(28779): at android.view.View$PerformClick.run(View.java:14329)
10-29 20:03:57.646: E/AndroidRuntime(28779): at android.os.Handler.handleCallback(Handler.java:605)
10-29 20:03:57.646: E/AndroidRuntime(28779): at android.os.Handler.dispatchMessage(Handler.java:92)
10-29 20:03:57.646: E/AndroidRuntime(28779): at android.os.Looper.loop(Looper.java:137)
10-29 20:03:57.646: E/AndroidRuntime(28779): at android.app.ActivityThread.main(ActivityThread.java:4511)
10-29 20:03:57.646: E/AndroidRuntime(28779): at java.lang.reflect.Method.invokeNative(Native Method)
10-29 20:03:57.646: E/AndroidRuntime(28779): at java.lang.reflect.Method.invoke(Method.java:511)
10-29 20:03:57.646: E/AndroidRuntime(28779): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:976)
10-29 20:03:57.646: E/AndroidRuntime(28779): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:743)
10-29 20:03:57.646: E/AndroidRuntime(28779): at dalvik.system.NativeStart.main(Native Method)
10-29 20:03:57.646: E/AndroidRuntime(28779): Caused by: java.lang.NoSuchMethodException: onClick [class android.view.View]
10-29 20:03:57.646: E/AndroidRuntime(28779): at java.lang.Class.getConstructorOrMethod(Class.java:460)
10-29 20:03:57.646: E/AndroidRuntime(28779): at java.lang.Class.getMethod(Class.java:915)
10-29 20:03:57.646: E/AndroidRuntime(28779): at android.view.View$1.onClick(View.java:3080)
10-29 20:03:57.646: E/AndroidRuntime(28779): ... 11 more