私はこれまでのところ、以下に書かれたことを達成しました..JSOnを使用してデータベースから値を取得し、印刷したい.....しかし、いくつかのエラーが発生しました..あなたの助けを待っています...
package com.yipl.Googlemaps;
import android.app.Activity;
import android.os.Bundle;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
//import java.util.ArrayList;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
//import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
//import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
//import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.util.Log;
public class GoogleMapsActivity extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String result = "";
InputStream is = null;
try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://10.0.2.2/example/request.php");
// httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
}catch(Exception e){
Log.e("log_tag", "Error in http connection "+e.toString());
}
//convert response to string
try{
BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
result=sb.toString();
}catch(Exception e){
Log.e("log_tag", "Error converting result "+e.toString());
}
//parse JSON data
try{
JSONArray jArray = new JSONArray(result);
for(int i=0;i<jArray.length();i++){
JSONObject json_data = jArray.getJSONObject(i);
Log.i("log_tag","id: "+json_data.getInt("id")+
", name: "+json_data.getString("name")+
", CHD: "+json_data.getString("CHD")+
", VDCs: "+json_data.getString("vdcs")+
", Children Vaccinated: "+json_data.getString("Vchildren")+
", Total: "+json_data.getString("total")+
", Latitude: "+json_data.getDouble("lat")+
", Longitude: "+json_data.getDouble("lng")
);
}
}catch(JSONException e){
Log.e("log_tag", "Error parsing data "+e.toString());
}
}
}
サービスコード.....
<?php
mysql_connect("localhost","root","");
mysql_select_db("niporg");
$q=mysql_query("select n.id, n.name, i.CHD, i.vdcs, i.Vchildren, i.total, l.lat, l.lng from info as i, nip_db as n, location as l where n.id=i.id and i.id = l.id");
while($e=mysql_fetch_array($q))
{
$output[]=$e;
}
print(json_encode($output));
mysql_close();
?>
しかし、私はエラーが発生しています..以下のように..
> 06-19 15:45:00.595: I/jdwp(267): received file descriptor 10 from ADB
> 06-19 15:45:00.635: D/ddm-heap(267): Got feature list request 06-19
> 15:45:00.815: D/AndroidRuntime(267): Shutting down VM 06-19
> 15:45:00.815: W/dalvikvm(267): threadid=3: thread exiting with
> uncaught exception (group=0x4001aa28) 06-19 15:45:00.815:
> E/AndroidRuntime(267): Uncaught handler: thread main exiting due to
> uncaught exception 06-19 15:45:00.835: E/AndroidRuntime(267):
> java.lang.RuntimeException: Unable to start activity
> ComponentInfo{com.yipl.Googlemaps/com.yipl.Googlemaps.GoogleMapsActivity}:
> android.view.InflateException: Binary XML file line #7: Error
> inflating class java.lang.reflect.Constructor 06-19 15:45:00.835:
> E/AndroidRuntime(267): at
> android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2401)
> 06-19 15:45:00.835: E/AndroidRuntime(267): at
> android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2417)
> 06-19 15:45:00.835: E/AndroidRuntime(267): at
> android.app.ActivityThread.access$2100(ActivityThread.java:116) 06-19
> 15:45:00.835: E/AndroidRuntime(267): at
> android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
> 06-19 15:45:00.835: E/AndroidRuntime(267): at
> android.os.Handler.dispatchMessage(Handler.java:99) 06-19
> 15:45:00.835: E/AndroidRuntime(267): at
> android.os.Looper.loop(Looper.java:123) 06-19 15:45:00.835:
> E/AndroidRuntime(267): at
> android.app.ActivityThread.main(ActivityThread.java:4203) 06-19
> 15:45:00.835: E/AndroidRuntime(267): at
> java.lang.reflect.Method.invokeNative(Native Method) 06-19
> 15:45:00.835: E/AndroidRuntime(267): at
> java.lang.reflect.Method.invoke(Method.java:521) 06-19 15:45:00.835:
> E/AndroidRuntime(267): at
> com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
> 06-19 15:45:00.835: E/AndroidRuntime(267): at
> com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549) 06-19
> 15:45:00.835: E/AndroidRuntime(267): at
> dalvik.system.NativeStart.main(Native Method) 06-19 15:45:00.835:
> E/AndroidRuntime(267): Caused by: android.view.InflateException:
> Binary XML file line #7: Error inflating class
> java.lang.reflect.Constructor 06-19 15:45:00.835:
> E/AndroidRuntime(267): at
> android.view.LayoutInflater.createView(LayoutInflater.java:512) 06-19
> 15:45:00.835: E/AndroidRuntime(267): at
> android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:564)
> 06-19 15:45:00.835: E/AndroidRuntime(267): at
> android.view.LayoutInflater.rInflate(LayoutInflater.java:617) 06-19
> 15:45:00.835: E/AndroidRuntime(267): at
> android.view.LayoutInflater.inflate(LayoutInflater.java:407) 06-19
> 15:45:00.835: E/AndroidRuntime(267): at
> android.view.LayoutInflater.inflate(LayoutInflater.java:320) 06-19
> 15:45:00.835: E/AndroidRuntime(267): at
> android.view.LayoutInflater.inflate(LayoutInflater.java:276) 06-19
> 15:45:00.835: E/AndroidRuntime(267): at
> com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:313)
> 06-19 15:45:00.835: E/AndroidRuntime(267): at
> android.app.Activity.setContentView(Activity.java:1620) 06-19
> 15:45:00.835: E/AndroidRuntime(267): at
> com.yipl.Googlemaps.GoogleMapsActivity.onCreate(GoogleMapsActivity.java:35)
> 06-19 15:45:00.835: E/AndroidRuntime(267): at
> android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
> 06-19 15:45:00.835: E/AndroidRuntime(267): at
> android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2364)
> 06-19 15:45:00.835: E/AndroidRuntime(267): ... 11 more 06-19
> 15:45:00.835: E/AndroidRuntime(267): Caused by:
> java.lang.reflect.InvocationTargetException 06-19 15:45:00.835:
> E/AndroidRuntime(267): at
> com.google.android.maps.MapView.<init>(MapView.java:237) 06-19
> 15:45:00.835: E/AndroidRuntime(267): at
> java.lang.reflect.Constructor.constructNative(Native Method) 06-19
> 15:45:00.835: E/AndroidRuntime(267): at
> java.lang.reflect.Constructor.newInstance(Constructor.java:446) 06-19
> 15:45:00.835: E/AndroidRuntime(267): at
> android.view.LayoutInflater.createView(LayoutInflater.java:499) 06-19
> 15:45:00.835: E/AndroidRuntime(267): ... 21 more 06-19 15:45:00.835:
> E/AndroidRuntime(267): Caused by: java.lang.IllegalArgumentException:
> MapViews can only be created inside instances of MapActivity. 06-19
> 15:45:00.835: E/AndroidRuntime(267): at
> com.google.android.maps.MapView.<init>(MapView.java:281) 06-19
> 15:45:00.835: E/AndroidRuntime(267): at
> com.google.android.maps.MapView.<init>(MapView.java:254) 06-19
> 15:45:00.835: E/AndroidRuntime(267): ... 25 more 06-19 15:45:00.855:
> I/dalvikvm(267): threadid=7: reacting to signal 3 06-19 15:45:00.855:
> E/dalvikvm(267): Unable to open stack trace file
> '/data/anr/traces.txt': Permission denied