RT,怎么run里面的while函数会退出呢?str_all数组里只有200多个,然后str就成null了,然后就退出了~public class holdon_listener extends PhoneStateListener {
@Override
public void onCallStateChanged(int state, String incomingNumber){
super.onCallStateChanged(state, incomingNumber);
if((state == TelephonyManager.CALL_STATE_OFFHOOK)&(firstcall)){
mhandler.postDelayed(mrun, 1000);
firstcall = false;
}
else if((state == TelephonyManager.CALL_STATE_IDLE)&(!(firstcall)))
{
firstcall = true;
}
}
}private Handler mhandler = new Handler();
private Runnable mrun = new Runnable(){
@SuppressWarnings("null")
@Override
public void run() {
// TODO Auto-generated method stub
System.out.println("--------func start--------"); // 方法启动 
        try 
        {
         ArrayList<String> cmdLine=new ArrayList<String>();   //设置命令   logcat -d 读取日志
            cmdLine.add("logcat");
            cmdLine.add("-d");
            
            ArrayList<String> clearLog=new ArrayList<String>();  //设置命令  logcat -c 清除日志
            clearLog.add("logcat");
            clearLog.add("-c");
            
            Process process=Runtime.getRuntime().exec(cmdLine.toArray(new String[cmdLine.size()]));   //捕获日志
            BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(process.getInputStream()));    //将捕
        String str = "";
        String str_all[] = new String [1000];
        int ii = 0;
        while((str = bufferedReader.readLine())!=null)
        {
         Runtime.getRuntime().exec(clearLog.toArray(new String[clearLog.size()])); 
         str_all[ii] = str;
                if(str==null)
                {
                    System.out.println("--   is null   --");
                }
         ii++;
        }
        ii = ii +1;
} catch (IOException e) 
{
e.printStackTrace();
System.out.println("--------str wrong--------");
}
System.out.println("--------func end--------");
}

解决方案 »

  1.   

    从日志中读入数据,可是调用清除日志功能,日志都清掉了,难道不应该为null吗?
      

  2.   

    Runtime.getRuntime().exec(clearLog.toArray(new String[clearLog.size()])); 是这句吗?这不是每次循环执行一次清空么,下一次执行str = bufferedReader.readLine()应该有新的吧?关键是str_all前100多都有值,然后就全是null了~~~
      

  3.   

    logcat -d 读取所有log后退出,读取的日志也是一次性的,就算没有运行logcat -c清除日志,bufferedReader.readLine每次读一行,也总有读到结尾结束的时候。建议手机连到电脑上,看Eclipse输出的日志数量与你程序中统计ii的数量是否相同。
      

  4.   

    明显Eclipse输出的日志比ii的要多得多,它是一直输出的,而为什么ii只能到100多呢,是不是线程中止了?
    public class holdon_listener extends PhoneStateListener {
        @Override
        public void onCallStateChanged(int state, String incomingNumber){
            super.onCallStateChanged(state, incomingNumber);
            if((state == TelephonyManager.CALL_STATE_OFFHOOK)&(firstcall)){
                mhandler.postDelayed(mrun, 1000);
                firstcall = false;
            }
            else if((state == TelephonyManager.CALL_STATE_IDLE)&(!(firstcall)))
            {
                firstcall = true;
            }
        }
    }调用方法有问题?
      

  5.   

    你只读了一次日志,Eclipse新输出的日志又没有读入