我恰好在这一行出现了一个异常,无法弄清楚这是怎么回事。
SecondsText.setText(Math.round(SecondsTime));
这是其余的代码:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
long AnDate = 1476650909;
TextView SecondsText = (TextView) findViewById(R.id.SecondsText);
TextView MinutesText = (TextView) findViewById(R.id.MinutesText);
TextView HoursText = (TextView) findViewById(R.id.HoursText);
TextView DaysText = (TextView) findViewById(R.id.DaysText);
long SecondsTime = System.currentTimeMillis()/1000 - AnDate;
long MinutesTime = SecondsTime/60;
long HoursTime = MinutesTime/60;
long DaysTime = HoursTime/24;
**SecondsText.setText(Math.round(SecondsTime));**
MinutesText.setText(Math.round(MinutesTime));
HoursText.setText(Math.round(HoursTime));
DaysText.setText(Math.round(DaysTime));
}
例外说明
> 10-12 15:32:25.920 9254-9254/com.example.mauro.howmuchtime E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.mauro.howmuchtime, PID: 9254
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mauro.howmuchtime/com.example.mauro.howmuchtime.MainActivity}: android.content.res.Resources$NotFoundException: String resource ID #0x3bd011c
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2792)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2870)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1601)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:172)
at android.app.ActivityThread.main(ActivityThread.java:6590)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x3bd011c
at android.content.res.Resources.getText(Resources.java:339)
at android.widget.TextView.setText(TextView.java:5496)
**at com.example.mauro.howmuchtime.MainActivity.onCreate(MainActivity.java:24)**
at android.app.Activity.performCreate(Activity.java:7023)
at android.app.Activity.performCreate(Activity.java:7014)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1215)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2745)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2870)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1601)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:172)
at android.app.ActivityThread.main(ActivityThread.java:6590)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
java.lang.Math被导入,SecondssText是Android Studio中的textview对象,SecondsTime是一个长变量,我希望从中删除小数。我知道这是一个非常愚蠢的问题,但无法真正弄清楚,因为我是Java新手。谢谢!