android studio在配置usb设备时不连接mysql db
我正在尝试将我的android应用程序与mysql db连接。如果我通过emulator连接,它会成功连接,但当我尝试使用usb设备平板电脑时,它不会成功连接。它显示了这个错误:android studio在配置usb设备时不连接mysql db,android,mysql,database,android-studio,database-connection,Android,Mysql,Database,Android Studio,Database Connection,我正在尝试将我的android应用程序与mysql db连接。如果我通过emulator连接,它会成功连接,但当我尝试使用usb设备平板电脑时,它不会成功连接。它显示了这个错误: 07-29 07:12:40.651 17236-17274/com.birdorg.anpr.sdk.simple.camera.example E/AndroidRuntime﹕ FATAL EXCEPTION: AsyncTask #3 java.lang.RuntimeException: An er
07-29 07:12:40.651 17236-17274/com.birdorg.anpr.sdk.simple.camera.example E/AndroidRuntime﹕ FATAL EXCEPTION: AsyncTask #3
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:299)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
at java.util.concurrent.FutureTask.run(FutureTask.java:239)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at java.lang.Thread.run(Thread.java:838)
Caused by: java.lang.NullPointerException
at com.birdorg.anpr.sdk.simple.camera.example.AnprSdkMain$AttemptLogin.doInBackground(AnprSdkMain.java:111)
at com.birdorg.anpr.sdk.simple.camera.example.AnprSdkMain$AttemptLogin.doInBackground(AnprSdkMain.java:75)
at android.os.AsyncTask$2.call(AsyncTask.java:287)
at java.util.concurrent.FutureTask.run(FutureTask.java:234)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at java.lang.Thread.run(Thread.java:838)
07-29 07:12:40.886 17236-17236/com.birdorg.anpr.sdk.simple.camera.example I/SurfaceTextureClient﹕ [STC::queueBuffer] (this:0x51b46238) fps:9.96, dur:1003.96, max:101.63, min:99.31
07-29 07:12:41.412 17236-17236/com.birdorg.anpr.sdk.simple.camera.example E/WindowManager﹕ Activity com.birdorg.anpr.sdk.simple.camera.example.AnprSdkMain has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{417c01a8 V.E..... R.....ID 0,0-219,114} that was originally added here
android.view.WindowLeaked: Activity com.birdorg.anpr.sdk.simple.camera.example.AnprSdkMain has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{417c01a8 V.E..... R.....ID 0,0-219,114} that was originally added here
at android.view.ViewRootImpl.<init>(ViewRootImpl.java:409)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:218)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
at android.app.Dialog.show(Dialog.java:281)
at com.birdorg.anpr.sdk.simple.camera.example.AnprSdkMain$AttemptLogin.onPreExecute(AnprSdkMain.java:89)
at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:586)
at android.os.AsyncTask.execute(AsyncTask.java:534)
at com.birdorg.anpr.sdk.simple.camera.example.AnprSdkMain.onClick(AnprSdkMain.java:72)
at android.view.View.performClick(View.java:4211)
at android.view.View$PerformClick.run(View.java:17446)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:153)
at android.app.ActivityThread.main(ActivityThread.java:5299)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
public class AnprSdkMain extends Activity implements OnClickListener{
private EditText user, pass;
private Button mSubmit, mRegister;
// Progress Dialog
private ProgressDialog pDialog;
// JSON parser class
JSONParser jsonParser = new JSONParser();
//php login script location:
//localhost :
//testing on your device
//put your local ip instead, on windows, run CMD > ipconfig
//or in mac's terminal type ifconfig and look for the ip under en0 or en1
//private static final String LOGIN_URL = "http://xxx.xxx.x.x:1234/webservice/login.php";
//testing on Emulator:
private static final String LOGIN_URL = "http://10.0.2.2/anpr/webservice/login.php";
//testing from a real server:
//private static final String LOGIN_URL = "http://www.yourdomain.com/webservice/login.php";
//JSON element ids from repsonse of php script:
private static final String TAG_SUCCESS = "success";
private static final String TAG_MESSAGE = "message";
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//setup input fields
user = (EditText)findViewById(R.id.editText1);
pass = (EditText)findViewById(R.id.editText2);
//setup buttons
mSubmit = (Button)findViewById(R.id.button1);
//register listeners
mSubmit.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
new AttemptLogin().execute();
}
class AttemptLogin extends AsyncTask<String, String, String> {
/**
* Before starting background thread Show Progress Dialog
* */
boolean failure = false;
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(AnprSdkMain.this);
pDialog.setMessage("Attempting login...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
@Override
protected String doInBackground(String... args) {
// TODO Auto-generated method stub
// Check for success tag
int success;
String username = user.getText().toString();
String password = pass.getText().toString();
try {
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("username", username));
params.add(new BasicNameValuePair("password", password));
Log.d("request!", "starting");
// getting product details by making HTTP request
JSONObject json = jsonParser.makeHttpRequest(
LOGIN_URL, "POST", params);
// check your log for json response
Log.d("Login attempt", json.toString());
success = json.getInt(TAG_SUCCESS);
if (success == 1) {
Log.d("Login Successful!", json.toString());
Intent i = new Intent(AnprSdkMain.this, Lista.class);
finish();
startActivity(i);
return json.getString(TAG_MESSAGE);
}else if(success == 0){
Log.d("Login Failure!", json.toString());
return json.getString(TAG_MESSAGE);
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
/**
* After completing background task Dismiss the progress dialog
* **/
protected void onPostExecute(String file_url) {
// dismiss the dialog once product deleted
pDialog.dismiss();
if (file_url != null){
Toast.makeText(AnprSdkMain.this, file_url, Toast.LENGTH_LONG).show();
}
}
}
}
我做错了什么?因为它可以与emulator一起使用,但不能与tablet一起使用。我试图改变http://10.0.2.2/anpr/webservice/login.php 到http://127.0.0.1/anpr/webservice/login.php 但还是一样。你不能那样做。如果您使用的是wifi网络,请尝试使用路由器提供给设备的IP地址。您的清单还需要internet权限。我有internet权限。如果我想连接在线phpmyadmin服务器,该怎么办?我不能使用IPS你说的在线服务器是什么意思?那么它应该有一个IP地址或者域名,我的意思是把index.php和login.php放在哪里?这是我第一次这样做,请给我一些指导它有一个域名,但不知道把index.php放在哪里,也不知道应该放在什么地方?我不清楚你的疑问。您是否从供应商处购买了自己的服务器?或者您正在本地计算机上运行?您可以将两个php文件放在同一个目录中。