简体   繁体   English

我的应用程序在Android 4.4上正常运行但在2.3上崩溃。 甚至没有开始

[英]My Application is running fine on Android 4.4 but crashes on 2.3. Not even starting

The below one is the source code. 下面是源代码。 This program just does the memory match game and works very well in android 4.4 package com.example.myimagematchgamev10; 这个程序只是做内存匹配游戏,在android 4.4包中运行得很好com.example.myimagematchgamev10;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.drawable.Drawable;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;
import android.widget.Button;
import android.widget.ImageButton;

import java.util.HashMap;
import java.util.Random;

class MyCustomImageButton extends ImageButton
{
    protected int holdingImage;

    public MyCustomImageButton(Context context) {
        super(context);
        this.holdingImage = -1;
    }
    public MyCustomImageButton(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.holdingImage = -1;
    }
    public MyCustomImageButton(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        this.holdingImage = -1;
    }
}
//public class MainActivity extends ActionBarActivity {
    public class MainActivity extends Activity {
    Random myR = new Random ();
    MyCustomImageButton[] myImageButtons;
    int[] myImages={R.drawable.one,R.drawable.two,R.drawable.five,R.drawable.seven,R.drawable.eight,R.drawable.six,R.drawable.three,R.drawable.four};
    int[] myImageButtonArray = {R.id.imageButton0, R.id.imageButton1, R.id.imageButton2, R.id.imageButton3, R.id.imageButton4,
            R.id.imageButton5, R.id.imageButton6, R.id.imageButton7, R.id.imageButton8, R.id.imageButton9,
            R.id.imageButton10, R.id.imageButton11, R.id.imageButton12, R.id.imageButton13, R.id.imageButton14,
            R.id.imageButton15};

    // The following four lies for holding temp data while checking the match
    int myFirstButtonImage = R.drawable.ic_launcher;
    int mySecondButtonImage = R.drawable.ic_launcher;
    ImageButton myFirstButton = null;
    ImageButton mySecondButton = null;

    // for message box
    int myNoOfClick = 0;
    int myNoOfCompletedCells = 0;

    Button myNewgame;
    AlertDialog.Builder alertDialog; // =  new AlertDialog.Builder(MainActivity.this);

    protected void initializeGrid()
    {
        for (int i=0; i < 16; ++i)
        {
            myImageButtons[i].setBackgroundResource(R.drawable.ic_launcher);
            myImageButtons[i].setClickable(true);
            myImageButtons[i].holdingImage = -1;
        }
        myNoOfClick = 0;
        myNoOfCompletedCells = 0;
    }

    protected void createGrid()
    {
        myImageButtons = new MyCustomImageButton[16];
        for (int i=0; i < 16; ++i)
        {
            myImageButtons[i] = (MyCustomImageButton) findViewById(myImageButtonArray[i]);

        }
    }

    protected void loadImages()
    {
        int myNextInt;
        for (int i=0; i < 8; ++i)
        {
            for(int j=0; j < 2; ++j)
            {
                myNextInt = myR.nextInt(16);
                while (myImageButtons[myNextInt].holdingImage != -1)
                {
                    myNextInt = myR.nextInt(16);
                }
                if(myImageButtons[myNextInt].holdingImage == -1)
                {
                    myImageButtons[myNextInt].setBackgroundResource(R.drawable.ic_launcher);
                    myImageButtons[myNextInt].holdingImage = myImages[i];
                    //myGridValues[myNextInt] = i+1;
                    // myMap.put(myImageButtonArray[myNextInt],myImages[i]);
                }
            }

        }
    }


    protected void showMessage()
    {
        alertDialog =  new AlertDialog.Builder(MainActivity.this);
        //alertDialog = new AlertDialog.Builder(MainActivity.this).create();
        alertDialog.setTitle("Score");
        alertDialog.setMessage("No. Of clicks are:  " + myNoOfClick +" !");
        alertDialog.setInverseBackgroundForced(true);
        alertDialog.setCancelable(true);
        alertDialog.setPositiveButton("OK", new DialogInterface.OnClickListener(){

            public void onClick(DialogInterface dialog,
                int which) {
                    dialog.dismiss();
                }
        });
        alertDialog.show();
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        createGrid();
        initializeGrid();
        loadImages();;

        myNewgame = (Button) findViewById(R.id.newGame);
        myNewgame.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                initializeGrid();
                loadImages();
            }
        });


        for(int i=0; i<myImageButtons.length; ++i)
        {
            final MyCustomImageButton myTempImageButton = myImageButtons[i];
            //final int myIBId = myTempImageButton.getId();
            myTempImageButton.setOnClickListener(new View.OnClickListener() {
                //@Override
                public void onClick(View view) {
                    ++myNoOfClick;
                    myTempImageButton.setBackgroundResource(myTempImageButton.holdingImage);
                    if (myFirstButtonImage == R.drawable.ic_launcher)
                    {
                        if(mySecondButtonImage == R.drawable.ic_launcher)
                        {
                            myFirstButtonImage = myTempImageButton.holdingImage;
                            myFirstButton = myTempImageButton;
                            myTempImageButton.setClickable(false);
                            myNoOfCompletedCells += 2;
                            if (myNoOfCompletedCells >= 16)
                            {
                                showMessage();
                            }
                        }
                        else
                        {
                            myFirstButton.setClickable(true);
                            mySecondButton.setClickable(true);
                            myFirstButton.setBackgroundResource(R.drawable.ic_launcher);
                            mySecondButton.setBackgroundResource(R.drawable.ic_launcher);

                            myFirstButton = myTempImageButton;
                            myFirstButtonImage = myTempImageButton.holdingImage;
                            myTempImageButton.setClickable(false);
                        }
                    }
                    else
                    {
                        myTempImageButton.setClickable(false);
                        if (myFirstButtonImage == myTempImageButton.holdingImage)   // For Success full Match
                        {
                            myFirstButton.setClickable(false);
                            myFirstButtonImage = R.drawable.ic_launcher;
                            mySecondButtonImage = R.drawable.ic_launcher;
                        }
                        else
                        {
                            mySecondButton = myTempImageButton;
                            mySecondButtonImage = myTempImageButton.holdingImage;
                            myFirstButtonImage = R.drawable.ic_launcher;
                        }
                    }
                }
            });
        }

    }


}




The above is the source file

I have the following in manifest xml 我在清单xml中有以下内容

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myimagematchgamev10"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="7"
        android:targetSdkVersion="10" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.myimagematchgamev10.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

The above one is the manifest xml 上面的清单是xml

The below is the log I am getting 以下是我得到的日志

Waiting for device. 等待设备。 "C:\\Program Files (x86)\\Android\\android-studio\\sdk\\tools\\emulator.exe" -avd AVD_for_Nexus_S -netspeed full -netdelay none “C:\\ Program Files(x86)\\ Android \\ android-studio \\ sdk \\ tools \\ emulator.exe”-avd AVD_for_Nexus_S -netspeed full -netdelay none

Device connected: emulator-5554 Device is online: emulator-5554 Target device: AVD_for_Nexus_S [emulator-5554] Uploading file local path: D:\\Android\\MyApplicationProject\\MyImageMatchgameV1.0Project\\MyImageMatchgameV1.0\\build\\apk\\MyImageMatchgameV1.0-debug-unaligned.apk remote path: /data/local/tmp/com.example.myimagematchgamev10 Installing com.example.myimagematchgamev10 DEVICE SHELL COMMAND: pm install -r "/data/local/tmp/com.example.myimagematchgamev10" pkg: /data/local/tmp/com.example.myimagematchgamev10 Success 设备已连接:emulator-5554设备在线:emulator-5554目标设备:AVD_for_Nexus_S [emulator-5554]上传文件本地路径:D:\\ Android \\ MyApplicationProject \\ MyImageMatchgameV1.0Project \\ MyImageMatchgameV1.0 \\ build \\ apk \\ MyImageMatchgameV1.0- debug-unaligned.apk remote path:/data/local/tmp/com.example.myimagematchgamev10安装com.example.myimagematchgamev10 DEVICE SHELL命令:pm install -r“/data/local/tmp/com.example.myimagematchgamev10”pkg: /data/local/tmp/com.example.myimagematchgamev10成功

Launching application: com.example.myimagematchgamev10/com.example.myimagematchgamev10.MainActivity. 启动应用程序:com.example.myimagematchgamev10 / com.example.myimagematchgamev10.MainActivity。 DEVICE SHELL COMMAND: am start -n "com.example.myimagematchgamev10/com.example.myimagematchgamev10.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.example.myimagematchgamev10/.MainActivity } DEVICE SHELL COMMAND:我开始-n“com.example.myimagematchgamev10 / com.example.myimagematchgamev10.MainActivity”-a android.intent.action.MAIN -c android.intent.category.LAUNCHER开始:Intent {act = android.intent .action.MAIN cat = [android.intent.category.LAUNCHER] cmp = com.example.myimagematchgamev10 / .MainActivity}

From what I can tell without the logs, you are using an API that was introduced after Gingerbread. 根据我没有日志的情况,您使用的是在Gingerbread之后引入的API。

Just read the LogCat, it should give you hints on the exact function that's not working. 只需阅读LogCat,它应该为您提供有关无法正常工作的提示。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android我的应用程序可以在2.3上运行,但即使在4.0上也无法启动 - Android My application works on 2.3 fine but doesn't start even on 4.0 应用程序未在android 4.4中运行 - Application is not running in android 4.4 使用expandableheadergridview在Android L上正常工作但在设备&lt;= 4.4上崩溃 - Using expandableheadergridview working fine on Android L but crashes on Devices<=4.4 Phonegap应用程序在运行Android 4.0时引发错误,但在Android 2.3及更低版本上可以正常运行 - Phonegap application throws error running Android 4.0, but works fine on Android 2.3 and below 在android 4.2.2上运行但不在4.4或更高版本上运行的应用程序 - Application running on android 4.2.2 but not running on 4.4 or higher 我的应用在Android 2.3中崩溃,但在4.0中没有崩溃 - My app crashes in Android 2.3 but not in 4.0 android应用程序在开始之前崩溃 - android application crashes before starting android app从2.3的片段开始活动时崩溃 - android app crashes on starting an activity from fragment on 2.3 Android Studio在同一部手机上运行应用程序时生成的APK崩溃正常。 怎么了? - Android Studio generated APK crashes while running the application on the same phone works fine. What is wrong? 在运行Android 7.0(API 24)的模拟器中运行的Android应用在运行Android 4.4(API 19)的手机中崩溃 - Android app that runs in emulator running Android 7.0 (API 24) crashes in phone running Android 4.4 (API 19)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM