我正在创建一个 android 应用程序的活动,用户在其中填写他的详细信息(由 id 的名称、bhawan、房间、手机、书籍等标识),这些值将直接传输到 Google 电子表格。它给了我那个奇怪的错误。你能帮我吗 ?提前致谢。
public class MainActivity extends Activity {
final EditText nameField = (EditText) findViewById(R.id.EditTextName);
String name = nameField.getText().toString();
final EditText bhawanField = (EditText) findViewById(R.id.EditTextBhawan);
String bhawan = bhawanField.getText().toString();
final EditText roomField = (EditText) findViewById(R.id.EditTextRoom);
String room = roomField.getText().toString();
final EditText mobileField = (EditText) findViewById(R.id.EditTextPhone);
String mobile = mobileField.getText().toString();
final EditText emailField = (EditText) findViewById(R.id.EditTextEmail);
String email = emailField.getText().toString();
final EditText bookField = (EditText) findViewById(R.id.EditTextBook);
String book = bookField.getText().toString();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button sendButton = (Button) findViewById(R.id.ButtonSubmit);
sendButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
btn_Click();
}}
);
}
public void btn_Click(){
SendHttpRequset();
}
public void SendHttpRequset(){
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost("https://spreadsheets.google.com/spreadsheet/formResponse?hl=en_US&formkey=dDlwZzh4bGFvNFBxUmRsR0d2VTVhYnc6MQ&ifq");
List<BasicNameValuePair> results = new ArrayList<BasicNameValuePair>(6);
results.add(new BasicNameValuePair("entry.0.single", name));
results.add(new BasicNameValuePair("entry.1.single", bhawan));
results.add(new BasicNameValuePair("entry.2.single", room));
results.add(new BasicNameValuePair("entry.4.single", mobile));
results.add(new BasicNameValuePair("entry.6.single", email));
results.add(new BasicNameValuePair("entry.8.single", book));
try {
HttpPost.setEntity(new UrlEncodedFormEntity(results));
}
catch (UnsupportedEncodingException e) {
// writing error to Log
e.printStackTrace();
}
// Making HTTP Request
try {
HttpResponse response = HttpClient.execute(post);
// writing response to log
Log.d("Http Response:", response.toString());
} catch (ClientProtocolException e) {
// writing exception to log
e.printStackTrace();
} catch (IOException e) {
// writing exception to log
e.printStackTrace();
}
}
/*public void submitDetails() {
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost("https://spreadsheets.google.com/spreadsheet/formResponse?hl=en_US&formkey=dDlwZzh4bGFvNFBxUmRsR0d2VTVhYnc6MQ&ifq");
List<BasicNameValuePair> results = new ArrayList<BasicNameValuePair>(6);
results.add(new BasicNameValuePair("entry.0.single", name));
results.add(new BasicNameValuePair("entry.1.single", bhawan));
results.add(new BasicNameValuePair("entry.2.single", room));
results.add(new BasicNameValuePair("entry.4.single", mobile));
results.add(new BasicNameValuePair("entry.6.single", email));
results.add(new BasicNameValuePair("entry.8.single", book));
try {
HttpPost.setEntity(new UrlEncodedFormEntity(results));
}
catch (UnsupportedEncodingException e) {
// writing error to Log
e.printStackTrace();
}
// Making HTTP Request
try {
HttpResponse response = HttpClient.execute(post);
// writing response to log
Log.d("Http Response:", response.toString());
} catch (ClientProtocolException e) {
// writing exception to log
e.printStackTrace();
} catch (IOException e) {
// writing exception to log
e.printStackTrace();
}
}*/
}