Hello, I have a map view in my android application and the map has overlays showing the events at a location, when i tap on the balloon overlay, it should take to the event details which is another activity in the application. there are few events which is shown in a list and each list item shows the description of the event when clicked/selected. I am trying to call the event by sending the indices of the map overlays. i.e. if i click the map overlay with index i should open the description of the corresponding event with the same index in the event list. the indices are passed through intents and are received in the required activity. But when i use the index for the method required to display the event details i get null pointer exception. I'll post the code which is used to display the event list and event details. and will post logcat too. Please have a review of the code and let me know where i may have gone wrong and what needs to be done.
Thank you. P.S. my code and log cat below _____________________________________________________________________________ // my overlay public void onBalloonTap(int index, Item item) { Intent i = new Intent(c,FestivalEvents.class); i.putExtra("index", index); event.setUpDesc(index); c.startActivity(i); } // events activity public class FestivalEvents extends Activity{ private ListView SearchListView; private ArrayList<ParsedData> items = new ArrayList<ParsedData>(); private RelativeLayout fv; private TextView tv1; private TextView tv2; private TextView tv3; private TextView date1; private ImageButton twitter; private ImageButton facebook; private ImageButton back; private ImageButton home; private boolean mCheckView; private SearchListAdapter aa; private String nameOFFile; private TextView title; private ImageView arrowImgRight; private ImageView arrowImgLeft; private String channelStr; int bkp_position = 0; private ImageView imLink; private ImageView imageLink; ImageView banner_img; ImageView banner_imge; private static Context mContext; private final int BANNER_TIME = 3000; private final int BANNER_MSG = 1; private int banner_index = 0; private int[] mImages_banner = { R.drawable.banner, R.drawable.banner1, R.drawable.banner2, R.drawable.banner3 }; private Handler mHandler = new Handler() { public void handleMessage(Message msg) { switch (msg.what) { case BANNER_MSG: { if(banner_index > 3) banner_index = 0; banner_imge.setImageResource(mImages_banner[banner_index]); banner_index++; mHandler.sendEmptyMessageDelayed(BANNER_MSG,BANNER_TIME); break; } default: super.handleMessage(msg); } } }; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.festivalevents1); Bundle extras = getIntent().getExtras(); // int index = extras.getInt("index"); // setUpDesc(index); SearchListView = (ListView)this.findViewById(R.id.searchListView); banner_imge = (ImageView) findViewById(R.id.imageView3); banner_imge.setOnClickListener(new OnClickListener() { public void onClick(View arg0) { Log.i("BedFordApp", "Banner clicked"); if(mContext == null) { Log.i("BedFordApp", " context null"); // return ; } Intent i = new Intent(FestivalEvents.this, Sponsors.class); i.putExtra("Name", "FestivalSponsors"); i.putExtra("title", "title"); Log.i("FestivalEvents", "Banner clicked"); switch(banner_index) { case 1: i.putExtra("banner", 1); break; case 2: i.putExtra("banner", 2); break; case 3: i.putExtra("banner", 3); break; case 4: i.putExtra("banner", 4); break; } FestivalEvents.this.startActivity(i); } }); mHandler.sendEmptyMessageDelayed(BANNER_MSG,BANNER_TIME); //SearchListView.setse fv = (RelativeLayout)this.findViewById(R.id.fullview); tv1 = (TextView)this.findViewById(R.id.titel); tv2 = (TextView)this.findViewById(R.id.desc); tv2.setMovementMethod(new ScrollingMovementMethod()); tv3 = (TextView)this.findViewById(R.id.link); date1 = (TextView)this.findViewById(R.id.date1); imLink = (ImageView)this.findViewById(R.id.imgLink); arrowImgRight = (ImageView) this.findViewById(R.id.arwimgright); arrowImgRight.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { System.out.println(bkp_position); if(bkp_position <= nodeLength) { bkp_position = bkp_position+1; setUpDesc(bkp_position); visibility_arrow_postion(); //visibility_left_arrow_postion(); }else { bkp_position =0; } } }); arrowImgLeft = (ImageView) this.findViewById(R.id.arwimgleft); arrowImgLeft.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if(bkp_position >= 0) { bkp_position = bkp_position-1; setUpDesc(bkp_position); //visibility_left_arrow_postion(); visibility_arrow_postion(); }else{ bkp_position =nodeLength; } } }); title = (TextView)this.findViewById(R.id.title); back = (ImageButton)findViewById(R.id.back); home = (ImageButton)findViewById(R.id.home); twitter = (ImageButton)findViewById(R.id.twitt); facebook = (ImageButton)findViewById(R.id.facebook); int Index = extras.getInt("index"); Log.i("index from map"," index is " + Index); if(extras != null){ setUpDesc(Index); // i'm not sure if i'm handling the indices in a proper way but i'm passing the indices to this method. } if(items.size()>0) items.clear(); back.setOnClickListener(new View.OnClickListener() { public void onClick(View arg0) { if(mCheckView){ fv.setVisibility(View.GONE); SearchListView.setVisibility(View.VISIBLE); mCheckView = false; } else{ finish(); } // finish(); } }); home.setOnClickListener(new View.OnClickListener() { public void onClick(View arg0) { finish(); } }); twitter.setOnClickListener(new View.OnClickListener() { public void onClick(View arg0) { Intent web = new Intent(FestivalEvents.this, Twitter.class); startActivity(web); } }); facebook.setOnClickListener(new OnClickListener() { public void onClick(View arg0) { Facebook facebook = new Facebook(BedFordApp.APP_ID); String[] lPermissions = new String[] { "user_likes" }; facebook.authorize(FestivalEvents.this, lPermissions, new BedFordFBDialogListener( FestivalEvents.this, facebook)); } }); tv3.setOnClickListener(new View.OnClickListener() { public void onClick(View arg0) { String link =tv3.getText().toString(); Intent web = new Intent(FestivalEvents.this,WebView1.class); web.putExtra("link", link); // web.putExtra("channelstr", channelStr); startActivity(web); } }); aa = new SearchListAdapter(this); SearchListView.setAdapter(aa); refreshEarthquakes(nameOFFile); } private int nodeLength; private void refreshEarthquakes(String fileName) { // Get the XML try { // File file = new File("/sdcard/BedfordEvents.xml"); // obj_is = new FileInputStream(file); InputStream inputStream = getAssets().open("BedfordEvents.xml"); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); // Parse the earthquake feed. Document dom = db.parse(new InputSource(inputStream)); Element docEle = dom.getDocumentElement(); // Clear the old earthquakes items.clear(); // Get a list of each earthquake entry. NodeList nl = docEle.getElementsByTagName("SearchResults"); nodeLength = nl.getLength()-1; if (nl != null && nl.getLength() > 0) { for (int i = 0 ; i < nl.getLength(); i++) { Element entry = (Element)nl.item(i); Element title = (Element)entry.getElementsByTagName("ArticleId").item(0); Element g = (Element)entry.getElementsByTagName("ArticleTitle").item(0); Element when = (Element)entry.getElementsByTagName("ArticleDesc").item(0); Element link = (Element)entry.getElementsByTagName("WebsiteLink").item(0); Element image = (Element)entry.getElementsByTagName("ImageLink").item(0); Element articleDate = (Element)entry.getElementsByTagName("ArticleDate").item(0); String details = title.getFirstChild().getNodeValue(); //String hostname = "http://earthquake.usgs.gov"; String linkString = link.getFirstChild().getNodeValue(); String imageLink = image.getFirstChild().getNodeValue(); String date = articleDate.getFirstChild().getNodeValue(); String titel = g.getFirstChild().getNodeValue(); String dt = when.getFirstChild().getNodeValue(); ParsedData pd = new ParsedData(details,titel, dt, linkString, imageLink,date); // Process a newly found data addNewDetail(pd); } } } catch (MalformedURLException e) { e.printStackTrace(); }catch (FileNotFoundException e) { System.out.println("file not found"); Toast.makeText(this, "No such File with Name "+nameOFFile+" Found in sdcard", Toast.LENGTH_LONG).show(); } catch (IOException e) { e.printStackTrace(); } catch (ParserConfigurationException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } finally { } } private void addNewDetail(ParsedData _data) { // Add the new data to our list items.add(_data); // Notify the Base adapter of a change. aa.notifyDataSetChanged(); } class SearchListAdapter extends BaseAdapter { private Context mContext; private LayoutInflater mInflater; private int currentPosition =0; public SearchListAdapter(Context c) { mContext = c; mInflater = LayoutInflater.from(mContext); } public int getCount() { return items.size(); } public Object getItem(int position) { return items.get(position); } public long getItemId(int position) { return position; } public View getView(final int position, View convertView, ViewGroup parent) { ViewHolder holder; if (convertView == null) { convertView = mInflater.inflate(R.layout.festivalevents2, null); holder = new ViewHolder(); holder.bar = (ProgressBar)convertView.findViewById(R.id.progress); holder.imageLink = (ImageView) convertView.findViewById(R.id.imageLink); holder.title = (TextView) convertView.findViewById(R.id.title); holder.desc = (TextView) convertView.findViewById(R.id.desc); holder.link = (TextView) convertView.findViewById(R.id.link); holder.date = (TextView) convertView.findViewById(R.id.date); holder.link.setVisibility(View.GONE); holder.desc.setVisibility(View.GONE); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } convertView.setOnClickListener(new OnClickListener() { public void onClick(View arg0) { // Toast.makeText(mContext, "you clicked position "+position, Toast.LENGTH_LONG).show(); bkp_position = position; //visibility_left_arrow_postion(); visibility_arrow_postion(); setUpDesc(position); } }); holder.date.setText(items.get(position).getDate()); holder.title.setText(items.get(position).getArticleTitle()); // title.setGravity(Gravity.RIGHT); holder.desc.setText(items.get(position).getArticleDesc()); final ProgressBar bar = holder.bar; final ImageView holderImage = holder.imageLink; new Thread(){ public void run() { try { BitmapFactory.Options o = new BitmapFactory.Options(); o.inJustDecodeBounds = true; BitmapFactory.decodeStream(new URL(items.get( position).getImageLink()).openStream(),null,o); //The new size we want to scale to final int REQUIRED_SIZE=40; //Find the correct scale value. It should be the power of 2. int width_tmp=o.outWidth, height_tmp=o.outHeight; int scale=1; while(true){ if(width_tmp/2<REQUIRED_SIZE || height_tmp/ 2<REQUIRED_SIZE) break; width_tmp/=2; height_tmp/=2; scale*=2; } //Decode with inSampleSize BitmapFactory.Options o2 = new BitmapFactory.Options(); o2.inSampleSize=scale; final Bitmap lBitmap = BitmapFactory.decodeStream(new URL(items.get( position).getImageLink()).openStream(), null, o2); handler.post(new Runnable() { public void run() { holderImage.setImageBitmap(lBitmap); holderImage.setVisibility(View.VISIBLE); bar.setVisibility(View.GONE); } }); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }.start(); SpannableString content = new SpannableString(items.get(position).getLink()); content.setSpan(new UnderlineSpan(), 0, content.length(), 0); holder.link.setText(content); holder.link.setOnClickListener(new OnClickListener() { public void onClick(View arg0) { startWebView(position+1); } }); return convertView; } protected void startWebView(int position) { String link = items.get(position).getLink(); Intent web = new Intent(mContext,WebView1.class); web.setAction("android.intent.action.own"); web.putExtra("link", link); web.putExtra("channelstr", channelStr); mContext.startActivity(web); } class ViewHolder { TextView date; ProgressBar bar; ImageView imageLink; TextView title; TextView desc; TextView link; } } private void visibility_arrow_postion() { if (bkp_position == 0){ arrowImgLeft.setVisibility(View.INVISIBLE); }else{ arrowImgLeft.setVisibility(View.VISIBLE); } if (bkp_position == nodeLength){ arrowImgRight.setVisibility(View.INVISIBLE); }else{ arrowImgRight.setVisibility(View.VISIBLE); } } // THIS METHOD IS THE ONE WHICH HELPS SHOWING EVENT DETAILS private void setUpDesc(int position) { SearchListView.setVisibility(View.GONE); mCheckView = true; final ParsedData parsedData = items.get(position); fv.setVisibility(View.VISIBLE); tv1.setText(parsedData.getArticleTitle()); tv2.setText(parsedData.getArticleDesc()); tv3.setText(parsedData.getLink()); date1.setText(parsedData.getDate()); Bundle lBundle = new Bundle(); lBundle.putString("url", parsedData.getImageLink()); Message msg = new Message(); msg.setData(lBundle); handler.dispatchMessage(msg); } Handler handler = new Handler() { @Override public void handleMessage(Message msg) { Bundle lBundle = msg.getData(); String url = lBundle.getString("url"); try { Bitmap lBitmap = BitmapFactory.decodeStream(new URL(url).openStream()); imLink.setImageBitmap(lBitmap); // imageLink.setImageBitmap(lBitmap); } catch (Exception e) { e.printStackTrace(); } } }; } -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en