ユーザーが自分の詳細 (ID の名前、バワン、部屋、携帯電話、書籍などで識別) を入力する Android アプリのアクティビティを作成しています。これらの値は 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();
}
}*/
}