 |
|
รบกวนที่ครับคือผมพยายามทำตามคลิปนี้ครับ
https://www.youtube.com/watch?v=cOsZHuu8Qog&index=2&list=PLshdtb5UWjSppGmM3IdygV6RusjU3KjlZ
ก็ทำตามเขาเป๊ะเลยครับ ไม่มีขึ้นแดงฟ้องเลย พอเขารันดันได้แต่ผมดัน Error บานเลยครับ
รบกวนที่ครับ ผมเครียดมากเลยครับ จนปัญญา มีท่านผู้รู้ท่านใดพอจะช่วยผมได้บ้างครับ
Register.java
package com.example.puen.connectmysqltest;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
public class Register extends Activity{
EditText ET_NAME,ET_USER_NAME,ET_USER_PASS;
String name,user_name,user_pass;
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.register_layout);
ET_NAME = (EditText)findViewById(R.id.name);
ET_USER_NAME = (EditText)findViewById(R.id.new_user_name);
ET_USER_PASS = (EditText)findViewById(R.id.new_user_pass);
}
public void userReg(View view)
{
name = ET_NAME.getText().toString();
user_name = ET_USER_NAME.getText().toString();
user_pass = ET_USER_PASS.getText().toString();
String method ="register";
BackgroundTask backgroundTask=new BackgroundTask(this);
backgroundTask.execute(method,name,user_name,user_pass);
finish();
}
}
BackgroundTask
package com.example.puen.connectmysqltest;
import android.content.Context;
import android.os.AsyncTask;
import android.widget.Toast;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
/**
* Created by puen on 4/4/2016.
*/
public class BackgroundTask extends AsyncTask<String,Void,String> {
Context ctx;
BackgroundTask(Context ctx)
{
this.ctx= ctx;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected String doInBackground(String... params) {
String reg_url ="http://10.0.2.2/webapp/register.php";
String login_url ="http://10.0.2.2/webapp/login.php";
String method = params[0];
if(method.equals("register"))
{
String name = params[1];
String user_name= params[2];
String user_pass= params[3];
try {
URL url = new URL(reg_url);
HttpURLConnection httpURLConnection = (HttpURLConnection)url.openConnection();
httpURLConnection.setRequestMethod("POST");
// httpURLConnection.setDoOutput(true);
OutputStream os = httpURLConnection.getOutputStream();
BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(os,"UTF-8"));
String data = URLEncoder.encode("user","UTF-8")+"="+URLEncoder.encode(name,"UTF-8")+"&"+
URLEncoder.encode("user_name","UTF-8")+"="+URLEncoder.encode(user_name,"UTF-8")+"&"+
URLEncoder.encode("user_pass","UTF-8")+"="+URLEncoder.encode(user_pass,"UTF-8");
bufferedWriter.write(data);
bufferedWriter.flush();
bufferedWriter.close();
os.close();
InputStream IS = httpURLConnection.getInputStream();
IS.close();
return "Registration Seccess...";
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
@Override
protected void onProgressUpdate(Void... values) {
super.onProgressUpdate(values);
}
@Override
protected void onPostExecute(String result) {
Toast.makeText(ctx,result,Toast.LENGTH_LONG).show();
}
}
อันนี้error ตรง monitor
04-04 13:46:54.465 1152-1152/com.example.puen.connectmysqltest E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.puen.connectmysqltest, PID: 1152
java.lang.IllegalStateException: Could not execute method for android:onClick
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:293)
at android.view.View.performClick(View.java:4438)
at android.view.View$PerformClick.run(View.java:18422)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
at android.view.View.performClick(View.java:4438)
at android.view.View$PerformClick.run(View.java:18422)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.puen.connectmysqltest/com.example.puen.connectmysqltest.Register}; have you declared this activity in your AndroidManifest.xml?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1628)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1424)
at android.app.Activity.startActivityForResult(Activity.java:3424)
at android.app.Activity.startActivityForResult(Activity.java:3385)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:843)
at android.app.Activity.startActivity(Activity.java:3627)
at android.app.Activity.startActivity(Activity.java:3595)
at com.example.puen.connectmysqltest.MainActivity.userReg(MainActivity.java:18)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
at android.view.View.performClick(View.java:4438)
at android.view.View$PerformClick.run(View.java:18422)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Event Log
11:48:41 PM Adb connection Error:An existing connection was forcibly closed by the remote host
11:48:41 PM Sending Tracking request failed!
11:48:41 PM Adb connection Error:An existing connection was forcibly closed by the remote host
11:48:42 PM Connection attempts: 1
11:48:44 PM Connection attempts: 2
11:48:46 PM Connection attempts: 3
11:48:49 PM Connection attempts: 4
11:48:49 PM Genymotion: Refresh: success
11:48:50 PM Connection attempts: 5
11:48:52 PM Connection attempts: 6
11:49:04 PM Connection attempts: 7
11:49:04 PM Connection attempts: 8
11:49:04 PM Connection attempts: 9
11:49:04 PM Connection attempts: 10
11:49:04 PM Connection attempts: 11
12:03:09 AM Executing tasks: [:app:assembleDebug]
12:06:33 AM Gradle build finished in 3m 38s 319ms
12:10:33 AM Session 'app': Error
12:14:22 AM Adb connection Error:An existing connection was forcibly closed by the remote host
12:14:23 AM Connection attempts: 1
12:14:25 AM Connection attempts: 2
12:14:27 AM Connection attempts: 3
12:14:29 AM Connection attempts: 4
12:14:31 AM Connection attempts: 5
12:14:33 AM Connection attempts: 6
12:14:35 AM Connection attempts: 7
12:14:37 AM Connection attempts: 8
12:14:39 AM Connection attempts: 9
12:14:41 AM Connection attempts: 10
12:14:43 AM Connection attempts: 11
Tag : Mobile, MySQL, WebService, Android, JAVA
|
|
 |
 |
 |
 |
Date :
2016-04-05 01:16:47 |
By :
rattapongza |
View :
1576 |
Reply :
4 |
|
 |
 |
 |
 |
|
|
|
 |