添加OnItemClickListener侦听器时出错

时间:2014-12-29 14:37:14

标签: java android

我将OnItemClickListener方法添加到以下listvew中,以便在项目点击时打开详细信息活动。但是点击活动崩溃。我不知道我在哪里犯错误。有什么建议吗?

public class Frontpage extends ActionBarActivity{
	private String TAG = this.getClass().getSimpleName();
    private ListView lstView;
    private RequestQueue mRequestQueue;
    private ArrayList<NewsModel> arrNews ;
    private LayoutInflater lf;
    private VolleyAdapter va;
    private ProgressDialog pd;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.trending);
        
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    	Intent newActivity4=new Intent();
    	setResult(RESULT_OK, newActivity4);
        
        
        lf = LayoutInflater.from(this);


        arrNews = new ArrayList<NewsModel>();
        va = new VolleyAdapter();

        lstView = (ListView) findViewById(R.id.listView);
        lstView.setAdapter(va);
        mRequestQueue =  Volley.newRequestQueue(this);
        String url = "http://pipes.yahooapis.com/pipes/pipe.run?_id=giWz8Vc33BG6rQEQo_NLYQ&_render=json";
        pd = ProgressDialog.show(this,"Loading...","Please Wait...");
        pd.setCancelable(true); 
        try{
           
        }catch(Exception e)
        {

            }
        JsonObjectRequest jr = new JsonObjectRequest
        		(Request.Method.GET,url,null,new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject response) {
                Log.i(TAG,response.toString());
                parseJSON(response);
                va.notifyDataSetChanged();
                pd.dismiss();
;            }
        },new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
            	if (error instanceof NoConnectionError){
                   	Toast.makeText(getBaseContext(), "Bummer..There's No Internet connection!", Toast.LENGTH_LONG).show();

                }};
            });
        mRequestQueue.add(jr);

 }
    @Override
    public void onDestroy() {
        super.onDestroy();
        dismissPd();
    }

    private void dismissPd() {
        if (pd != null) {
            pd.dismiss();
            pd = null;
        }

        lstView.setOnItemClickListener(new AdapterView.OnItemClickListener(){ 

        	@Override
        	public void onItemClick(AdapterView<?> parent, View view,
        	                        int position, long id) { 
        		Intent intent = new Intent(Frontpage.this, NewsDetails.class);    
        	    startActivity(intent);
        	}
        	});}

    private void parseJSON(JSONObject json){
        try{
            JSONObject value = json.getJSONObject("value");
            JSONArray items = value.getJSONArray("items");
            for(int i=0;i<items.length();i++){

                    JSONObject item = items.getJSONObject(i);
                    NewsModel nm = new NewsModel();
                    nm.setTitle(item.optString("title"));
                    nm.setDescription(item.optString("description"));
                    nm.setLink(item.optString("link"));
                    nm.setPubDate(item.optString("pubDate"));
                    arrNews.add(nm);
            }
        }


        
        catch(Exception e){
            e.printStackTrace();
        }

    }

我的logcat:

12-29 17:33:47.759: E/dalvikvm(20958): GC_CONCURRENT freed 477K, 31% free 9562K/13763K, paused 14ms+15ms, total 59ms
12-29 17:33:48.059: I/Frontpage(20958): {"value":{"callback":"","generator":"http:\/\/pipes.yahooapis.com\/pipes\/","pubDate":"Mon, 29 Dec 2014 14:29:12 +0000","title":"Cycling News","items":[{"guid":{"content":"urn:newsml:sports.yahoo,lego:19780928:top,article,5d2ebd25-84e5-3b2c-9939-fa928362f76e-l:1","isPermaLink":"false"},"pubDate":"Thu, 25 Dec 2014 05:06:03 PST","category":"SC","title":"Trott announces engagement to British team mate Kenny (Reuters)","y:title":"Trott announces engagement to British team mate Kenny (Reuters)","y:id":{"value":"urn:newsml:sports.yahoo,lego:19780928:top,article,5d2ebd25-84e5-3b2c-9939-fa928362f76e-l:1","permalink":"false"},"description":"LONDON (Reuters) - British Olympic track cycling gold medalists Laura Trott and Jason Kenny are to tie the knot. \"Merry Christmas everyone. I've had the most amazing couple of days thanks to @JasonKenny107 and the whole family #engaged\", Trott write on Twitter on Thursday. Trott, 22, took two golds at London 2012 in the team pursuit and omnium while 26-year-old Kenny also topped the podium in team sprint and individual sprint. Both are expected to be part of the British team for the Rio Olympics in 2016. (Editing by Martyn Herman)","link":"http:\/\/us.rd.yahoo.com\/sports\/rss\/sc\/SIG=137v5fe67\/*http%3A\/\/sports.yahoo.com\/news\/trott-announces-engagement-british-team-mate-kenny-130603685--spt.html","y:published":{"minute":"6","day_of_week":"4","utime":"1419512763","timezone":"UTC","day_name":"Thursday","second":"3","day_ordinal_suffix":"th","month":"12","year":"2014","month_name":"December","day":"25","hour":"13"},"y:repeatcount":"1"},{"guid":{"content":"urn:newsml:sports.yahoo,lego:19780928:top,article,d8de91ac-8da9-3d9d-81bb-79a44e8d3c41-l:1","isPermaLink":"false"},"pubDate":"Fri, 19 Dec 2014 16:26:26 PST","media:content":{"type":"image\/jpeg","url":"http:\/\/l.yimg.com\/iu\/api\/res\/1.2\/kuPd5jCbslBsMo8k0akURQ--\/YXBwaWQ9eXZpZGVvO2NoPTIwMDA7Y3I9MTtjdz0yMDAwO2R4PTUwMTtkeT0xO2ZpPXVsY3JvcDtoPTEzMDtxPTEwMDt3PTEzMA--\/http:\/\/media.zenfs.com\/en_us\/Sports\/ap\/201412191711618863458","width":"130","height":"130"},"category":"SC","title":"2 Armstrong associates settle lawsuit with Landis (The Associated Press)","y:title":"2 Armstrong associates settle lawsuit with Landis (The Associated Press)","y:id":{"value":"urn:newsml:sports.yahoo,lego:19780928:top,article,d8de91ac-8da9-3d9d-81bb-79a44e8d3c41-l:1","permalink":"false"},"description":"<p><a rel=\"nofollow\" target=\"_blank\" href=\"http:\/\/us.rd.yahoo.com\/sports\/rss\/sc\/SIG=13141nrib\/*http%3A\/\/sports.yahoo.com\/news\/2-armstrong-associates-settle-lawsuit-landis-223026201--spt.html\"><img src=\"http:\/\/l.yimg.com\/iu\/api\/res\/1.2\/kuPd5jCbslBsMo8k0akURQ--\/YXBwaWQ9eXZpZGVvO2NoPTIwMDA7Y3I9MTtjdz0yMDAwO2R4PTUwMTtkeT0xO2ZpPXVsY3JvcDtoPTEzMDtxPTEwMDt3PTEzMA--\/http:\/\/media.zenfs.com\/en_us\/Sports\/ap\/201412191711618863458\" width=\"130\" height=\"130\" alt=\"FILE - In this Feb. 15, 2011 file photo, Lance Armstrong pauses during an interview in Austin, Texas. Two of Lance Armstrong's longtime business partners have agreed to pay the federal government $500,000 to settle a whistleblower lawsuit filed by a former teammate, Floyd Landis, Friday, Dec. 19, 2014. (AP Photo\/Thao Nguyen, File)\" align=\"left\" border=\"0\"><\/a><\/p><p>AUSTIN, Texas (AP) -- Two of Lance Armstrong's longtime business partners have agreed to pay the federal government $500,000 to settle a whistleblower lawsuit filed by former teammate Floyd Landis.<\/p><br clear=\"all\"\/>","media:credit":{"content":"The Associated Press","role":"provider"},"link":"http:\/\/us.rd.yahoo.com\/sports\/rss\/sc\/SIG=13141nrib\/*http%3A\/\/sports.yahoo.com\/news\/2-armstrong-associates-settle-lawsuit-landis-223026201--spt.html","media:text":{"content":"FILE - In this Feb. 15, 2011 file photo, Lance Armstrong pauses during an interview in Austin, Texas. Two of Lance Armstrong's longtime business partners have agreed to pay the federal government $500,000 to settle a whistleblower lawsuit filed by a former teammate, Floyd Landis, Friday, Dec. 19, 
12-29 17:33:50.039: W/dalvikvm(20958): threadid=1: thread exiting with uncaught exception (group=0x410f1438)
12-29 17:33:53.009: E/Trace(22348): error opening trace file: No such file or directory (2)
12-29 17:33:53.069: W/dalvikvm(22348): Refusing to reopen boot DEX '/system/framework/hwframework.jar'
12-29 17:33:53.239: W/System.err(22348): Invalid int: ""
12-29 17:33:53.859: I/Adreno200-EGL(22348): <qeglDrvAPI_eglInitialize:299>: EGL 1.4 QUALCOMM build: AU_LINUX_ANDROID_JB_REL_2.0.3.04.01.01.21.010_msm8625_JB_REL_2.0.3_Merge_release_AU (Merge)
12-29 17:33:53.859: I/Adreno200-EGL(22348): Build Date: 10/26/12 Fri
12-29 17:33:53.859: I/Adreno200-EGL(22348): Local Branch: 
12-29 17:33:53.859: I/Adreno200-EGL(22348): Remote Branch: quic/jb_rel_2.0.3
12-29 17:33:53.859: I/Adreno200-EGL(22348): Local Patches: NONE
12-29 17:33:53.859: I/Adreno200-EGL(22348): Reconstruct Branch: AU_LINUX_ANDROID_JB_REL_2.0.3.04.01.01.21.010 +  NOTHING

0 个答案:

没有答案
相关问题