<Button
android:id="@+id/shortmsg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="짧은 메시지"
/>
android:id="@+id/shortmsg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="짧은 메시지"
/>
(toasttest.xml)
public void onClick(View v) {
switch (v.getId()) {
case R.id.shortmsg:
switch (v.getId()) {
case R.id.shortmsg:
(ToastTest.java)
error: constant expression required
case R.id.shortmsg:
^
찾아보니 final 상수가 아니라서 발생하는 오류라는데
xml 파일에 정의한건 final 상수가 아닌게 되는건가??
switch 대신 if 쓰면 됨
이거 2016년 책인데(김상형 저) 그 예제 그대로 복붙한건데 예제가 구버전이라 그런거임??
ㅇㅇ
답변 감사 근데 언제 저거 바뀐거임??
non final이 기본값이 된건 최근인데, 아마 2-3년 전부터 바뀔거라고 ide에서 경고로 나왔던 것 같음
아하 답변 감사
https://stackoverflow.com/questions/64335374/how-to-resolve-resource-ids-will-be-non-final-in-android-gradle-plugin-version
아하