所以我试着制作一个应用程序,将数据发布到我的服务器并查看应用程序中的数据库。
我的数据库中确实有一些条目,所以即使是视图数据库选项也应该向我展示一些信息,但我不会得到我的祝酒词。
catlog是我试图添加数据。这张贴在下面。
我遇到了一些连接问题。但那些都得到了解决。我缺乏java的经验,所以所有的帮助都很受欢迎。
我在这里做错了什么?
这是我的大部分代码:
public class BackgoundTasks extends AsyncTask<String,String,String> {
Context ctx;
BackgoundTasks (Context ctx)
{
this.ctx = ctx;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected String doInBackground(String... params) {
String RegisterURL = "http://10.0.2.2:80freeln/webapp/register.php";
String method = params[0];
if (method.equals("register")) {
String Shipname = params[1];
String manufacturer = params[2];
String price = params[3];
try {
URL url = new URL(RegisterURL);
HttpURLConnection httpConnect = (HttpURLConnection) url.openConnection();
httpConnect.setRequestMethod("POST");
httpConnect.setDoOutput(true);
OutputStream OS = httpConnect.getOutputStream();
BufferedWriter bufferdWriter = new BufferedWriter(new OutputStreamWriter(OS, "UTF-8"));
// send info to server
Toast.makeText(ctx, "Sending data ...", Toast.LENGTH_SHORT).show();
String data = URLEncoder.encode("Shipname", "UTF-8") + "=" + URLEncoder.encode(Shipname, "UTF-8") + "&" +
URLEncoder.encode("manufacturer", "UTF-8") + "=" + URLEncoder.encode(manufacturer, "UTF-8") + "&" +
URLEncoder.encode("price", "UTF-8") + "=" + URLEncoder.encode(price, "UTF-8");
bufferdWriter.write(data);
bufferdWriter.flush();
bufferdWriter.close();
OS.close();
InputStream IS = httpConnect.getInputStream();
IS.close();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return "Ship added";
}else if (method.equals("RequestDB") ) {
URL url;
try {
url = new URL("http://10.0.2.2:80/webapp/login.php");
HttpURLConnection urlConnection = (HttpURLConnection) url
.openConnection();
InputStream in = urlConnection.getInputStream();
InputStreamReader isw = new InputStreamReader(in);
int data = isw.read();
while (data != -1) {
char current = (char) data;
data = isw.read();
System.out.print(current);
Toast.makeText(ctx, current, Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return null;
}
@Override
protected void onProgressUpdate(String... values) {
}
@Override
protected void onPostExecute(String result) {
if (result != null)
Toast.makeText(ctx,result,Toast.LENGTH_LONG).show();
}
}
这是我的catlog:
0-16 21:01:05.214 7136-7142/com.example.simon.myapplication W/art: Suspending all threads took: 23.267ms
10-16 21:01:05.960 7136-7302/com.example.simon.myapplication D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
[ 10-16 21:01:06.016 7136: 7136 D/ ]
HostConnection::get() New Host Connection established 0xabc83928, tid 7136
[ 10-16 21:01:06.018 7136: 7136 W/ ]
Unrecognized GLES max version string in extensions: ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_dma_v1
10-16 21:01:06.666 7136-7302/com.example.simon.myapplication I/OpenGLRenderer: Initialized EGL, version 1.4
10-16 21:01:06.669 7136-7302/com.example.simon.myapplication W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
10-16 21:01:06.677 7136-7302/com.example.simon.myapplication D/EGL_emulation: eglCreateContext: 0xab21d620: maj 2 min 0 rcv 2
10-16 21:01:06.696 7136-7302/com.example.simon.myapplication D/EGL_emulation: eglMakeCurrent: 0xab21d620: ver 2 0 (tinfo 0xabb79620)
10-16 21:01:06.816 7136-7302/com.example.simon.myapplication D/EGL_emulation: eglMakeCurrent: 0xab21d620: ver 2 0 (tinfo 0xabb79620)
10-16 21:01:07.203 7136-7142/com.example.simon.myapplication W/art: Suspending all threads took: 10.419ms
10-16 21:01:07.484 7136-7136/com.example.simon.myapplication W/art: Before Android 4.1, method int android.support.v7.widget.ListViewCompat.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView
10-16 21:01:07.535 7136-7136/com.example.simon.myapplication I/Choreographer: Skipped 85 frames! The application may be doing too much work on its main thread.
10-16 21:01:08.246 7136-7136/com.example.simon.myapplication I/Choreographer: Skipped 42 frames! The application may be doing too much work on its main thread.
10-16 21:01:08.810 7136-7136/com.example.simon.myapplication I/Choreographer: Skipped 33 frames! The application may be doing too much work on its main thread.
10-16 21:01:22.819 7136-7142/com.example.simon.myapplication W/art: Suspending all threads took: 85.426ms
10-16 21:01:23.745 7136-7142/com.example.simon.myapplication W/art: Suspending all threads took: 9.830ms
10-16 21:01:24.243 7136-7142/com.example.simon.myapplication W/art: Suspending all threads took: 9.550ms
10-16 21:01:27.765 7136-7142/com.example.simon.myapplication W/art: Suspending all threads took: 20.642ms
10-16 21:01:35.680 7136-7136/com.example.simon.myapplication W/IInputConnectionWrapper: endBatchEdit on inactive InputConnection
10-16 21:01:39.939 7136-7142/com.example.simon.myapplication W/art: Suspending all threads took: 168.810ms
10-16 21:01:39.989 7136-7136/com.example.simon.myapplication W/IInputConnectionWrapper: finishComposingText on inactive InputConnection
10-16 21:01:40.217 7136-7146/com.example.simon.myapplication I/art: Background sticky concurrent mark sweep GC freed 9541(991KB) AllocSpace objects, 0(0B) LOS objects, 60% free, 1465KB/3MB, paused 10.235ms total 549.182ms
10-16 21:01:40.245 7136-7146/com.example.simon.myapplication W/art: Suspending all threads took: 25.713ms
10-16 21:01:40.785 7136-7142/com.example.simon.myapplication W/art: Suspending all threads took: 11.561ms
10-16 21:01:43.346 7136-7142/com.example.simon.myapplication W/art: Suspending all threads took: 65.096ms
10-16 21:26:11.037 7136-7142/com.example.simon.myapplication W/art: Suspending all threads took: 18.749ms
10-16 21:36:08.508 7136-7142/com.example.simon.myapplication W/art: Suspending all threads took: 21.113ms