0

这是我从中获得一个指向第 65 行的空指针的类。

 public class searchlist extends ListActivity 
  {

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    new loadSomeStuff().execute();
}

public class loadSomeStuff extends AsyncTask<String, Integer, String[]>
{
  ProgressDialog dialog;

  protected void onPreExecute()
  {
     dialog = new ProgressDialog(searchlist.this); 
     dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
     dialog.setMax(100);
     dialog.show();
  }
    @Override
    protected String[] doInBackground(String... arg0) {
        // TODO Auto-generated method stub

        for(int i =0; i<20; i++)
        {
          publishProgress(5);
          try
          {
          Thread.sleep(80);
          } catch(InterruptedException e)
          {
              e.printStackTrace();
          }
        }
        dialog.dismiss();
        int loops = search_page.returnlooped();
        int[] teacup = search_page.returnNumArray();
        sqlStuff searching = new sqlStuff(searchlist.this);
        String[] IDSysNames = searching.getIDSysName();
        searching.close();

        String[] resultList = new String[loops];
        for(int i=0; i < loops; i++ )
        {
            if(IDSysNames[teacup[i]] != null)
            {

            resultList[i].equals(IDSysNames[teacup[i]]);    //Line 65 

            }
        }
         setListAdapter(new ArrayAdapter<String>(searchlist.this, android.R.layout.simple_list_item_1, resultList));
        return null;
    }

    protected void onProgressUpdate(Integer...progress)
    {
        dialog.incrementProgressBy(progress[0]);
    }
}

这是上面的类使用的 getIDSysname 类。

 public String[] getIDSysName()
{
    String[] result = new String[0];

    try
    {
        String[] columns = new String[] {KEY_SYSNAME};
        Cursor c  =  ChemPal.query(DATABASE_TABLE, columns, null, null, null, null, null);
        Log.d("SqlDStuff", "Cursor count: "+c.getCount());
        int iSysName = c.getColumnIndex(KEY_SYSNAME);

        int i = 0;
        for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()){
            i++;
        }

        result = new String[i];
        i = 0;
        for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()){
            result[i] = c.getString(iSysName);
            i++;

        }
    }
    catch(Exception e)
    {   

    }

    return result;
}

如果还需要什么,请在评论中提问,因为这让我感到沮丧。谢谢

4

3 回答 3

0

您已经分配了一个字符串数组:

String[] resultList = new String[loops];
for (int i=0; i < loops; i++ ) {
    if (IDSysNames[teacup[i]] != null) {
        resultList[i].equals(IDSysNames[teacup[i]]);    //Line 65 

里面没有任何可以调用的字符串equals

于 2013-05-04T20:13:02.020 回答
0
   dialog.dismiss();

你不能打电话给解雇doInBackground()。与 UI 线程相关的每个方法都必须在 UI 线程上调用。

尝试:

runOnUiThread(new Runnable() {

    public void run() {
        dialog.dismiss();
    }
});
于 2013-05-04T20:13:53.140 回答
0

setListAdapter(new ArrayAdapter(searchlist.this, android.R.layout.simple_list_item_1, resultList));

我不得不将此方法移至 onCreate(); 我不得不通过名为 onPostExecute 的方法重新运行 resultList 值。

原来日志猫正在组成空指针不知道为什么。谢谢大家,但我现在明白了。

于 2013-05-04T22:12:36.193 回答