현재 안드로이드 (네이티브 앱)에 신규 사용자 등록 양식을 만들고 .php 파일을 사용하여 등록 양식을 개발 중입니다. Runnig 코드에 따라 다음과 같은 오류가 발생합니다. "불행히도 응용 프로그램이 중지되었습니다." 코드를 변경하기 위해 여러 가지 방법으로 코드를 변경하려고했지만 아무런 결과가 없었습니다.SignUp 형식 : 안드로이드 4.0을 사용하여 MySQL에 데이터 삽입
<?php
$dbcnx = @mysql_connect("localhost", "root", "root");
$db = "dbname";
mysql_select_db($db, $dbcnx);
$user_id=$_POST['user'];
$passwd=$_POST['passwd'];
$query = 'INSERT INTO `users` VALUES (NULL, \''.$user_id.'\', \''.$passwd.'\')';
$result = mysql_query($query) or die ("<b>Query failed:</b> " . mysql_error());
mysql_free_result($result);
mysql_close($dbcnx);
?>
그리고 된 .java 파일 : 다음은 PHP 코드
import java.util.ArrayList;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
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 org.apache.http.protocol.HTTP;
import android.app.ListActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class Register extends ListActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.register);
Button Insert=(Button)findViewById(R.id.send_button);
Insert.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
try {
EditText Text1=(EditText)findViewById(R.id.user_id);
EditText Text2=(EditText)findViewById(R.id.passwd);
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("user", ""+Text1.getText().toString()+""));
nameValuePairs.add(new BasicNameValuePair("passwd", ""+Text2.getText().toString()+""));
Log.e(""+Text1.getText().toString(),"0");
Log.e(""+Text2.getText().toString(),"0");
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://10.0.2.2/jku/user_reg.php");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs, HTTP.UTF_8));
HttpResponse response = httpclient.execute(httppost);
}
catch(Exception e) {
Log.e("log_tag", "Error in http connection "+e.toString());
}
}
});
}
}
내 실수에 집착, 그래서 나는 안드로이드에 초보자이야 어떤 제안 도움이 될 것입니다.
LogCat을 확인했지만 아무 것도 이해하지 못했습니다. 그래서 여기에 로그 이야기는 다음과 같습니다
01-04 21:37:13.275: D/gralloc_goldfish(552): Emulator without GPU emulation detected.
01-04 21:37:13.345: W/TextLayoutCache(552): computeValuesWithHarfbuzz -- need to force to single run
01-04 21:37:47.385: D/AndroidRuntime(552): Shutting down VM
01-04 21:37:47.385: W/dalvikvm(552): threadid=1: thread exiting with uncaught exception (group=0x409961f8)
01-04 21:37:47.476: E/AndroidRuntime(552): FATAL EXCEPTION: main
01-04 21:37:47.476: E/AndroidRuntime(552): java.lang.RuntimeException: Unable to start activity ComponentInfo{jku.project.kusss/jku.project.kusss.Register}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
01-04 21:37:47.476: E/AndroidRuntime(552): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
01-04 21:37:47.476: E/AndroidRuntime(552): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
01-04 21:37:47.476: E/AndroidRuntime(552): at android.app.ActivityThread.access$600(ActivityThread.java:122)
01-04 21:37:47.476: E/AndroidRuntime(552): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
01-04 21:37:47.476: E/AndroidRuntime(552): at android.os.Handler.dispatchMessage(Handler.java:99)
01-04 21:37:47.476: E/AndroidRuntime(552): at android.os.Looper.loop(Looper.java:137)
01-04 21:37:47.476: E/AndroidRuntime(552): at android.app.ActivityThread.main(ActivityThread.java:4340)
01-04 21:37:47.476: E/AndroidRuntime(552): at java.lang.reflect.Method.invokeNative(Native Method)
01-04 21:37:47.476: E/AndroidRuntime(552): at java.lang.reflect.Method.invoke(Method.java:511)
01-04 21:37:47.476: E/AndroidRuntime(552): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
01-04 21:37:47.476: E/AndroidRuntime(552): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
01-04 21:37:47.476: E/AndroidRuntime(552): at dalvik.system.NativeStart.main(Native Method)
01-04 21:37:47.476: E/AndroidRuntime(552): Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
01-04 21:37:47.476: E/AndroidRuntime(552): at android.app.ListActivity.onContentChanged(ListActivity.java:243)
01-04 21:37:47.476: E/AndroidRuntime(552): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:254)
01-04 21:37:47.476: E/AndroidRuntime(552): at android.app.Activity.setContentView(Activity.java:1835)
01-04 21:37:47.476: E/AndroidRuntime(552): at jku.project.kusss.Register.onCreate(Register.java:27)
01-04 21:37:47.476: E/AndroidRuntime(552): at android.app.Activity.performCreate(Activity.java:4465)
01-04 21:37:47.476: E/AndroidRuntime(552): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
01-04 21:37:47.476: E/AndroidRuntime(552): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
01-04 21:37:47.476: E/AndroidRuntime(552): ... 11 more
logcat을 사용하여 오류에 대한 정보를 얻고 스택 트레이스를 추가하십시오. – fkerber
오류 스택 추적을 게시 할 수 있습니까? eclipse 또는 "adb logcat"에서이 출력을 얻을 수 있습니다. 또한 안전상의 이유로 PHP와 SQL 상호 작용을 할 때 PDO를 조사해야합니다. http://ca3.php.net/pdo보다 안전한 SQL 상호 작용을 작성하는 것이 훨씬 쉽습니다. – jlindenbaum
LogCat 위에 추가했습니다. 그런데 코드 절차가 옳은가? 실수하지 않고? – Dozent