Rackor
- Forum-Beiträge: 19
13.10.2013, 15:27:32 via Website
13.10.2013 15:27:32 via Website
in my app there is a part where i am searching dynamically for user..when i find some i send a hashmap with the userID to a asynctask to get their profildata(String and bitmap)
First i get the userData(Name etc.)..then i get here(start of the code that is shown here) the Urls from the Pictures stored on a webserver...when i have the URLs i save them in an Array and use this Array to get the Pictures. There I use a "for-loop" to get every single Picture..in Addition i want to save all the Bitmaps in an Array and return this Array together with my string(userdata) Array... but i cant store the Bitmaps in an Array, arraylist, or hashmap...everytime this variables return null...when i initialized the variables in the method i got a warning: "nullpointer Access, this varaible only can return null at this Point"...this warning was gone when i initialized the variable in the class head...but the Problem is still there..
what will be the Problem? did i do anything wrong??
First i get the userData(Name etc.)..then i get here(start of the code that is shown here) the Urls from the Pictures stored on a webserver...when i have the URLs i save them in an Array and use this Array to get the Pictures. There I use a "for-loop" to get every single Picture..in Addition i want to save all the Bitmaps in an Array and return this Array together with my string(userdata) Array... but i cant store the Bitmaps in an Array, arraylist, or hashmap...everytime this variables return null...when i initialized the variables in the method i got a warning: "nullpointer Access, this varaible only can return null at this Point"...this warning was gone when i initialized the variable in the class head...but the Problem is still there..
what will be the Problem? did i do anything wrong??
1try{
2 ArrayList<NameValuePair> nameValuePair = new ArrayList<NameValuePair>();
3 Iterator<String> it = btID.keySet().iterator();
4 while(it.hasNext()){
5 String key = it.next();
6 nameValuePair.add(new BasicNameValuePair
7 (key,btID.get(key)));
8 }
9 DefaultHttpClient httpclient = new DefaultHttpClient();
10 HttpPost httppost = new HttpPost(url1);
11 httppost.setEntity(new UrlEncodedFormEntity(nameValuePair));
12 HttpResponse response = httpclient.execute(httppost);
13 HttpEntity entity = response.getEntity();
14 is = entity.getContent();
15
16 }catch(Exception e){
17 Log.e("log_tag", "Fehler bei der http-Verbindung" +
18 e.toString());
19 }
20
21 try{
22 BufferedReader reader= new BufferedReader
23 (new InputStreamReader(is,"iso-8859-1"),8);
24 StringBuilder sb = new StringBuilder();
25 String line = null;
26 while ((line = reader.readLine()) !=null) {
27 sb.append(line);
28 }
29 is.close();
30 result_picUrl = sb.toString();
31 urls = result_picUrl.toString().split(",");
32
33 }catch(Exception e){
34 Log.e("log_tag", "Error converting result " + e.toString());
35 }
36
37 //for(int i=0; i<urls.length; i++){
38 try {
39 InputStream in = new java.net.URL(urls[0]).openStream();
40 result = BitmapFactory.decodeStream(in);
41 } catch (Exception e) {
42 Log.e("Error", e.getMessage());
43 e.printStackTrace();
44 }
45 // HERE is the Problem!!
46 try{
47 bitmap.put("pic", result);
48 }catch(Exception e){
49 Log.e("log_tag", e.toString());
50 }
51 //}
52
53 BitString bitstring = new BitString(result_data, result_pic);
2 ArrayList<NameValuePair> nameValuePair = new ArrayList<NameValuePair>();
3 Iterator<String> it = btID.keySet().iterator();
4 while(it.hasNext()){
5 String key = it.next();
6 nameValuePair.add(new BasicNameValuePair
7 (key,btID.get(key)));
8 }
9 DefaultHttpClient httpclient = new DefaultHttpClient();
10 HttpPost httppost = new HttpPost(url1);
11 httppost.setEntity(new UrlEncodedFormEntity(nameValuePair));
12 HttpResponse response = httpclient.execute(httppost);
13 HttpEntity entity = response.getEntity();
14 is = entity.getContent();
15
16 }catch(Exception e){
17 Log.e("log_tag", "Fehler bei der http-Verbindung" +
18 e.toString());
19 }
20
21 try{
22 BufferedReader reader= new BufferedReader
23 (new InputStreamReader(is,"iso-8859-1"),8);
24 StringBuilder sb = new StringBuilder();
25 String line = null;
26 while ((line = reader.readLine()) !=null) {
27 sb.append(line);
28 }
29 is.close();
30 result_picUrl = sb.toString();
31 urls = result_picUrl.toString().split(",");
32
33 }catch(Exception e){
34 Log.e("log_tag", "Error converting result " + e.toString());
35 }
36
37 //for(int i=0; i<urls.length; i++){
38 try {
39 InputStream in = new java.net.URL(urls[0]).openStream();
40 result = BitmapFactory.decodeStream(in);
41 } catch (Exception e) {
42 Log.e("Error", e.getMessage());
43 e.printStackTrace();
44 }
45 // HERE is the Problem!!
46 try{
47 bitmap.put("pic", result);
48 }catch(Exception e){
49 Log.e("log_tag", e.toString());
50 }
51 //}
52
53 BitString bitstring = new BitString(result_data, result_pic);
Empfohlener redaktioneller Inhalt
Mit Deiner Zustimmung wird hier ein externer Inhalt geladen.
Mit Klick auf den oben stehenden Button erklärst Du Dich damit einverstanden, dass Dir externe Inhalte angezeigt werden dürfen. Dabei können personenbezogene Daten an Drittanbieter übermittelt werden. Mehr Infos dazu findest Du in unserer Datenschutzerklärung.