API Level

  • Antworten:0
Christian Keusch
  • Forum-Beiträge: 14

31.07.2013, 11:45:22 via Website

Hallo,
ich habe ein kleines Programm mit einer Google Maps Karte programmiert und dafür MapFragment benutzt welche ein API Level von mindestens 11 voraussetzt. Nun wollte ich die Sache mit einer Datenbank verbinden und habe folgenden Code eingesetzt:

1// mysql abfrage start
2 intent1 = getIntent();
3 HttpClient httpclient = new DefaultHttpClient();
4 HttpPost httppost = new HttpPost(
5 "MEINESEITE/test.php?projekt="
6 + intent1.getStringExtra("projekt"));
7 //TextView textView = (TextView) findViewById(R.id.json_text);
8 JSONObject json_data;
9 InputStream is;
10 String jsonResult = null;
11 try {
12 HttpResponse response = httpclient.execute(httppost);
13 HttpEntity entity = response.getEntity();
14 is = entity.getContent();
15 String rLine = "";
16 StringBuilder answer = new StringBuilder();
17 BufferedReader rd = new BufferedReader(new InputStreamReader(is));
18
19
20 while ((rLine = rd.readLine()) != null) {
21 answer.append(rLine + "\n");
22 }
23 is.close();
24
25 jsonResult = answer.toString();
26
27 // String jsonResult =
28 // inputStreamToString(response.getEntity().getContent()).toString();
29 // textView.setText(jsonResult);
30
31 JSONArray jArray = new JSONArray(jsonResult);
32
33 for (int i = 0; i < jArray.length(); i++) {
34 json_data = jArray.getJSONObject(i);
35
36 String proj1 = json_data.getString("proj");
37 String koord1 = json_data.getString("koord");
38 String beschr1 = json_data.getString("beschr");
39 String typ1 = json_data.getString("typ");
40 String titel1 = json_data.getString("titel");
41
42 String[] koord_split = koord1.split(",");
43 String lat1 = koord_split[0];
44 String long1 = koord_split[1];
45 double lat2 = Double.parseDouble(lat1);
46 double long2 = Double.parseDouble(long1);
47
48 //Toast.makeText(this, lat1 + "-" + long1, RESULT_OK).show();
49
50 //Toast.makeText(this, beschr1, RESULT_OK).show();
51
52
53 if (typ1.equals("start")){
54 myMap.addMarker(new MarkerOptions()
55 .position(
56 new LatLng(lat2, long2))
57
58 .icon(start).title(titel1).snippet(beschr1));
59
60 CameraPosition cameraPosition = new CameraPosition.Builder()
61 .target(new LatLng(lat2, long2)).zoom(17.0f).build();
62 CameraUpdate cameraUpdate = CameraUpdateFactory
63 .newCameraPosition(cameraPosition);
64 myMap.moveCamera(cameraUpdate);
65
66
67 }
68
69 else if (typ1.equals("pflanze")){
70 myMap.addMarker(new MarkerOptions()
71 .position(
72 new LatLng(lat2, long2))
73
74 .icon(pflanze).title(titel1).snippet(beschr1));
75 }
76 else if (typ1.equals("biotop")){
77 myMap.addMarker(new MarkerOptions()
78 .position(
79 new LatLng(lat2, long2))
80
81 .icon(biotop).title(titel1).snippet(beschr1));
82 }
83 else if (typ1.equals("sehenswuerdigkeit")){
84 myMap.addMarker(new MarkerOptions()
85 .position(
86 new LatLng(lat2, long2))
87
88 .icon(schild).title(titel1).snippet(beschr1));
89 }
90
91 }
92 } catch (JSONException e) {
93 e.printStackTrace();
94 } catch (ClientProtocolException e) {
95 e.printStackTrace();
96 } catch (IOException e) {
97 e.printStackTrace();
98 }
99
100 // mysql abfrage ende


Es funktioniert auch alles recht gut aber nur wenn ich im Manifest android:targetSdkVersion="9" eingebe ab API-Level 10 bricht das Programm sofort ab.

Hat wer eine Ahnung was sich bei meinem Code nicht mit einem höheren Level verträgt??

LG, Christian.

Antworten