2013-05-09 5 views
1

경고 대화 상자에 비트 맵 이미지를 표시하려고 할 때마다 문제가 발생합니다. 응용 프로그램이 강제로 닫히거나 "불행히도 blabla ..가 멈 춥니 다"라는 오류 메시지가 표시됩니다. 내 비트 맵 이미지로 any1이 도움이 될까요?경고 대화 상자에 비트 맵 이미지 표시 관련 문제

enter code here 



@Override 
public void onCreate(Bundle savedInstanceState) 
{ 
    super.onCreate(savedInstanceState); 
    this.setContentView(R.layout.marker_detail); 

    String valueretrievee=null; 



    //valueretrieve="2"; 




    //get the large image view 
    picView = (ImageView) findViewById(R.id.picture); 
    //get the gallery view 
    picGallery = (Gallery) findViewById(R.id.gallery); 

    //create a new adapter 
    imgAdapt = new PicAdapter(this); 
    //set the gallery adapter 
    picGallery.setAdapter(imgAdapt); 


    //set the click listener for each item in the thumbnail gallery 
    picGallery.setOnItemClickListener(new OnItemClickListener() { 
     //handle clicks 
     public void onItemClick(AdapterView<?> parent, View v, int position, long id) { 



      //set the larger image view to display the chosen bitmap calling method of adapter class 
      picView.setImageBitmap(imgAdapt.getPic(position)); 
      //start 

    AlertDialog.Builder alertadd = new AlertDialog.Builder(ARTAADAfterTouch.this); 
    //ImageView imageView = (ImageView) findViewById(R.id.picture); 


    ImageView imageView = (ImageView) findViewById(R.id.picture); 
    final Bitmap bitmap = Bitmap.createBitmap(imgAdapt.getPic(position)); 

    imageView.setImageBitmap(bitmap); 
    alertadd.setView(imageView); 
    alertadd.setPositiveButton("Yes", new DialogInterface.OnClickListener() 
    { 
     @Override 
     public void onClick(DialogInterface dialog, int which) { 
      finish();  
     } 
    }); 
    alertadd.setNegativeButton("No", null); 
    alertadd.show(); 

    //end 
    picView.setImageBitmap(bitmap); 
     } 
    }); 

} 

public void setData(String valueretrieve) 
{ 
    this.valueretrieve=valueretrieve; 
} 
public String getData() 
{ 
    return valueretrieve; 
} 

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


    if (resultCode == RESULT_OK) { 
     //check if we are returning from picture selection 
     if (requestCode == PICKER) { 
       //import the image 
     } 
    } 
    //superclass method 
    super.onActivityResult(requestCode, resultCode, data); 
    //the returned picture URI 

    Uri pickedUri = data.getData(); 
    //declare the bitmap 
    Bitmap pic = null; 
    //declare the path string 
    String imgPath = ""; 
    //retrieve the string using media data 
    String[] medData = { MediaStore.Images.Media.DATA }; 
    //query the data 
    Cursor picCursor = managedQuery(pickedUri, medData, null, null, null); 
    if(picCursor!=null) 
    { 
     //get the path string 
     int index = picCursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); 
     picCursor.moveToFirst(); 
     imgPath = picCursor.getString(index); 
    } 
    else 
     imgPath = pickedUri.getPath(); 

    //pass bitmap to ImageAdapter to add to array 
    imgAdapt.addPic(pic); 
    //redraw the gallery thumbnails to reflect the new addition 
    picGallery.setAdapter(imgAdapt); 

    //display the newly selected image at larger size 
    picView.setImageBitmap(pic); 
    //scale options 
    picView.setScaleType(ImageView.ScaleType.FIT_CENTER); 
} 





public class PicAdapter extends BaseAdapter 
{ 
    //use the default gallery background image 
    int defaultItemBackground; 
    //gallery context 
    private Context galleryContext; 
    //array to store bitmaps to display 
    private Bitmap[] imageBitmaps; 
    //placeholder bitmap for empty spaces in gallery 
    Bitmap placeholder; 


    //Intent ft= getIntent(); // gets the previously created intent 
    //String firstKeyName = ft.getStringExtra("firstKeyName"); // will return "FirstKeyValue" 



    public PicAdapter(Context c) { 
     //instantiate context 
     galleryContext = c; 






     //copy right by aaron yong -> OVER HERE 



     //String firstKeyName = intent.getStringExtra("firstKeyName"); // will return "SecondKeyValue" 
     //create bitmap array 
     imageBitmaps = new Bitmap[5]; 
     //decode the placeholder image 
     //placeholder = BitmapFactory.decodeResource(getResources(), R.drawable.hotel1); 
     //placeholder = BitmapFactory.decodeResource(getResources(), R.drawable.hotel2); 
     //more processing 



     //Intent intent = getIntent(); 
     //String valueretrieve = intent.getStringExtra("firstKeyName"); 



     //set placeholder as all thumbnail images in the gallery initially 
     for(int i=0; i<imageBitmaps.length; i++) 
     { 

      Bundle extras = getIntent().getExtras(); 
      if (extras != null) { 
       valueretrieve = extras.getString("myFirstKey"); 
      } 

      TextView theTextView = (TextView) findViewById(R.id.textView2); 
      theTextView.setText(valueretrieve); 

      //copy right by aaron yong ->> YESS! msut use equal!! 
      if(theTextView.getText().equals("1")) 
      { 
       imageBitmaps[0] = BitmapFactory.decodeResource(getResources(), R.drawable.shop1); 
       imageBitmaps[1] = BitmapFactory.decodeResource(getResources(), R.drawable.hotel1); 
      } 
      else if(theTextView.getText().equals("2")) 
      { 
       imageBitmaps[0] = BitmapFactory.decodeResource(getResources(), R.drawable.it1); 
       imageBitmaps[1] = BitmapFactory.decodeResource(getResources(), R.drawable.hotel2); 
      } 
      else if(theTextView.getText().equals("3")) 
      { 
       imageBitmaps[0] = BitmapFactory.decodeResource(getResources(), R.drawable.transport1); 
       imageBitmaps[1] = BitmapFactory.decodeResource(getResources(), R.drawable.transport2); 
      } 


      //imageBitmaps[0] = BitmapFactory.decodeResource(getResources(), R.drawable.hotel1); 
      //imageBitmaps[1] = BitmapFactory.decodeResource(getResources(), R.drawable.hotel2); 
      imageBitmaps[i]=placeholder; 
     } 






     //get the styling attributes - use default Andorid system resources 
     TypedArray styleAttrs = galleryContext.obtainStyledAttributes(R.styleable.PicGallery); 
     //get the background resource 
     defaultItemBackground = styleAttrs.getResourceId(
      R.styleable.PicGallery_android_galleryItemBackground, 0); 
     //recycle attributes 
     styleAttrs.recycle(); 
    } 


    //************************************************* 




    //return number of data items i.e. bitmap images 
    public int getCount() { 
     return imageBitmaps.length; 
    } 

    //return item at specified position 
    public Object getItem(int position) { 
     return position; 
    } 

    //return item ID at specified position 
    public long getItemId(int position) { 
     return position; 
    } 

    //get view specifies layout and display options for each thumbnail in the gallery 
    public View getView(int position, View convertView, ViewGroup parent) { 
     //create the view 
     ImageView imageView = new ImageView(galleryContext); 
     //specify the bitmap at this position in the array 
     imageView.setImageBitmap(imageBitmaps[position]); 
     //set layout options 
     imageView.setLayoutParams(new Gallery.LayoutParams(470, 400)); 
     //scale type within view area 
     imageView.setScaleType(ImageView.ScaleType.FIT_CENTER); 
     //set default gallery item background 
     imageView.setBackgroundResource(defaultItemBackground); 
     //return the view 
     return imageView; 
    } 

    //helper method to add a bitmap to the gallery when the user chooses one 
    public void addPic(Bitmap newPic) 
    { 
     //set at currently selected index 
     imageBitmaps[currentPic] = newPic; 
    } 

    //return bitmap at specified position for larger display 
    public Bitmap getPic(int posn) 
    { 
     //return bitmap at posn index 
     return imageBitmaps[posn]; 
    } 

} 

}

TXT 형식의 로그 캣 링크 : http://pastebin.com/4DSwxXx8

관련 로그 캣

05-10 00:22:24.867: E/AndroidRuntime(2276): FATAL EXCEPTION: main 
05-10 00:22:24.867: E/AndroidRuntime(2276): java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first. 
05-10 00:22:24.867: E/AndroidRuntime(2276):  at android.view.ViewGroup.addViewInner(ViewGroup.java:3339) 
05-10 00:22:24.867: E/AndroidRuntime(2276):  at android.view.ViewGroup.addView(ViewGroup.java:3210) 
05-10 00:22:24.867: E/AndroidRuntime(2276):  at android.view.ViewGroup.addView(ViewGroup.java:3186) 
05-10 00:22:24.867: E/AndroidRuntime(2276):  at com.android.internal.app.AlertController.setupView(AlertController.java:413) 
05-10 00:22:24.867: E/AndroidRuntime(2276):  at com.android.internal.app.AlertController.installContent(AlertController.java:241) 
05-10 00:22:24.867: E/AndroidRuntime(2276):  at android.app.AlertDialog.onCreate(AlertDialog.java:337) 
05-10 00:22:24.867: E/AndroidRuntime(2276):  at android.app.Dialog.dispatchOnCreate(Dialog.java:355) 
05-10 00:22:24.867: E/AndroidRuntime(2276):  at android.app.Dialog.show(Dialog.java:260) 
05-10 00:22:24.867: E/AndroidRuntime(2276):  at android.app.AlertDialog$Builder.show(AlertDialog.java:951) 
05-10 00:22:24.867: E/AndroidRuntime(2276):  at com.apu.ARTAAD.activity.ARTAADAfterTouch$1.onItemClick(ARTAADAfterTouch.java:123) 
05-10 00:22:24.867: E/AndroidRuntime(2276):  at android.widget.AdapterView.performItemClick(AdapterView.java:298) 
05-10 00:22:24.867: E/AndroidRuntime(2276):  at android.widget.Gallery.onSingleTapUp(Gallery.java:981) 
05-10 00:22:24.867: E/AndroidRuntime(2276):  at android.view.GestureDetector.onTouchEvent(GestureDetector.java:588) 
05-10 00:22:24.867: E/AndroidRuntime(2276):  at android.widget.Gallery.onTouchEvent(Gallery.java:958) 
05-10 00:22:24.867: E/AndroidRuntime(2276):  at android.view.View.dispatchTouchEvent(View.java:7246) 
05-10 00:22:24.867: E/AndroidRuntime(2276):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2168) 
05-10 00:22:24.867: E/AndroidRuntime(2276):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1903) 
05-10 00:22:24.867: E/AndroidRuntime(2276):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174) 
05-10 00:22:24.867: E/AndroidRuntime(2276):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917) 
05-10 00:22:24.867: E/AndroidRuntime(2276):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174) 
05-10 00:22:24.867: E/AndroidRuntime(2276):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917) 
05-10 00:22:24.867: E/AndroidRuntime(2276):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174) 
05-10 00:22:24.867: E/AndroidRuntime(2276):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917) 
05-10 00:22:24.867: E/AndroidRuntime(2276):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174) 
05-10 00:22:24.867: E/AndroidRuntime(2276):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917) 
05-10 00:22:24.867: E/AndroidRuntime(2276):  at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2090) 
05-10 00:22:24.867: E/AndroidRuntime(2276):  at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1417) 
05-10 00:22:24.867: E/AndroidRuntime(2276):  at android.app.Activity.dispatchTouchEvent(Activity.java:2410) 
05-10 00:22:24.867: E/AndroidRuntime(2276):  at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2038) 
05-10 00:22:24.867: E/AndroidRuntime(2276):  at android.view.View.dispatchPointerEvent(View.java:7426) 
05-10 00:22:24.867: E/AndroidRuntime(2276):  at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3220) 
05-10 00:22:24.867: E/AndroidRuntime(2276):  at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3165) 
05-10 00:22:24.867: E/AndroidRuntime(2276):  at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4292) 
05-10 00:22:24.867: E/AndroidRuntime(2276):  at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4271) 
05-10 00:22:24.867: E/AndroidRuntime(2276):  at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4363) 
05-10 00:22:24.867: E/AndroidRuntime(2276):  at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:179) 
05-10 00:22:24.867: E/AndroidRuntime(2276):  at android.os.MessageQueue.nativePollOnce(Native Method) 
05-10 00:22:24.867: E/AndroidRuntime(2276):  at android.os.MessageQueue.next(MessageQueue.java:125) 
05-10 00:22:24.867: E/AndroidRuntime(2276):  at android.os.Looper.loop(Looper.java:124) 
05-10 00:22:24.867: E/AndroidRuntime(2276):  at android.app.ActivityThread.main(ActivityThread.java:5195) 
05-10 00:22:24.867: E/AndroidRuntime(2276):  at java.lang.reflect.Method.invokeNative(Native Method) 
05-10 00:22:24.867: E/AndroidRuntime(2276):  at java.lang.reflect.Method.invoke(Method.java:511) 
05-10 00:22:24.867: E/AndroidRuntime(2276):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795) 
05-10 00:22:24.867: E/AndroidRuntime(2276):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562) 
05-10 00:22:24.867: E/AndroidRuntime(2276):  at dalvik.system.NativeStart.main(Native Method) 
enter code here 
+4

전체 스택 추적을 게시하십시오. – hardartcore

+1

은 아마도 메모리 문제 일 수 있습니다. 왜, 예를 들어 동일한 비트 맵을 두 번 만들었습니까? 최종 비트 맵 삽입 bitmap = Bitmap.createBitmap (imgAdapt.getPic (position)); 메서드의 시작 부분에서 setImageBitmap()에 사용합니다. – DigCamara

+0

어댑터 클래스의 선택한 비트 맵 호출 메서드를 표시하도록 큰 이미지보기를 설정합니다. picView.setImageBitmap (imgAdapt.getPic (position)) ; – DigCamara

답변

3

당신은 그것을 이름 (레이아웃 디렉토리에이 추가

final View alertDialog= factory.inflate(R.layout.alert_dialog, null); 
ImageView imageView= (ImageView) view 
       .findViewById(R.id.selectedImage); 
imageView.setImageBitmap(imgAdapt.getPic(position)); 

AlertDialog.Builder alertadd = new AlertDialog.Builder(ARTAADAfterTouch.this); 

alertadd.setView(alertDialog); 
alertadd.setPositiveButton("Yes", new DialogInterface.OnClickListener() 
{ 
    @Override 
    public void onClick(DialogInterface dialog, int which) { 
     finish();  
    } 
}); 
alertadd.setNegativeButton("No", null); 
alertadd.show(); 

로 변경해야하고,

final View view = factory.inflate(R.layout.image_view, null); 
      ImageView imageView = (ImageView) view 
        .findViewById(R.id.finalImage); 
      imageView.setImageBitmap(bitmap); 
      imageView.invalidate(); 

, 않습니다 "alert_dialog .xml ")

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:background="#FFFFFF" 
    tools:context=".MainActivity" > 

    <ImageView 
     android:id="@+id/selectedImage" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
    /> 
</RelativeLayout> 
+0

답장을 보내 주셔서 감사합니다.하지만 어쨌든 여전히 앱은 충돌합니다. 내 페이지에서 모든 코드를 편집하고 게시하십시오.보세요. – Aaron

+0

죄송합니다. 여기에 logcat을 게시하는 방법은 무엇입니까? 상자에 logcat을 붙여 넣지 만 너무 많아서 30000 단어 이상이면 여기에 txt 파일을 업로드 할 수 있습니까? – Aaron

+0

http://pastebin.com에 게시하고 여기에 링크를 붙여 넣으십시오. –

0

당신은 이미지 뷰를 무효화 시도해야 덕분에, 아래에있는 내 코드입니다.

이 시도 :

imageView.setImageBitmap(bitmap); 
imageView.invalidate(); 

잘 모르겠어요이 솔루션은 확실히 작동합니다.

하지만이 하나 image_view.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:background="#FFFFFF" 
    tools:context=".MainActivity" > 

    <ImageView 
     android:id="@+id/finalImage" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/checkBox" 
     android:src="@drawable/img" /> 
</RelativeLayout> 
+0

답장을 보내 주셔서 감사합니다. 하지만 그것은 나던 대화가 튀어 나오려고 시도 할 때마다 작동하지 않습니다. (실제로 충돌 이전에 튀어 나올 기회가 없습니다) ... – Aaron