0

编辑:我想出了什么问题,就像我说我将包名更改为 from com.musicbynumbers.pianoscalesto com.musicbynumbers.pianoscalesfull。但我忘了

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

所有的代码都很好。非常感谢你的帮助。

好的,这只是在我进入确切问题之前的一些背景信息:我正在使用 eclipse。几周前,我在 Play Store 上发布了我的第一个应用程序,一个钢琴音阶应用程序,获得了许可。两天前,我意识到许可阻止了一些为该应用程序付费的用户使用它。我注释掉了许可并进行了更新,但我的密钥库已损坏。所以我从商店中删除了应用程序并更改了包名称。该应用程序是一个菜单,可将您带到显示所选图像的显示活动。当我再次测试应用程序时,我发现只显示默认的 android 图像。我不认为我更改了子菜单或显示活动中的任何代码,因为它正在工作,但无论如何我都会把它们放上去。顺便说一句,这是我的第一个应用程序,该应用程序预定明天随书一起发布,

这是导致活动“显示”的几个子菜单之一

    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";

    }}

我真的很感激任何帮助,因为我的时间不多了。

编辑:

日志猫:

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
4

2 回答 2

0

I don't get it:

In the display activity you have: ImageView displayScale; declared at the beginning and then you declare it again: ImageView displayScale = (ImageView) findViewById(R.id.displayImage);

And this a problem mainly among other reason becaouse you got the Initalize(); going on there.

if you are saying that you are not reciving anything but the default android image then clearly

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

not working and all what's left is the: gotScale = "ic_launcher.png"; from the initialization.

Try to log the gotScale parameter right before you get the image depending on it to see what it holds.

EDIT:

To log:

Log.d("ActivityName", "The message you want to show");

and monitor your logcat using the cmd to see the log message.

or you can always show a toast to see what is the content of gotScale.

于 2013-03-11T18:12:23.450 回答
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.
希望这可以帮助您节省一些时间。:)

于 2013-03-11T18:16:21.717 回答