0

さて、アプリを動作させるのに問題があります。基本的に、私はユーザーからいくつかの写真と文字列を取得する必要があるゲームを持っています。メニュー(MenuScreen)を開くスプラッシュ画面として機能する開始画面(OpeningScreen)があります。そこから、ユーザーはゲームに移動するか、現在の写真を表示するアクティビティ(PickScreen)に移動するかを選択できます。ユーザーはそのアクティビティに移動し、そこから別のアクティビティを開いて、現在選択している画像の拡大版またはデフォルトの画像(PicOne)を表示できます。ここで、ユーザーは新しい写真を撮り、現在の文字列を変更するオプションがあります。ほとんどの場合、すべてがうまく機能します。私の問題は次の場合に発生します:

ユーザーが写真を選択してアプリを終了した後。次に開いたときに、PickScreenに戻ったとき、または新しい写真を撮った後に[完了]を押した後、場合によってはPicOneアクティビティに移動したときに、強制的に閉じます。毎回同じことをするわけではなく、それらのポイントの1つでクラッシュするだけです。

3つの文字列名を変更すると、もう1つの問題が発生します。保存を押してPickScreenに戻った後、PicOneに戻るときにアプリがクラッシュするか、アプリを終了するとMenuScreenからPickScreenに戻るときにクラッシュします。

これは見るべきコードがたくさんあることは知っていますが、私はこのアプリのさまざまな場所からコードを探して取得するのに多くの時間を費やしており、理解できない段階にあります。私より知識のある人が多いと思いますので、よろしくお願いします。何か仕事をしていることを示さずに質問することはできないことを私は知っているので、ここにあります。

アプリが一度は完全に機能し、その後、2回目にさまざまな場所でクラッシュするのはなぜですか?ちなみに、力を閉じた後も、1回だけ正常に機能します。また、文字列を変更すると、なぜ強制的に閉じるのですか?

みんな、ありがとう!!

PicOneクラス

public class PicOne extends Activity implements OnClickListener {
ImageView iv;
EditText c1, c2, c3;
Button cam, save;
Bitmap bit, bmp,other;
Intent i;
Uri uriSavedImage;
String imageFilePath10 = "", name1="", name2="", name3="";
final static int cameraData = 0; 
boolean CAMERA;
int camORgal10 = 0;
SharedPreferences gameData;

    @Override
    protected void onCreate(Bundle savedInstanceState)  {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.picone);
        CAMERA = false;
        iv = (ImageView)findViewById(R.id.picIV);
        cam = (Button)findViewById(R.id.camButton);
        save = (Button)findViewById(R.id.savebut);
        e1 = (EditText)findViewById(R.id.Enter1);
        e2 = (EditText)findViewById(R.id.Enter2);
        e3 = (EditText)findViewById(R.id.Enter3);

        cam.setOnClickListener(this);
        save.setOnClickListener(this);
}
    public void onClick(View v) {
        // TODO Auto-generated method stub
        switch(v.getId())
        {
        //camera
        case R.id.camButton:
            camORgal10 = 1;
            i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);               
            File imagesFolder = new File(Environment.getExternalStorageDirectory(), "MySpot"); 
            imagesFolder.mkdirs(); // <---- 
            String fileName = "image_1.PNG"; 
            File output = new File(imagesFolder, fileName);             
            uriSavedImage = Uri.fromFile(output);         
            i.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);
            i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivityForResult(i, cameraData);
            break;

        case R.id.savebut:
            CAMERA = true;
            name1 = e1.getText().toString();
            name2 = e2.getText().toString();
            name3 = e3.getText().toString();
            SharedPreferences.Editor editor = gameData.edit();
            editor.putInt("NUM10CAMGAL", camORgal10);
            editor.putString("NUM10NAME1", name1);
            editor.putString("NUM10NAME2", name2);
            editor.putString("NUM10NAME3", name3);
            editor.commit();
            Intent goPT = new Intent(this, PickScreen.class);
            goPT.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            goPT.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
            finish();
            startActivity(goPT);                
            break;

        }
    }

    public boolean onKeyDown(int keyCode, KeyEvent event)
    {
        if(keyCode == KeyEvent.KEYCODE_BACK)
        {
            CAMERA = true;
            name1 = e1.getText().toString();
            name2 = e2.getText().toString();
            name3 = e3.getText().toString();
            SharedPreferences.Editor editor = gameData.edit();
            editor.putInt("NUM10CAMGAL", camORgal10);
            editor.putString("NUM10NAME1", name1);
            editor.putString("NUM10NAME2", name2);
            editor.putString("NUM10NAME3", name3);
            editor.commit();
            Intent goPT = new Intent(this, PickScreen.class);
            goPT.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            goPT.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
            finish();
            startActivity(goPT);

            return true;
        }
        return super.onKeyDown(keyCode, event);
    }   

    @Override
    protected void onActivityResult(int requestCode, int resultCode,
            Intent data) {
        // TODO Auto-generated method stub
        super.onActivityResult(requestCode, resultCode, data);
        if(requestCode == cameraData)     
        {         
            if(resultCode == RESULT_OK && data.hasExtra("data"))         
            {             
                    bmp = (Bitmap) data.getExtras().get("data");
                    iv.setImageBitmap(bmp); 



            }         
            else if (resultCode == RESULT_CANCELED)        
            {            
                Toast.makeText(getApplicationContext(), "Cancelled",Toast.LENGTH_SHORT).show();    
            }      
        }


      }



    @Override
    protected void onPause() {
        // TODO Auto-generated method stub

        super.onPause();

    }

    @Override
    protected void onResume() {
        // TODO Auto-generated method stub


        if(OpeningScreen.isEXIT)
        {
            finish();
        }
        gameData = getSharedPreferences(MenuScreen.MYFOLDER, 0);
        name1 = slotData.getString("NUM10NAME1", "one");
        name2 = slotData.getString("NUM10NAME2", "two");
        name3 = slotData.getString("NUM10NAME3", "three");
        e1.setText(name1);
        e2.setText(name2);
        e3.setText(name3);
        camORgal10 = gameData.getInt("NUM10CAMGAL", 0);
        if(camORgal10 == 0)
        {
            bit = BitmapFactory.decodeResource(getResources(), R.drawable.red);
        }
        else if(camORgal10 == 1)
        {
            File imgFile = new File(Environment.getExternalStorageDirectory() + "/MySpot/image_1.PNG");
            if(imgFile.exists())
            {
               bit = BitmapFactory.decodeFile(imgFile.getAbsolutePath());   
            }
            else
            {
                bit = BitmapFactory.decodeResource(getResources(), R.drawable.red);
            }
        }

        else
        {
            bit = BitmapFactory.decodeResource(getResources(), R.drawable.red);
        }           
        iv.setImageBitmap(bit);
        super.onResume();
    }
}

OpeningScreen

public class OpeningScreen extends Activity {
/** Called when the activity is first created. */
 public static boolean isEXIT = false;

@Override   
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    isEXIT = false;
    Thread timer = new Thread(){
        public void run(){
            try{
                sleep(2500);
            } catch(InterruptedException e){

            } finally{
                Intent toMenu = new Intent(getApplicationContext(), MenuScreen.class);
                toMenu.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                //toMenu.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
                finish();
                startActivity(toMenu);                  
            }               
        }
    };
    timer.start();
}

@Override
protected void onPause() {
    // TODO Auto-generated method stub
    finish();
    super.onPause();        
}

@Override
protected void onResume() {
    // TODO Auto-generated method stub
    if(isEXIT)
    {
        finish();
    }

    super.onResume();
}    
}

MenuScreen

public class MenuScreen extends Activity implements OnClickListener {
float x,y;
int camORgal = 0;
ImageButton play, edit, more;
Intent i;
public static String MYFOLDER = "GAMEDATA";
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.menu);
    play = (ImageButton)findViewById(R.id.IBplay);
    edit = (ImageButton)findViewById(R.id.IBedit);
    more = (ImageButton)findViewById(R.id.IBmore);
    play.setOnClickListener(this);
    edit.setOnClickListener(this);
    more.setOnClickListener(this);
}

public boolean onKeyDown(int keyCode, KeyEvent event)
{
    if(keyCode == KeyEvent.KEYCODE_BACK)
    {
        OpeningScreen.isEXIT = true;
        finish();
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

public void onClick(View v) {
    // TODO Auto-generated method stub
    switch(v.getId())
    {
    case R.id.IBplay:
        i = new Intent(getApplicationContext(), TheGame.class);
        i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        finish();
        startActivity(i);           
        break;
    case R.id.IBedit:
        i = new Intent(this, PickScreen.class);
        i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        finish();
        startActivity(i);           
        break;
    case R.id.IBmore:

        break;
    }
}

}

PickScreen

public class PickScreen extends Activity implements OnClickListener {
Button bPic1, bPic2, bPic3;
ImageView ivpic3,ivpic2, ivpic1;
TextView TVpic3a, TVpic3b, TVpic3c, TVpic2a, TVpic2b, TVpic2c, TVpic1a, TVpic1b, TVpic1c;
Intent pageMove;
SharedPreferences gameData;
int camORgal10 = 0;
String threeNamea = "", threeNameb = "", threeNamec = "", twoNamea = "", twoNameb = "", twoNamec = "", oneNamea = "", oneNameb = "", oneNamec = "";

Bitmap bmp1, bmp2,bmp3;
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.paytable);
                intitializeThings();        
}


public void intitializeThings()
{
    bPic1 = (Button)findViewById(R.id.pic1but);
    bPic2 = (Button)findViewById(R.id.pic2but);
    bPic3 = (Button)findViewById(R.id.pic3but);
    ivpic3 = (ImageView)findViewById(R.id.ivpic3a);
    ivpic2 = (ImageView)findViewById(R.id.ivpic2a);
    ivpic1 = (ImageView)findViewById(R.id.ivpic1a);
    TVpic3a = (TextView)findViewById(R.id.pic3TVa);
    TVpic3b = (TextView)findViewById(R.id.pic3TVb);
    TVpic3c = (TextView)findViewById(R.id.pic3TVc);
    TVpic2a = (TextView)findViewById(R.id.pic2TVa);
    TVpic2b = (TextView)findViewById(R.id.pic2TVb);
    TVpic2c = (TextView)findViewById(R.id.pic2TVc);
    TVpic1a = (TextView)findViewById(R.id.pic1TVa);
    TVpic1b = (TextView)findViewById(R.id.pic1TVb);
    TVpic1c = (TextView)findViewById(R.id.pic1TVc);


    bPic1.setOnClickListener(this);
    bPic2.setOnClickListener(this);
    bPic3.setOnClickListener(this);
}

public void onClick(View v) {
    // TODO Auto-generated method stub
    switch(v.getId())
    {
    case R.id.pic1but:
        pageMove = new Intent(getApplicationContext(), PicOne.class);
        pageMove.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        pageMove.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        //pageMove.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
        finish();
        startActivity(pageMove);

        break;
    case R.id.pic2but:
        pageMove = new Intent(getApplicationContext(), PicTwo.class);
        pageMove.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        //pageMove.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
        startActivity(pageMove);
        finish();
                          break;
    case R.id.pic3but:
        pageMove = new Intent(getApplicationContext(), PicThree.class);
        pageMove.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        //pageMove.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
        startActivity(pageMove);
        finish();   
                          break;            
    }
}

public boolean onKeyDown(int keyCode, KeyEvent event)
{
    if(keyCode == KeyEvent.KEYCODE_BACK)
    {
        Intent goOP = new Intent(this, MenuScreen.class);
        goOP.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        goOP.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        finish();
        startActivity(goOP);

        return true;
    }
    return super.onKeyDown(keyCode, event);
}


@Override
protected void onPause() {
    // TODO Auto-generated method stub
    super.onPause();

}

@Override
protected void onResume() {
    // TODO Auto-generated method stub
    super.onResume();   


        gameData = getSharedPreferences(MenuScreen.MYFOLDER, 0);
        oneNamea = gameData.getString("NUM10NAME1", "one");
        oneNameb = gameData.getString("NUM10NAME2", "two");
        oneNamec = gameData.getString("NUM10NAME3", "three");
        camORgal10 = gameData.getInt("NUM10CAMGAL", 0);


        if(camORgal10 == 1)
        {
            File pic1 = new File(Environment.getExternalStorageDirectory() + "/MySpot/image_1.PNG");
            if(pic1.exists())
            {
                bmp1 = BitmapFactory.decodeFile(pic1.getAbsolutePath());
            }
            else
            {
                bmp1 = BitmapFactory.decodeResource(getResources(), R.drawable.red);
            }
        }

        else if(camORgal10 == 0)
        {
            bmp1 = BitmapFactory.decodeResource(getResources(), R.drawable.red);
        }
        else
        {
            bmp1 = BitmapFactory.decodeResource(getResources(), R.drawable.red);
        }


        File pic2 = new File(Environment.getExternalStorageDirectory() + "/MySpot/image_2.PNG");
        File pic3 = new File(Environment.getExternalStorageDirectory() + "/MySpot/image_3.PNG");


        if(pic2.exists())
        {
            bmp2 = BitmapFactory.decodeFile(pic2.getAbsolutePath());
        }
        else
        {
            bmp2 = BitmapFactory.decodeResource(getResources(), R.drawable.purple);
        }
        if(pic3.exists())
        {
            bmp3 = BitmapFactory.decodeFile(pic3.getAbsolutePath());
        }
        else
        {
            bmp3 = BitmapFactory.decodeResource(getResources(), R.drawable.green);
        }


        ivpic3.setImageBitmap(bmp3);

        ivpic2.setImageBitmap(bmp2);

        ivpic1.setImageBitmap(bmp1);

        TVpic1a.setText(oneNamea);
        TVpic1b.setText(oneNameb);
        TVpic1c.setText(oneNamec);

}


} 
4

2 に答える 2

1

Logcat はスタック トレースを提供し、debug を使用してクラッシュしている場所を特定します。コード、特に OOP コードを読み取って最新のアプリケーションをデバッグすることは、ほとんど不可能です。

于 2012-03-11T04:06:01.813 に答える