为什么这段代码会导致程序无响应

解决方案 »

  1.   

    debug调试下就知道了  你的while循环写的有问题 
      

  2.   

    public class MainActivity extends Activity implements OnClickListener {
        EditText editText;
        Button bt;
        TextView textView,textView1;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            editText=(EditText)findViewById(R.id.edittext);
            bt=(Button)findViewById(R.id.button);
            textView=(TextView)findViewById(R.id.tv1);
            textView1=(TextView)findViewById(R.id.tv2);
            bt.setOnClickListener(this);
        }
        @Override
        public void onClick(View v) {
            switch (v.getId()) {
            case R.id.button:
                 
                String str=editText.getText().toString();
                textView.setText(str+"以内的质数有:");
                textView1.setText("2,3");
                try{
                int n=Integer.parseInt(str);
                int i=5;
                int j;
                while(i<=n)
                {
                 j=2;
                    while(j<i)
                    {
                        if(i%j==0)
                            break;
                        if(i-1==j)
                            textView1.append(","+i);
                        j++;
                    }
                    i++;
                }
                }
                catch (Exception e)
                {
                 textView1.setText(e.toString());
                }
                 
                break;
           default:break;
            }
        }
    }