Hallo!
Ich habe ein Codeschnipsel in dem ich jetzt ein Button einfügen möchte!
Der Button ist in allen Ansichten vorhanden jedoch bekomme ich immer die Fehlermeldung:
"error: cannot find symbol variable button2"
Egal ob ich "findViewById(R.id.button2);" im onCreate oder onClick Event verwende, jedesmal das selbe!
Zuerst erstelle ich eine Button Variable, dann versuche ich der Variable die ID vom Button zuzuweisen, aber klappt nicht..woran könnte es liegen?!?
Spoiler anzeigen
Das gibt er mir noch inne Gradle Console:
Spoiler anzeigen
Ich habe ein Codeschnipsel in dem ich jetzt ein Button einfügen möchte!
Der Button ist in allen Ansichten vorhanden jedoch bekomme ich immer die Fehlermeldung:
"error: cannot find symbol variable button2"
Egal ob ich "findViewById(R.id.button2);" im onCreate oder onClick Event verwende, jedesmal das selbe!
Zuerst erstelle ich eine Button Variable, dann versuche ich der Variable die ID vom Button zuzuweisen, aber klappt nicht..woran könnte es liegen?!?
C#-Quellcode
- /*
- * Copyright (C) The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- package com.google.android.gms.samples.vision.barcodereader;
- import android.content.Intent;
- import android.os.Bundle;
- import android.app.Activity;
- import android.util.Log;
- import android.view.View;
- import android.widget.Button;
- import android.widget.CompoundButton;
- import android.widget.TextView;
- import com.google.android.gms.common.api.CommonStatusCodes;
- import com.google.android.gms.vision.barcode.Barcode;
- /**
- * Main activity demonstrating how to pass extra parameters to an activity that
- * reads barcodes.
- */
- public class MainActivity extends Activity implements View.OnClickListener {
- // use a compound button so either checkbox or switch widgets work.
- private CompoundButton autoFocus;
- public static CompoundButton useFlash;
- private TextView statusMessage;
- private TextView barcodeValue;
- private Button okButton;
- private static final int RC_BARCODE_CAPTURE = 9001;
- private static final String TAG = "BarcodeMain";
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- statusMessage = findViewById(R.id.status_message);
- barcodeValue = findViewById(R.id.barcode_value);
- autoFocus = findViewById(R.id.auto_focus);
- useFlash = findViewById(R.id.use_flash);
- okButton = findViewById(R.id.button2); // Hier meckert er!!!
- findViewById(R.id.read_barcode).setOnClickListener(this);
- // bOK.setOnClickListener(this);
- }
- /**
- * Called when a view has been clicked.
- *
- * @param v The view that was clicked.
- */
- @Override
- public void onClick(View v) {
- if (v.getId() == R.id.read_barcode) {
- // launch barcode activity.
- Intent intent = new Intent(this, BarcodeCaptureActivity.class);
- // intent.putExtra(BarcodeCaptureActivity.AutoFocus, autoFocus.isChecked());
- intent.putExtra(BarcodeCaptureActivity.UseFlash, useFlash.isChecked());
- startActivityForResult(intent, RC_BARCODE_CAPTURE);
- okButton.setVisibility(View.VISIBLE);
- }
- }
Das gibt er mir noch inne Gradle Console:
C:\Users\Morrison\Desktop\android-vision-master\visionSamples\barcode-reader\app\src\main\java\com\google\android\gms\samples\vision\barcodereader\MainActivity.java:60: error: cannot find symbol
okButton = findViewById(button2);
^
symbol: variable button2
location: class MainActivity
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: C:\Users\Morrison\Desktop\android-vision-master\visionSamples\barcode-reader\app\src\main\java\com\google\android\gms\samples\vision\barcodereader\ui\camera\GraphicOverlay.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error
FAILED
:app:buildInfoGeneratorDebug
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.
* Get more help at help.gradle.org
BUILD FAILED in 1s
okButton = findViewById(button2);
^
symbol: variable button2
location: class MainActivity
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: C:\Users\Morrison\Desktop\android-vision-master\visionSamples\barcode-reader\app\src\main\java\com\google\android\gms\samples\vision\barcodereader\ui\camera\GraphicOverlay.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error
FAILED
:app:buildInfoGeneratorDebug
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.
* Get more help at help.gradle.org
BUILD FAILED in 1s
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „Morrison“ ()