私はこの機能を持っています:
public static String getXML(int id, int choose, int foo){
String line = null;
try {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = null;
if(id == 100)
{
httpPost = new HttpPost("http://andronekat.com/sawalef/logFollow.php?id="+ foo + "");
}
else if(id == 20)
{
httpPost = new HttpPost("http://andronekat.com/sawalef/logMyTimeLine.php?id="+ foo + "");
}
else if(id == 19)
{
httpPost = new HttpPost("http://andronekat.com/sawalef/logMyEntity.php?id="+ foo + "");
}
else if(choose == 1)
{
httpPost = new HttpPost("http://andronekat.com/sawalef/log.php?id="+ id + "");
}
else if(choose == 2)
httpPost = new HttpPost("http://andronekat.com/sawalef/log2.php?id="+ id + "");
else if(choose == 3)
httpPost = new HttpPost("http://andronekat.com/sawalef/comments.php?tag="+ id + "");
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
line = EntityUtils.toString(httpEntity, "UTF-8");
}
次の最初の ULR を除いて、すべての文字列 URL は正常に機能します。
if(id == 100)
{
httpPost = new HttpPost("http://andronekat.com/sawalef/logFollow.php?id="+ foo + "");
}
この行に java.lang.NullPointerException が表示されます
HttpResponse httpResponse = httpClient.execute(httpPost);
どこからnullを取得したのかわかりません。リンクをブラウザに入れると、リンクは正常に機能します。誰でも私を助けてもらえますか?
ログキャット:
04-28 09:37:34.500: E/AndroidRuntime(21842): FATAL EXCEPTION: main
04-28 09:37:34.500: E/AndroidRuntime(21842): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.softshell.sowalef/com.softshell.sowalef.Follow}: java.lang.NullPointerException
04-28 09:37:34.500: E/AndroidRuntime(21842): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100)
04-28 09:37:34.500: E/AndroidRuntime(21842): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
04-28 09:37:34.500: E/AndroidRuntime(21842): at android.app.ActivityThread.access$600(ActivityThread.java:140)
04-28 09:37:34.500: E/AndroidRuntime(21842): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
04-28 09:37:34.500: E/AndroidRuntime(21842): at android.os.Handler.dispatchMessage(Handler.java:99)
04-28 09:37:34.500: E/AndroidRuntime(21842): at android.os.Looper.loop(Looper.java:137)
04-28 09:37:34.500: E/AndroidRuntime(21842): at android.app.ActivityThread.main(ActivityThread.java:4898)
04-28 09:37:34.500: E/AndroidRuntime(21842): at java.lang.reflect.Method.invokeNative(Native Method)
04-28 09:37:34.500: E/AndroidRuntime(21842): at java.lang.reflect.Method.invoke(Method.java:511)
04-28 09:37:34.500: E/AndroidRuntime(21842): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1008)
04-28 09:37:34.500: E/AndroidRuntime(21842): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:775)
04-28 09:37:34.500: E/AndroidRuntime(21842): at dalvik.system.NativeStart.main(Native Method)
04-28 09:37:34.500: E/AndroidRuntime(21842): Caused by: java.lang.NullPointerException
04-28 09:37:34.500: E/AndroidRuntime(21842): at com.softshell.sowalef.Follow.onCreate(Follow.java:71)
04-28 09:37:34.500: E/AndroidRuntime(21842): at android.app.Activity.performCreate(Activity.java:5206)
04-28 09:37:34.500: E/AndroidRuntime(21842): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
04-28 09:37:34.500: E/AndroidRuntime(21842): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
04-28 09:37:34.500: E/AndroidRuntime(21842): ... 11 more