在运行App时在Adapter类的getView中获取java.lang.NullPointerException

时间:2015-07-31 14:44:09

标签: java android sqlite listview android-adapter

我试图在自定义ListView中的SQLite数据库中显示我的表中的行,因为我创建了一个ProductAdapter类。 运行应用程序时出错 以下是错误

protected void claim(object sender, EventArgs e)
{
        var location = Request.Params["lid"];
        string logon_user = Request.LogonUserIdentity.Name.Substring(7);
        LinkButton claimButton = (LinkButton)(sender);
        int currentID = Convert.ToInt32(claimButton.CommandArgument);

        bool isTaken = false;
        using (SqlConnection conn = new SqlConnection(""))
        {
            SqlCommand cmd = new SqlCommand(@"SELECT COUNT(*) as isTaken FROM ClaimList WHERE ID = '" + currentID + "' AND Status = 2", conn);
            conn.Open();
            SqlDataReader rdr = cmd.ExecuteReader();
            while (rdr.Read())
            {
                if (Convert.ToInt32(rdr["isTaken"]) > 0) isTaken = true;
            }
            rdr.Close();
        }
        if (!isTaken)
        {
            using (SqlConnection conn = new SqlConnection(""))
            {
                SqlCommand cmd = new SqlCommand(@"UPDATE ClaimList set Status=@f1, ClaimedBy=@f2, ClaimedDate=@f3 where ID=@f4", conn);
                conn.Open();
                cmd.Parameters.Add("@f1", SqlDbType.Int).Value = 2;
                cmd.Parameters.Add("@f2", SqlDbType.Int).Value = logon_user;
                cmd.Parameters.Add("@f3", SqlDbType.DateTime).Value = DateTime.Now.ToString();
                cmd.Parameters.Add("@f4", SqlDbType.Int).Value = currentID;
                cmd.ExecuteNonQuery();
            }
            Response.Redirect("View.aspx?id=" + currentID);
        }
        else
        {
            Response.Redirect("Location.aspx?lid=" + location + "&action=taken");
        }
}

以下是第07-31 14:31:42.548 1968-1968/? E/AndroidRuntime﹕ FATAL EXCEPTION: main java.lang.NullPointerException at com.sling.freshecomart.ProductAdapter.getView(ProductAdapter.java:54)

ProductAdapter.java:54

ProductAdapter类是

convertView = mInflater.inflate(R.layout.item,null);

请提供帮助并提前致谢

1 个答案:

答案 0 :(得分:3)

更改

 convertView = mInflater.inflate(R.layout.item,null);

 convertView = inflater.inflate(R.layout.item,null);

becoz mInflater=null