2013-03-11 128 views
0

編輯:我想通了什麼錯了,就像我說過的,我將包名從com.musicbynumbers.pianoscales更改爲com.musicbynumbers.pianoscalesfull。但我忘了Android:圖片不顯示在照片顯示中活動

change int id =getResources().getIdentifier("com.musicbynumbers.pianoscalesfull:drawable/" + gotScale, null, null);

所有的代碼是好的。非常感謝你的幫助。

好的,這只是一些beckground信息,然後才進入確切的問題: 我正在使用eclipse。幾個星期前,我在遊戲商店發佈了我的第一款應用程序 - 鋼琴秤應用程序,並獲得了許可。兩天前,我意識到許可證阻止了一些支付應用程序的用戶使用它。我評論了許可,並去了更新,但我的密鑰庫已損壞。所以我從商店中刪除了應用程序並更改了軟件包名稱。該應用程序是一個菜單,可以顯示所選圖像的顯示Activity。當我再次測試應用程序時,我發現只顯示默認的Android圖像。我不認爲我改變了子菜單中的任何代碼或顯示活動,因爲它正在工作,但我仍然會把它們放在一起。順便說一下,這是我的第一個應用程序,該應用程序將在明天發佈,並隨附一本書,因此對我來說這是一個真正的第11個小時的情況。

這是幾個子菜單中的一個通向活動「顯示」

package com.musicbynumbers.scales; 



import android.os.Bundle; 
import android.app.Activity; 
import android.content.Intent; 
import android.graphics.PixelFormat; 
import android.view.View; 
import android.view.WindowManager; 
import android.widget.Button; 
import android.widget.ImageButton; 
import com.musicbynumbers.pianoscalesfull.R; 

public class majorScales extends Activity implements View.OnClickListener { 
    Button aflatmaj, amaj, bflatmaj, bmaj, cmaj, dflatmaj, dmaj, eflatmaj, emaj, fmaj, fsharpmaj, gmaj; 
    ImageButton mainMenu; 
    Intent j; 
    String scaleName; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     // TODO Auto-generated method stub 
     super.onCreate(savedInstanceState); 
     getWindow().setFormat(PixelFormat.RGBA_8888); 
     getWindow().addFlags(WindowManager.LayoutParams.FLAG_DITHER); 
     setContentView(R.layout.majorscales); 
     j = new Intent(this, display.class); 
     mainMenu = (ImageButton) findViewById(R.id.imagelogo); 
     aflatmaj = (Button) findViewById(R.id.aflatmajb); 
     amaj = (Button) findViewById(R.id.amajb); 
     bflatmaj = (Button) findViewById(R.id.bflatmajb); 
     bmaj = (Button) findViewById(R.id.bmajb); 
     cmaj = (Button) findViewById(R.id.cmajb); 
     dflatmaj = (Button) findViewById(R.id.dflatmajb); 
     dmaj = (Button) findViewById(R.id.dmajb); 
     eflatmaj = (Button) findViewById(R.id.eflatmajb); 
     emaj = (Button) findViewById(R.id.emajb); 
     fmaj = (Button) findViewById(R.id.fmajb); 
     fsharpmaj = (Button) findViewById(R.id.fsharpmajb); 
     gmaj = (Button) findViewById(R.id.gmajb); 
     mainMenu.setOnClickListener(this); 
     aflatmaj.setOnClickListener(this); 
     amaj.setOnClickListener(this); 
     bflatmaj.setOnClickListener(this); 
     bmaj.setOnClickListener(this); 
     cmaj.setOnClickListener(this); 
     dflatmaj.setOnClickListener(this); 
     dmaj.setOnClickListener(this); 
     eflatmaj.setOnClickListener(this); 
     emaj.setOnClickListener(this); 
     fmaj.setOnClickListener(this); 
     fsharpmaj.setOnClickListener(this); 
     gmaj.setOnClickListener(this); 



    } 






     @Override 
      public void onClick(View arg0) { 
       // TODO Auto-generated method stub 
       switch(arg0.getId()){ 
       case R.id.imagelogo: 
        Intent i = new Intent(majorScales.this, MainMenu.class); 
        startActivity(i); 
        break; 
       case R.id.aflatmajb: 
        scaleName = "aflatmaj"; 
        j.putExtra("key", scaleName); 

        startActivity(j); 
        break; 
       case R.id.amajb: 
        scaleName = "amaj"; 
        j.putExtra("key", scaleName); 
        startActivity(j); 
        break; 
       case R.id.bflatmajb: 
        scaleName = "bflatmaj"; 
        j.putExtra("key", scaleName); 
        startActivity(j); 
        break; 
       case R.id.bmajb: 
        scaleName = "bmaj"; 
        j.putExtra("key", scaleName); 
        startActivity(j); 
        break; 
       case R.id.cmajb: 
        scaleName = "cmaj"; 
        j.putExtra("key", scaleName); 
        startActivity(j); 
        break; 
       case R.id.dflatmajb: 
        scaleName = "dflatmaj"; 
        j.putExtra("key", scaleName); 
        startActivity(j); 
        break; 
       case R.id.dmajb: 
        scaleName = "dmaj"; 
        j.putExtra("key", scaleName); 
        startActivity(j); 
        break; 
       case R.id.eflatmajb: 
        scaleName = "eflatmaj"; 
        j.putExtra("key", scaleName); 
        startActivity(j); 
        break; 
       case R.id.emajb: 
        scaleName = "emaj"; 
        j.putExtra("key", scaleName); 
        startActivity(j); 
        break; 
       case R.id.fmajb: 
        scaleName = "fmaj"; 
        j.putExtra("key", scaleName); 
        startActivity(j); 
        break; 
       case R.id.fsharpmajb: 
        scaleName = "fsharpmaj"; 
        j.putExtra("key", scaleName); 
        startActivity(j); 
        break; 
       case R.id.gmajb: 
        scaleName = "gmaj"; 
        j.putExtra("key", scaleName); 
        startActivity(j); 
        break; 




    } 

} 
} 

這是顯示所選擇的圖像,但只有現在正在顯示默認的顯示活動。

package com.musicbynumbers.scales; 

import android.app.Activity; 
import android.os.Bundle; 
import android.widget.ImageView; 
import com.musicbynumbers.pianoscalesfull.R; 


public class display extends Activity { 

    ImageView displayScale; 
    String gotScale; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     // TODO Auto-generated method stub 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.display); 
     Initalize(); 
     gotScale = getIntent().getStringExtra("key"); 
     ImageView displayScale = (ImageView) findViewById(R.id.displayImage); 
     //aflatmaj-gotscale 
     int id = getResources().getIdentifier("com.musicbynumbers.pianoscales:drawable/" + gotScale, null, null); 
     displayScale.setImageResource(id); 

    } 

    private void Initalize() { 
     // TODO Auto-generated method stub 
     displayScale = (ImageView) findViewById(R.id.displayImage); 
     gotScale = "ic_launcher.png"; 

    }} 

我真的很感激任何幫助,因爲我沒有時間了。

編輯:

的logcat:

03-11 18:38:00.194: I/ActivityManager(59): Starting activity: Intent { cmp=com.musicbynumbers.pianoscalesfull/com.musicbynumbers.scales.majorScales } 
03-11 18:38:00.824: W/ActivityManager(59): Activity pause timeout for HistoryRecord{45f03618 com.musicbynumbers.pianoscalesfull/com.musicbynumbers.scales.MainMenu} 
03-11 18:38:03.284: I/ActivityManager(59): Displayed activity com.musicbynumbers.pianoscalesfull/com.musicbynumbers.scales.majorScales: 2454 ms (total 2454 ms) 
03-11 18:38:07.854: I/ActivityManager(59): Starting activity: Intent { cmp=com.musicbynumbers.pianoscalesfull/com.musicbynumbers.scales.display (has extras) } 
03-11 18:38:08.234: I/WindowManager(59): Setting rotation to 1, animFlags=1 
03-11 18:38:08.404: I/ActivityManager(59): Config changed: { scale=1.0 imsi=310/260 loc=en_US touch=3 keys=2/1/2 nav=3/1 orien=2 layout=18 uiMode=17 seq=32} 
03-11 18:38:09.616: I/ActivityManager(59): Displayed activity com.musicbynumbers.pianoscalesfull/com.musicbynumbers.scales.display: 1384 ms (total 1384 ms) 
03-11 18:38:13.123: D/dalvikvm(59): GC_EXPLICIT freed 3329 objects/183760 bytes in 462ms 

回答

0

我不明白這一點:

在顯示活動,您有:ImageView displayScale;開頭聲明,然後你再次聲明:ImageView displayScale = (ImageView) findViewById(R.id.displayImage);

而這個問題主要是因爲你得到了Initalize();去那裏。

,如果你說你不reciving什麼,但默認的Android圖像,然後明確

gotScale = getIntent().getStringExtra("key"); 

沒有工作,所有剩下的就是在:gotScale = "ic_launcher.png";從初始化。

嘗試在獲取圖像之前立即記錄gotScale參數,具體取決於該參數以瞭解它的含義。

編輯:

要登錄:

Log.d( 「ActivityName」, 「你要顯示的信息」);

並使用cmd監視您的logcat以查看日誌消息。

,或者你可以總是顯示舉杯,看看有什麼是gotScale內容。

+0

我看到,Iv'e改變第二個在OnCreate到displayScale =(ImageView的)findViewById(R.id.displayImage);並即時測試它在模擬器上 – 2013-03-11 18:17:42

+0

剛剛嘗試過,它仍然只是顯示默認圖像。 – 2013-03-11 18:19:39

+0

查看更新的答案。 – 2013-03-11 18:20:41

0

我還沒有測試過我的代碼。所以你可以把它當作一個建議。在檢查你的代碼後,似乎

int id = getResources().getIdentifier("com.musicbynumbers.pianoscales:drawable/" + gotScale, null, null); 
     displayScale.setImageResource(id);
看起來很奇怪。你能記錄返回的標識符並驗證它嗎?

//一個很好的替代,你甚至可以嘗試。 //獲取圖標


    String uri = "drawable/"+gotScale; 
int id = getResources().getIdentifier(uri, "drawable", getPackageName()); // your res id. 
希望這將幫助你節省一些時間。 :)

+0

是否有任何需要進入「drawable」的東西,還是隻剩下那樣。這看起來很明顯,但我相對較新。並且記錄標識符是否意味着複製日誌貓的那一部分? – 2013-03-11 18:37:24

+0

是否需要進入「可繪製」狀態?還是僅僅是這樣。這看起來很明顯,但我相對較新。並且記錄標識符是否意味着複製日誌貓的那一部分? – 2013-03-11 18:45:33

+0

我將logcat添加到主要問題 – 2013-03-11 18:48:47