2011-03-25 64 views
1

我必须从列表活动调用mapactivity。每当用户点击listview上的项目,地图活动应该fire.But当项目被点击即时获取异常,您的地图活动类别找到。地图活动没有被调用列表项目单击监听器

如果我把简单胡亚蓉insted的地图activity..my代码工作well..i不知道为什么引发异常

这里是我的代码。

XML文件

<?xml version="1.0" encoding="utf-8"?> 

  <!--Header --> 
<LinearLayout android:id="@+id/Header" 
      android:background="#EE7621" 
      android:layout_width="fill_parent" 
      android:layout_height="35dip" android:orientation="horizontal"> 

    <Button android:id="@+id/backPantries" 
      android:background="@drawable/pantryback" 
      android:layout_marginTop="2dip" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"> 
    </Button> 


</LinearLayout> 

<TextView android:textColor="#00AF33" android:background="#FFFFFF" android:text="pantryNameOnMap" android:id="@+id/pantryNameOnMap" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textSize="15dip"></TextView> 

<LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content"> 

    <com.google.android.maps.MapView 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/singlePantry" 
     android:layout_width="fill_parent" 
     android:layout_height="390dip" 
     android:gravity="center" 
     android:clickable="true" 
     android:apiKey="016JeH4RyEu_PJVdseJdN45AnkUvFrjE6gwLh9w"/> 



</LinearLayout> 

<TextView android:textColor="#00AF33" android:background="#FFFFFF" android:text="pantryPhNoOnMap" android:id="@+id/pantryPhNoOnMap" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center" android:textSize="15dip"></TextView> 


<LinearLayout android:id="@+id/linearLayout1" 
      android:background="@drawable/footer" 
      android:gravity="bottom" 
      android:orientation="vertical" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content"> 
</LinearLayout> 

这里是我的Java文件

package com.example; 

import java.net.URL; 
import java.util.ArrayList; 

import javax.xml.parsers.SAXParser; 
import javax.xml.parsers.SAXParserFactory; 

import org.xml.sax.InputSource; 
import org.xml.sax.XMLReader; 



import android.app.ListActivity; 
import android.app.ProgressDialog; 
import android.content.Context; 
import android.content.Intent; 
import android.os.Bundle; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.AdapterView; 
import android.widget.ArrayAdapter; 
import android.widget.ImageView; 
import android.widget.ListView; 
import android.widget.TextView; 
import android.widget.Toast; 
import android.widget.AdapterView.OnItemClickListener; 

public class OnlineUsersList extends ListActivity 
{ 
    public static ArrayList<UserInfo> m_user=new ArrayList<UserInfo>(); 
    OnlineUserInfo parsedOnlineUserInfo; 
    ImageAdapter m_adapter; 
    private Runnable viewOrders; 
    ProgressDialog m_ProgressDialog=null; 
    Intent myIntent; 
    @Override 
    public void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 
     TextView tv=new TextView(this); 
     Bundle bundle=new Bundle(); 
     bundle=this.getIntent().getExtras(); 
     String username=bundle.getString("username"); 
     String password=bundle.getString("password"); 
     tv.setText(username + " "+ password); 
     setContentView(R.layout.onlineuserlist); 
     this.m_adapter=new ImageAdapter(this, R.layout.onlineuserlistrow,m_user); 
     setListAdapter(this.m_adapter); 
     m_adapter.clear(); 
     ListView lv = getListView(); 
     lv.setTextFilterEnabled(true); 

     lv.setOnItemClickListener(new OnItemClickListener() 
     { 


      public void onItemClick(AdapterView<?> parent, View view,int Position,long id) 
      { 
       Toast.makeText(OnlineUsersList.this,"hi",Toast.LENGTH_LONG).show(); 
       myIntent=new Intent(OnlineUsersList.this,SinglePantriesOnMap.class); 
       startActivityForResult(myIntent, 0); 
      } 
     }); 
     viewOrders = new Runnable() 
     { 
      @Override 
      public void run() 
      { 
       try 
       { 
        String url="http://www.lafoodbank.org/iphone/general-xml.aspx?mode=volunteer"; 
        SAXParserFactory spf=SAXParserFactory.newInstance(); 
        SAXParser sp=spf.newSAXParser(); 
        XMLReader xr=sp.getXMLReader(); 
        URL sourceURL= new URL(url); 
        OnlineUserXMLHandler onlineUserXmlHandler=new OnlineUserXMLHandler(); 
        xr.setContentHandler(onlineUserXmlHandler); 
        xr.parse(new InputSource(sourceURL.openStream())); 

        parsedOnlineUserInfo=OnlineUserXMLHandler.getOnlineUserInfo(); 

         getOnlineUsers(); 
         try 
         { 
         Thread.sleep(1000); 
         } 
        catch (InterruptedException e) 
        { 
         e.printStackTrace(); 
        } 
         runOnUiThread(returnRes); 

       } 
       catch(Exception e) 
       { 
        System.out.println("====>Exception Raised in Parsing:"+ e); 
       } 

       System.out.println("=============================================>>Total volunteers:"+parsedOnlineUserInfo.getName().size()); 
       runOnUiThread(returnRes); 
      } 

     }; 

     Thread thread = new Thread(null, viewOrders, "MagentoBackground"); 
     thread.start(); 

      m_ProgressDialog = ProgressDialog.show(OnlineUsersList.this,  
      "Please Wait...!", "Retriving Volunteers...", true); 





    }///on creat over 
    private Runnable returnRes = new Runnable() 
    { 

      @Override 
      public void run() 
      { 
       if(m_user != null && m_user.size() > 0){ 
        m_adapter.notifyDataSetChanged(); 

        for(int i=0;i<m_user.size();i++) 
         m_adapter.add(m_user.get(i)); 
       } 
       TextView total=(TextView)findViewById(R.id.totalVolunteers); 
       total.setText("Total "+parsedOnlineUserInfo.getVId().size()+"Volunteers");  

       m_ProgressDialog.dismiss(); 
       m_adapter.notifyDataSetChanged(); 
      } 
    }; 

    public void getOnlineUsers() 
    { 
     m_user=new ArrayList<UserInfo>(); 
     UserInfo user[]=null; 
     user=new UserInfo[parsedOnlineUserInfo.getVId().size()]; 

     for(int i=0;i<parsedOnlineUserInfo.getVId().size();i++) 
     { 
      user[i]=new UserInfo(); 


      String vid=parsedOnlineUserInfo.getVId().get(i); 
      String name=parsedOnlineUserInfo.getName().get(i); 
      String organization=parsedOnlineUserInfo.getOrganization().get(i); 
      String email=parsedOnlineUserInfo.getEmail().get(i); 
      String longitude=parsedOnlineUserInfo.getLongitude().get(i); 
      String latitude=parsedOnlineUserInfo.getLatitude().get(i); 
      String address=parsedOnlineUserInfo.getAddress().get(i); 
      String city=parsedOnlineUserInfo.getCity().get(i); 
      String state=parsedOnlineUserInfo.getState().get(i); 
      String otherState=parsedOnlineUserInfo.getOtherState().get(i); 
      String zipCode=parsedOnlineUserInfo.getZipCode().get(i); 
      String loginStatus=parsedOnlineUserInfo.getLoginStatus().get(i); 
      String phone=parsedOnlineUserInfo.getPhone().get(i); 
      String mobId=parsedOnlineUserInfo.getMobId().get(i); 

      user[i].setVId(vid); 
      user[i].setName(name); 
      user[i].setOrganization(organization); 
      user[i].setEmail(email); 
      user[i].setLongitude(longitude); 
      user[i].setLatitude(latitude); 
      user[i].setAddress(address); 
      user[i].setCity(city); 
      user[i].setState(state); 
      user[i].setOtherState(otherState); 
      user[i].setZipCode(zipCode); 
      user[i].setLoginStatus(loginStatus); 
      user[i].setPhone(phone); 
      user[i].setMobId(mobId); 

      System.out.println("\n\n"+(i+1)+ " Volunteer"); 
      System.out.println("======================>USER INFO:ID"+user[i].getVId()); 
      System.out.println("======================>USER INFO:name"+user[i].getName()); 
      System.out.println("======================>USER INFO:organization"+user[i].getOrganization()); 
      System.out.println("======================>USER INFO:Email"+user[i].getEmail()); 
      System.out.println("======================>USER INFO:Longitude"+user[i].getLongitude()); 
      System.out.println("======================>USER INFO:Latitude"+user[i].getLatitude()); 
      System.out.println("======================>USER INFO:Addreess"+user[i].getAddress()); 
      System.out.println("======================>USER INFO:City"+user[i].getCity()); 
      System.out.println("======================>USER INFO:State"+user[i].getState()); 
      System.out.println("======================>USER INFO:OtherState"+user[i].getOtherState()); 
      System.out.println("======================>USER INFO:ZipCode"+user[i].getZipCode()); 
      System.out.println("======================>USER INFO:LOGIN STATUS"+user[i].getLoginStatus()); 
      System.out.println("======================>USER INFO:Phone"+user[i].getPhone()); 
      System.out.println("======================>USER INFO:MobileID"+user[i].getMobId()); 

      m_user.add(user[i]); 
      //m_adapter.add(m_user.get(i)); 

     } 

    } 

    class ImageAdapter extends ArrayAdapter<UserInfo> 
    { 
     private ArrayList<UserInfo> items; 

     public ImageAdapter(Context context, int textViewResourceId,ArrayList<UserInfo> items) 
     { 
      super(context, textViewResourceId, items); 
      this.items = items; 

     } 

     public View getView(final int position, View convertView, ViewGroup parent) 
     { 

      View v = convertView; 
      if (v == null) 
      { 
       try 
       { 
       LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
       v = vi.inflate(R.layout.onlineuserlistrow, null); 



        } 
       catch(Exception e) 
       { 
        System.out.println("Excption Caught"+e); 
       } 
      } 
      UserInfo user = items.get(position); 


      if (user != null) 
      { 
       TextView volunteerName = (TextView) v.findViewById(R.id.volunteerName); 
       ImageView statusImg=(ImageView)v.findViewById(R.id.statusImg); 

       if (volunteerName != null) 
       { 
        volunteerName.setText(user.getName()); 
       } 
       if(statusImg != null) 
       { 
        int loginStatus=Integer.parseInt(user.getLoginStatus()); 
        if(loginStatus==1) 
        { 
         statusImg.setImageResource(R.drawable.online); 
        } 
        else 
        { 
         statusImg.setImageResource(R.drawable.offline); 
        } 
       } 

      } 


       return v; 
     } 

    } 

} 

如果我把简单的活动,并删除的MapView从XML文件那么我的代码工作好...但是当我在XML文件,然后引发异常它说,找不到(),这是从REFRENCED MAP onListItemClickListener活动

回答

2

我不的类中声明活性MAPACTIVITY和地点的MapView在这里看到它,但你需要在你的Android清单文件中这样的一行。它需要在活动标签之外和应用程序标签内。

<uses-library android:name="com.google.android.maps"/> 
+0

apesa:非常感谢你的朋友....我花了很多时间在这个错误背后...... – 2011-03-29 03:53:43