2017-01-22 2 views
3

Der folgende Quellcode sollte ein Bild machen und auf dem Bildschirm anzeigen. Aber ich bekomme ein paar Fehler. Cannot resolve symbol 'activity_fullscreen', das gleiche für imageView1, dummy_button, fullscreen_content und fullscreen_content_controls.Warum erhalte ich einen Fehler: kann keine Symbolvariable in der R-Klasse finden

protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_fullscreen); 

     mVisible = true; 
     mControlsView = findViewById(R.id.fullscreen_content_controls); 
     mContentView = findViewById(R.id.fullscreen_content); 


     // Set up the user interaction to manually show or hide the system UI. 
     mContentView.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View view) { 
       toggle(); 
      } 
     }); 

     // Upon interacting with UI controls, delay any scheduled hide() 
     // operations to prevent the jarring behavior of controls going away 
     // while interacting with the UI. 
     findViewById(R.id.dummy_button).setOnTouchListener(mDelayHideTouchListener);//dummy abaendern 


     //super.onCreate(savedInstanceState); 
     //setContentView(R.layout.activity_fullscreen); 
     this.imageView = (ImageView)this.findViewById(R.id.imageView1); 
     Button photoButton = (Button) this.findViewById(R.id.dummy_button); 
     photoButton.setOnClickListener(new View.OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
       startActivityForResult(cameraIntent, CAMERA_REQUEST); 
      } 
     }); 


    } 

Das sind meine Importe:

import android.annotation.SuppressLint; 
import android.app.Activity; 
import android.graphics.Bitmap; 
import android.support.v7.app.ActionBar; 
import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import android.os.Handler; 
import android.view.MotionEvent; 
import android.view.View; 
import android.content.Intent; 
import android.widget.Button; 
import android.widget.ImageView; 
import android.R; 

Nun wollen wir auf jeden Fall an der activity_fullscreen.xml Die fehlenden Teile sind einen Blick.

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#0099cc" 
    tools:context="com.example.sasha.myapplication2.FullscreenActivity"> 

    <!-- The primary full-screen view. This can be replaced with whatever view 
     is needed to present your content, e.g. VideoView, SurfaceView, 
     TextureView, etc. --> 
    <TextView 
     android:id="@+id/fullscreen_content" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:gravity="center" 
     android:keepScreenOn="true" 
     android:text="@string/dummy_content" 
     android:textColor="#33b5e5" 
     android:textSize="50sp" 
     android:textStyle="bold" /> 

    <!-- This FrameLayout insets its children based on system windows using 
     android:fitsSystemWindows. --> 
    <FrameLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:fitsSystemWindows="true"> 

     <LinearLayout 
      android:id="@+id/fullscreen_content_controls" 
      style="?metaButtonBarStyle" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="bottom|center_horizontal" 
      android:background="@color/black_overlay" 
      android:orientation="horizontal" 
      tools:ignore="UselessParent"> 

      <Button 
       android:id="@+id/dummy_button" 
       style="?metaButtonBarButtonStyle" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:text="@string/dummy_button" /> 
      <ImageView android:id="@+id/imageView1" android:layout_height="wrap_content" android:src="@drawable/icon" android:layout_width="wrap_content"></ImageView> 

     </LinearLayout> 
    </FrameLayout> 

</FrameLayout> 

Ich habe bereits die Empfehlungen in the following answer. Soweit ich sehen kann, enthält der Name keine illegalen Zeichen. Ich habe auch schon das android Studio neu gestartet, indem ich Datei -> Caches/Cache neu starten ... starte.

Aber ich habe immer noch keine Lösung für meine Probleme gefunden. Wie ist es möglich, dass R aufgelöst werden kann, aber nicht sein Inhalt? Irgendwelche Ideen sind willkommen. Danke

+0

Haben Sie sich [diese Frage] (http://stackoverflow.com/questions/27312897/android-flavor-cannot-find-symbol-variable-in-r-file)? –

+0

Warum ist das hilfreich? Ich habe nur einen Button und einen ItemView –

+0

Sie rufen 'findViewById (R.id.some_name_here);' –

Antwort

5

Sie importiert die falsche 'R'

entfernen diese:

import android.R; 

hinzufügen:

import com.yourCompany.yourApp.R; 
+0

Interessante Lösung. Obwohl Eclipse den Import als unbenutzt markiert, scheint es zu funktionieren. Vielen Dank –

-1

Sie müssen die R-Datei nicht importieren. Dadurch wird das Umwandeln der R.Activity-Datei entfernt. Bereinigen Sie das Projekt, um den Fehler zu entfernen.

+0

fertig, nichts geändert! –

0

verwenden diese die Zuordnung Ihrer Anwendung zu importieren.

import com.example.sasha.myapplication2.R; 
Verwandte Themen