-3
私はAndroid開発には新しく、Androidスタジオに時計アプリを作成しようとしています。目覚まし時計機能を追加しようとしているうちに、問題が発生しました。メッセージ',' or ')' expected
が表示され、それに追従しようとするとエラーが発生しました。'、' or ')'が目覚まし時計設定で予想されています
これはMainActivity.java内のコードの一部です:
public void onToggleClicked(View view) {
Calendar calendar = Calendar.getInstance();
long time=(calendar.getTimeInMillis()-(calendar.getTimeInMillis()%60000));
if (((Switch) view).isChecked()) {
//this line and the next are causing the errors
calendar.set(Calendar.HOUR_OF_DAY, alarmTimePicker.getHour(String time));
calendar.set(Calendar.MINUTE, alarmTimePicker.getMinute(String time));
Intent intent = new Intent(this, myReceiver.class);
pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0);
if(System.currentTimeMillis()>time) {
if(calendar.AM_PM == 0)
time = time + (1000 * 60 * 60 * 12);
else
time = time + (1000 * 60 * 60 * 24);
}
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, time, 10000, pendingIntent);
}
else {
alarmManager.cancel(pendingIntent);
}
}
EDIT: このアプリをコンパイルしようとしているエラーログです:
error: ')' expected
calendar.set(Calendar.HOUR_OF_DAY, alarmTimePicker.getHour(String time));
^
error: ';' expected
calendar.set(Calendar.HOUR_OF_DAY, alarmTimePicker.getHour(String time));
^
error: illegal start of expression
calendar.set(Calendar.HOUR_OF_DAY, alarmTimePicker.getHour(String time));
^
error: ')' expected
calendar.set(Calendar.MINUTE, alarmTimePicker.getMinute(String time));
^
error: ';' expected
calendar.set(Calendar.MINUTE, alarmTimePicker.getMinute(String time));
^
error: illegal start of expression
calendar.set(Calendar.MINUTE, alarmTimePicker.getMinute(String time));
^
6 errors
:app:compileDebugJavaWithJavac FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --
debug option to get more log output.
BUILD FAILED
Total time: 10.872 secs
これは構文上正しいと思われます。これはエラーを引き起こすコードですか? AM_PMはゼロ以外の整数定数であるため、FYI - 'calendar.AM_PM == 0'も常にfalseになります。 –
@Ed George Androidスタジオは誤ったエラーで有名ですが、コードはコンパイルされません。 –
完全なエラーメッセージをコピーできますか?あるいは、問題のコードをさらに表示することもできます。これは、「誤ったエラー」である可能性は低く、構文エラーである可能性がより高い –