2016-04-18 9 views
0

Ich versuche meine Kamera über eine Absicht zu öffnen und das resultierende Bild als Bitmap zu speichern. Wenn Sie dann in Google Maps auf eine Markierung klicken, möchte ich diese Bitmap in ein anderes Layout übertragen, das zum Auffüllen eines Popup-Fensters im Hauptlayout der Aktivitäten verwendet wird.ImageView als Bitmap im layoutflator Container setzen

Allerdings erhalte ich die Fehlermeldung: „java.lang.NullPointerException: Der Versuch, auf einer Null-Objekt Referenz virtuelle Methode‚Leeren android.widget.ImageView.setImageBitmap (android.graphics.Bitmap)‘aufzurufen“

Hier sind Teile meines Codes:

MainActivity:

@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 

    // if the action was to capture a picture, then store all relevant data in the database 
    if (requestCode == 1) { 
     if (resultCode == RESULT_OK) { 
      Toast.makeText(this, "Picture Received"/*data.getData().toString()*/, Toast.LENGTH_SHORT).show(); 

      Bundle extras = data.getExtras(); 
      imageBitmap = (Bitmap) extras.get("data"); 
      //imageView.setImageBitmap(imageBitmap); 
     } 
    } 
} 


@Override 
public boolean onMarkerClick(Marker marker) { 

    layoutInflator = (LayoutInflater) getApplicationContext().getSystemService(LAYOUT_INFLATER_SERVICE); 
    ViewGroup container = (ViewGroup) layoutInflator.inflate(R.layout.imagecontainer, null); 

    ImageView image = (ImageView) findViewById(R.id.imageView); 
    image.setImageBitmap(imageBitmap); 

    popUpWindow = new PopupWindow(container, 800, 1220, true); 
    popUpWindow.setBackgroundDrawable(new BitmapDrawable()); 
    popUpWindow.setOutsideTouchable(true); 
    popUpWindow.showAtLocation(relativeLayout, Gravity.CENTER, Gravity.CENTER_HORIZONTAL, Gravity.CENTER_VERTICAL); 

    return false; 
} 

imagecontainer.xml:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#FFFFFF" 
    android:id="@+id/imageContainer"> 

    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/imageView" 
     android:layout_gravity="top|center_horizontal" /> 
</LinearLayout> 

Antwort

0

Meinen Sie (verpasste Container?):

ImageView image = (ImageView) container.findViewById(R.id.imageView); 
+0

Thank you! Ich habe vergessen, "Container" in den Vordergrund zu stellen. – rgins16

Verwandte Themen