Navigation MenuItem Switch Fehler

wer112

Top Contributor
Wollte ein kleines Nebenprojekt starten, dafür benutze ich die Fragment Steuerung aus meinem App Store.
Ich habe alles genauso gemacht. Leider wird die Reihe mit dem Case rot angestrichen und bekomme diese Fehler Meldung:

error: constant expression required
case R.id.fr�hst�ck_icon:
^

der Code:

Java:
nav.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {


                switch (item.getItemId()){


                    case R.id.fruehstueck_icon:

                }

                return true;
            }
        });

Ich verstehe grade nicht, wieso im App Store es geht, aber diesmal nicht.

Und Ja es ist die veraltete Steuerung.

Ich bedanke mich bei euch ;)
 

KonradN

Super-Moderator
Mitarbeiter
Hast Du ein Library Projekt? Das wäre jetzt meine Vermutung. Die Erklärung ist, dass mit ADT 14 die Definition von R.id.* bei Library Projekten geändert wurde und es keine Konstanten mehr sind.

Non-constant Fields in Case Labels - Android Studio Project Site
In a regular Android project, constants in the resource R class are declared like this:
public static final int main=0x7f030004;

However, as of ADT 14, in a library project, they will be declared like this:
public static int main=0x7f030004;

In other words, the constants are not final in a library project. The reason for this is simple: When multiple library projects are combined, the actual values of the fields (which must be unique) could collide. Before ADT 14, all fields were final, so as a result, all libraries had to have all their resources and associated Java code recompiled along with the main project whenever they were used. This was bad for performance, since it made builds very slow. It also prevented distributing library projects that didn't include the source code, limiting the usage scope of library projects.
 

wer112

Top Contributor
Hast Du ein Library Projekt? Das wäre jetzt meine Vermutung. Die Erklärung ist, dass mit ADT 14 die Definition von R.id.* bei Library Projekten geändert wurde und es keine Konstanten mehr sind.

Non-constant Fields in Case Labels - Android Studio Project Site
Ich habe grade die Lösung gefunden:


Aber ich verstehe nicht, wieso im App Store geht und hier ohne die Zeile nicht. Was muss ich machen, damit ich diese Zeile nicht brauche in den propetice
 

wer112

Top Contributor
Dann schaue mal welche Plugins in den neuen Projekt und welche in deinem alten benutzt werden. Welche AS da selber eingebunden hat.
Im neuen:

plugins {
id 'com.android.application' version '8.0.1' apply false
id 'com.android.library' version '8.0.1' apply false
}

Im Alten:


// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {


classpath 'com.android.tools.build:gradle:8.0.1'



// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

allprojects {
repositories {
google()
jcenter()

}
}

task clean(type: Delete) {
delete rootProject.buildDir
}
 

Neue Themen


Oben