android中的uncaughtException

时间:2015-06-22 16:45:12

标签: android thread-exceptions

运行我的应用程序时,我有Exception这导致停止应用程序。

  

异常是:ThreadGroup.uncaughtException(Thread,Throwable)   行:689

我清楚这个问题,我有2项活动,如下:

1)HomeActivity:包含一个打开第二个活动的“打开Emsakkeya”按钮

2)EmsakeyyaActivity:在这个Activity我设置并显示一些数据......

当我调试应用程序时,当我在按钮keyListener

中调用第二个活动时它崩溃了
public class HomeActivity extends ActionBarActivity 
{
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home);
    setTitle("Home Screen");

    Button emsakeyya_btn=(Button) findViewById(R.id.emsakeyya_btn);
    emsakeyya_btn.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {

            Intent i = new Intent(HomeActivity.this, EmsakeyyaActivity.class);
            startActivity(i);
        }
    });
}

第二个活动

public class EmsakeyyaActivity extends ActionBarActivity {

EmsakeyyaActivity()
{
    fajrTime = new Time();
    shuroqTime = new Time();
    duhrTime = new Time();
    asrTime = new Time();
    maghrebTime = new Time();
    eshaaTime = new Time();
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_emsakeyya);

    String zoneName = "zoneName";
    AllPraysTime(fajrTime,shuroqTime,duhrTime,asrTime,maghrebTime,eshaaTime);

    currentPrayTime = (TextView) findViewById(R.id.currentSalah_lbl2);
    nextPrayTime = (TextView) findViewById(R.id.nxtSalah_lbl2);
    fajrPrayTime = (TextView) findViewById(R.id.fajrPrayTime_lbl2);
    shuroqPrayTime = (TextView) findViewById(R.id.shuroqPrayTime_lbl2);
    duhrPrayTime = (TextView) findViewById(R.id.duhrPrayTime_lbl2);
    asrPrayTime = (TextView) findViewById(R.id.asrPrayTime_lbl2);
    maghrebPrayTime = (TextView) findViewById(R.id.maghrebPrayTime_lbl2);
    eshaaPrayTime = (TextView) findViewById(R.id.eshaaPrayTime_lbl2);

    SetPraysTime();

}

关于这个例外的任何想法?!我应该怎么做

1 个答案:

答案 0 :(得分:1)

使EmsakeyyaActivity的构造函数公开,如下所示:

public EmsakeyyaActivity()
{
    fajrTime = new Time();
    shuroqTime = new Time();
    duhrTime = new Time();
    asrTime = new Time();
    maghrebTime = new Time();
    eshaaTime = new Time();
}

另外,作为一般规则,最好在onCreate()方法中初始化您的活动,而不是使用构造函数。