だから私はアプリを作っていて、インターネット http://www.arleitiss.netne.net/DBindex.php?action=fetchTransからクエリのリストを取得 して実行するアプリが必要です。電話でテストしてもエラーは表示されませんが、AVDでnullpointerがスローされます。
package com.example.droid;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import android.content.Context;
import android.util.Log;
public class OnlineSync {
Context context;
public OnlineSync(Context context){
this.context = context;
}
public boolean AddUser(String username, String pass, String name, String city, String country, String age){
HttpClient http = new DefaultHttpClient();
HttpPost httpp = new HttpPost("http://www.arleitiss.netne.net/DBindex.php");
boolean result = false;
try{
List<NameValuePair> nvp = new ArrayList<NameValuePair>(6);
nvp.add(new BasicNameValuePair("action", "adduser"));
nvp.add(new BasicNameValuePair("username", username));
nvp.add(new BasicNameValuePair("password", pass));
nvp.add(new BasicNameValuePair("name", name));
nvp.add(new BasicNameValuePair("city", city));
nvp.add(new BasicNameValuePair("country", country));
nvp.add(new BasicNameValuePair("age", String.valueOf(age)));
httpp.setEntity(new UrlEncodedFormEntity(nvp));
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String response = http.execute(httpp, responseHandler);
Log.d("RESPONSE", response);
if(response.toString().equals("ERROR1")){
result = true;
}
else if(response.toString().equals("ERROR-1")){
result = false;
}
}
catch(ClientProtocolException e){result = false;}
catch(IOException e){result = false;}
return result;
}
public String[] SyncTrans(){
BufferedReader in = null;
String data = null;
try{
HttpClient client = new DefaultHttpClient();
URI website = new URI("http://www.arleitiss.netne.net/DBindex.php?action=fetchTrans");
HttpGet request = new HttpGet();
request.setURI(website);
HttpResponse response = client.execute(request);
in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
StringBuffer sb = new StringBuffer("");
String l = "";
String nl = System.getProperty("line.seperator");
while(( l = in.readLine()) != null){
sb.append(l + nl);
}
in.close();
data = sb.toString();
String arr[] = data.split("<br>");
return arr;
}
catch(Exception e){}
return null;
}
public void Exec(){
DbCon dc = new DbCon(this.context);
String queries[] = SyncTrans();
for(int a = 0; a < queries.length-1; a++){
dc.ExecQuery(queries[a]);
Log.d("TAGG",queries[a].toString());
}
}
}
データベースには単純な機能があります:
public void ExecQuery(String query){
DbCon.this.open();
database.rawQuery(query, null);
DbCon.this.close();
}
ヘルプ?
LogCat:
04-22 02:36:42.648: E/AndroidRuntime(5983): 致命的な例外: メイン 04-22 02:36:42.648: E/AndroidRuntime(5983): java.lang.RuntimeException: アクティビティ ComponentInfo{com を開始できません。 example.droid/com.example.droid.Incomes_act}: java.lang.NullPointerException 04-22 02:36:42.648: E/AndroidRuntime(5983): android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180) で 04 -22 02:36:42.648: E/AndroidRuntime(5983): android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230) 04-22 02:36:42.648: E/AndroidRuntime(5983): android.app で.ActivityThread.access$600(ActivityThread.java:141) 04-22 02:36:42.648: E/AndroidRuntime(5983): android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234) 04-22 02: 36:42.648: E/AndroidRuntime(5983): android.os.Handler.dispatchMessage(Handler.java:99) 04-22 02:36:42.648: E/AndroidRuntime(5983): android.os.Looper.loop(Looper.java:137) 04-22 02:36:42.648: E/AndroidRuntime(5983) : android.app.ActivityThread.main(ActivityThread.java:5039) 04-22 02:36:42.648: E/AndroidRuntime(5983): java.lang.reflect.Method.invokeNative(ネイティブ メソッド) 04-22 02 :36:42.648: E/AndroidRuntime(5983): java.lang.reflect.Method.invoke(Method.java:511) 04-22 02:36:42.648: E/AndroidRuntime(5983): com.android. internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 04-22 02:36:42.648: E/AndroidRuntime(5983): com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) ) 04-22 02:36:42.648: E/AndroidRuntime(5983): dalvik.system.NativeStart.main(ネイティブ メソッド) 04-22 02:36:42.648: E/AndroidRuntime(5983): 原因: java.言語NullPointerException 04-22 02:36:42.648: E/AndroidRuntime(5983): com.example.droid.OnlineSync.Exec(OnlineSync.java:89) 04-22 02:36:42.648: E/AndroidRuntime(5983): com.example.droid.Incomes_act.onCreate(Incomes_act.java:88) 04-22 02:36:42.648: E/AndroidRuntime(5983): android.app.Activity.performCreate(Activity.java:5104) 04- 22 02:36:42.648: E/AndroidRuntime(5983): android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080) 04-22 02:36:42.648: E/AndroidRuntime(5983): android.app. ActivityThread.performLaunchActivity(ActivityThread.java:2144) 04-22 02:36:42.648: E/AndroidRuntime(5983): ... 11 もっと見るIncomes_act.onCreate(Incomes_act.java:88) 04-22 02:36:42.648: E/AndroidRuntime(5983): android.app.Activity.performCreate(Activity.java:5104) 04-22 02:36:42.648: E/AndroidRuntime(5983): android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080) 04-22 02:36:42.648: E/AndroidRuntime(5983): android.app.ActivityThread.performLaunchActivity(ActivityThread.java) :2144) 04-22 02:36:42.648: E/AndroidRuntime(5983): ... 11 もっと見るIncomes_act.onCreate(Incomes_act.java:88) 04-22 02:36:42.648: E/AndroidRuntime(5983): android.app.Activity.performCreate(Activity.java:5104) 04-22 02:36:42.648: E/AndroidRuntime(5983): android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080) 04-22 02:36:42.648: E/AndroidRuntime(5983): android.app.ActivityThread.performLaunchActivity(ActivityThread.java) :2144) 04-22 02:36:42.648: E/AndroidRuntime(5983): ... 11 もっと見るperformLaunchActivity(ActivityThread.java:2144) 04-22 02:36:42.648: E/AndroidRuntime(5983): ... 11 もっと見るperformLaunchActivity(ActivityThread.java:2144) 04-22 02:36:42.648: E/AndroidRuntime(5983): ... 11 もっと見る
別の logcat ログ #2:
04-22 13:55:48.304: E/AndroidRuntime(933): 致命的な例外: メイン 04-22 13:55:48.304: E/AndroidRuntime(933): java.lang.RuntimeException: アクティビティ ComponentInfo{com を開始できません。 example.droid/com.example.droid.Incomes_act}: java.lang.NullPointerException 04-22 13:55:48.304: E/AndroidRuntime(933): android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059) で 04 -22 13:55:48.304: E/AndroidRuntime(933): android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084) 04-22 13:55:48.304: E/AndroidRuntime(933): android.app で.ActivityThread.access$600(ActivityThread.java:130) 04-22 13:55:48.304: E/AndroidRuntime(933): android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195) 04-22 13: 55:48.304: E/AndroidRuntime(933): android.os.Handler.dispatchMessage(Handler.java:99) 04-22 13:55:48.304: E/AndroidRuntime(933): android.os.Looper.loop(Looper.java:137) 04-22 13:55:48.304: E/AndroidRuntime(933): at android.app.ActivityThread.main(ActivityThread.java:4745) 04-22 13:55:48.304: E/AndroidRuntime(933): java.lang.reflect.Method.invokeNative(ネイティブ メソッド) 04-22 13:55 で:48.304: E/AndroidRuntime(933): java.lang.reflect.Method.invoke(Method.java:511) 04-22 13:55:48.304: E/AndroidRuntime(933): com.android.internal. os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 04-22 13:55:48.304: E/AndroidRuntime(933): com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 04 -22 13:55:48.304: E/AndroidRuntime(933): dalvik.system.NativeStart.main(ネイティブ メソッド) 04-22 13:55:48.304: E/AndroidRuntime(933): 原因: java.lang. NullPointerException 04-22 13:55:48。304: E/AndroidRuntime(933): com.example.droid.OnlineSync.Exec(OnlineSync.java:92) 04-22 13:55:48.304: E/AndroidRuntime(933): com.example.droid.Incomes_act で.onCreate(Incomes_act.java:88) 04-22 13:55:48.304: E/AndroidRuntime(933): android.app.Activity.performCreate(Activity.java:5008) 04-22 13:55:48.304: E /AndroidRuntime(933): android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079) 04-22 13:55:48.304: E/AndroidRuntime(933): android.app.ActivityThread.performLaunchActivity(ActivityThread.java: 2023年)5008) 04-22 13:55:48.304: E/AndroidRuntime(933): android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079) 04-22 13:55:48.304: E/AndroidRuntime(933): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)5008) 04-22 13:55:48.304: E/AndroidRuntime(933): android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079) 04-22 13:55:48.304: E/AndroidRuntime(933): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
作成されたスレッド:
String arr[];
Thread trd = new Thread(new Runnable(){
@Override
public void run(){
BufferedReader in = null;
String data = null;
try{
final HttpClient client = new DefaultHttpClient();
URI website = new URI("http://www.arleitiss.netne.net/DBindex.php?action=fetchTrans");
final HttpGet request = new HttpGet();
request.setURI(website);
HttpResponse response = client.execute(request);
in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
StringBuffer sb = new StringBuffer("");
String l = "";
String nl = System.getProperty("line.seperator");
while(( l = in.readLine()) != null){
sb.append(l + nl);
}
in.close();
data = sb.toString();
String arr2[] = data.split("<br>");
arr = arr2;
}
catch(Exception e){
e.printStackTrace();
return;
}
}
});