Android应用谷歌电子表格表单数据发布

时间:2012-10-29 13:34:28

标签: java android google-sheets google-docs-api google-spreadsheet-api

我一直在对帖子进行整理,试图解决这个问题。我不能让我的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;
}
}

logcat的:

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

1 个答案:

答案 0 :(得分:0)

现在为时已晚,但它可能有助于某人尝试做类似的事情,this有关代码匠的文章详细介绍了您应该使用的流程,以便从Android应用向Google电子表格发送数据。