0

我想意圖imageview到新的活動。我的imageview使用xmlparser。但我的應用程序強制關閉,如果我點擊imageview。我想意圖imageview

這是我的代碼:

Intent in = getIntent(); 
Bundle bun = in.getExtras(); 

//Get XML values from previous intent 
String headline = bun.getString(KEY_HEADLINE); 
String date = bun.getString(KEY_ARTICLEDATE); 
String Body = bun.getString(KEY_BODY); 
//String image = bun.getString(KEY_IMAGEURL); 
Bitmap image = (Bitmap) bun.getParcelable(KEY_IMAGEURL); 
    WebView browser = (WebView)findViewById(R.id.webView1); 

String HTML = ......................; 
browser.loadData(HTML, "text/html", "utf-8"); 

這是logcat的我的應用程序

  12-16 16:10:46.017: E/dalvikvm(19543): GC_FOR_ALLOC freed 1537K, 19% free 10221K/12579K, paused 4ms+5ms 
      12-16 16:10:46.017: I/dalvikvm-heap(19543): Grow heap (frag case) to 10.719MB for 660976-byte allocation 
      12-16 16:10:46.064: E/dalvikvm(19543): GC_FOR_ALLOC freed <1K, 19% free 10866K/13283K, paused 2ms+2ms 
      12-16 16:10:46.118: D/webviewglue(19543): nativeDestroy view: 0x9683f0 
      12-16 16:10:46.126: D/webhistory(19543): Writing Form data else {} Tag 
      12-16 16:10:46.126: D/webhistory(19543): Writing Form data else {} Tag 
      12-16 16:10:46.173: I/dalvikvm(19602): Turning on JNI app bug workarounds for target SDK version 8... 
+0

你的初始化你的'thumb_image'在你的點擊事件中。發佈完整的logcat。 – Hariharan

+0

這是我的完整logcat – user3086099

+0

試試我的答案,你可以得到它。 – Hariharan

回答

0

避免這種buildDrawingCache()方法 根據機器人

thumb_image.setOnClickListener(new View.OnClickListener() 
     { 
      public void onClick(View v) 
      { 
       String title = ((TextView) findViewById(R.id.textURL)).getText().toString(); 
       String date = ((TextView) findViewById(R.id.dateURL)).getText().toString(); 
       String body = ((TextView) findViewById(R.id.bodyURL)).getText().toString(); 
       ImageView thumb_image=(ImageView)findViewById(R.id.ImageURL); // thumb image 
       thumb_image.buildDrawingCache(); 
       Bitmap image= thumb_image.getDrawingCache(); 
        Bundle extras = new Bundle(); 
       extras.putParcelable(KEY_IMAGEURL, image); 
       // Starting new intent 
       Intent i = new Intent(getApplicationContext(), SingleMenuItemActivity.class); 
       i.putExtra(KEY_HEADLINE, title); 
       i.putExtra(KEY_ARTICLEDATE, date); 
       i.putExtra(KEY_BODY,body); 
       i.putExtras(extras); 

       startActivity(i); 

我的singlemenuactivity代碼開發者文檔

Build Drawing Cache

調用此方法將增加內存使用並導致視圖在軟件中呈現一次,從而對性能產生負面影響。 嘗試另一種方法來傳遞另一個活動圖像URL或圖像數據

0

試試這個..

更改您的位圖codeing這樣的..

BitmapDrawable bitmapDrawable = ((BitmapDrawable) thumb_image.getDrawable()); 
Bitmap bitmap1 = bitmapDrawable .getBitmap();  

thumb_image.setOnClickListener(new View.OnClickListener() 
     { 
      public void onClick(View v) 
      { 
       String title = ((TextView) findViewById(R.id.textURL)).getText().toString(); 
       String date = ((TextView) findViewById(R.id.dateURL)).getText().toString(); 
       String body = ((TextView) findViewById(R.id.bodyURL)).getText().toString(); 
       BitmapDrawable bitmapDrawable = ((BitmapDrawable) thumb_image.getDrawable()); 
       Bitmap image = bitmapDrawable.getBitmap();  
       Bundle extras = new Bundle(); 
       extras.putParcelable(KEY_IMAGEURL, image); 
       // Starting new intent 
       Intent i = new Intent(this, SingleMenuItemActivity.class); 
       i.putExtra(KEY_HEADLINE, title); 
       i.putExtra(KEY_ARTICLEDATE, date); 
       i.putExtra(KEY_BODY,body); 
       i.putExtras(extras); 

       startActivity(i); 
      } 
}); 
+0

我的應用仍然強制關閉@Tamilan – user3086099

+0

@ user3086099發佈您的logcat錯誤。 – Hariharan

+0

@ user3086099'SingleMenuItemActivity.java'中的行號** 33 **是什麼,並且在那個類中發佈 – Hariharan