运行我的应用程序时,我有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();
}
关于这个例外的任何想法?!我应该怎么做
答案 0 :(得分:1)
使EmsakeyyaActivity的构造函数公开,如下所示:
public EmsakeyyaActivity()
{
fajrTime = new Time();
shuroqTime = new Time();
duhrTime = new Time();
asrTime = new Time();
maghrebTime = new Time();
eshaaTime = new Time();
}
另外,作为一般规则,最好在onCreate()方法中初始化您的活动,而不是使用构造函数。