Hello,

Could anyone help please on the next topic?
My android app does not start on emulator. it gets stuck on this step "Starting activity com..MainActivity on device emulator-5554"

package com.fun.funapp;

import java.util.Random;


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

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

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".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>




package com.fun.funapp;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class mainActivityy extends Activity {
    private MainActivity mGame;

    private Button mBoardButtons[];
    private TextView mInfoTextView;
    private TextView mHumanCount;
    private TextView mTieCount;
    private TextView mAndroidCount;

    private int mHumanCounter = 0;
    private int mTieCounter = 0;
    private int mAndroidCounter = 0;

    private boolean mHumanFirst = true;
    private boolean mGameOver = false;

    public void onCreate(Bundle savedInstancesState) {
        super.onCreate(savedInstancesState);
        setContentView(R.layout.activity_main);

        mBoardButtons = new Button[mGame.getBoardSize()];
        mBoardButtons[0] = (Button) findViewById(R.id.Button03);
        mBoardButtons[1] = (Button) findViewById(R.id.Button01);
        mBoardButtons[2] = (Button) findViewById(R.id.Button02);
        mBoardButtons[3] = (Button) findViewById(R.id.Button04);
        mBoardButtons[4] = (Button) findViewById(R.id.Button05);
        mBoardButtons[5] = (Button) findViewById(R.id.Button06);
        mBoardButtons[6] = (Button) findViewById(R.id.Button07);
        mBoardButtons[7] = (Button) findViewById(R.id.Button08);
        mBoardButtons[8] = (Button) findViewById(R.id.Button09);

        mInfoTextView = (TextView) findViewById(R.id.information);
        mHumanCount = (TextView) findViewById(R.id.humanCount);
        mTieCount = (TextView) findViewById(R.id.TiesCount);
        mAndroidCount = (TextView) findViewById(R.id.AndroidCount);

        mHumanCount.setText(Integer.toString(mHumanCounter));
        mAndroidCount.setText(Integer.toString(mAndroidCounter));
        mTieCount.setText(Integer.toString(mTieCounter));

        mGame = new MainActivity();
        startNewGame();

    }

    private void startNewGame() {

        mGame.clearBoard();

        for (int i = 0; i < mBoardButtons.length; i++) {
            mBoardButtons[i].setText("");
            mBoardButtons[i].setEnabled(true);
            mBoardButtons[i].setOnClickListener(new ButtonClickListener(i));

        }
        if (mHumanFirst) {
            mInfoTextView.setText(R.string.human_first);
            mHumanFirst = false;

        } else {
            mInfoTextView.setText(R.string.android_turn);
            int move = mGame.getComputerMove();
            setMove(mGame.Android_Player, move);
            mHumanFirst = true;

        }
    }

    private class ButtonClickListener implements View.OnClickListener {

        int location;

        public ButtonClickListener(int location) {
            this.location = location;
        }

        public void onClick(View view) {
            if (!mGameOver) {
                if (mBoardButtons[location].isEnabled()) {

                    setMove(mGame.Human_Player, location);
                    int winner = mGame.checkForWinner();

                    if (winner == 0) {
                        mInfoTextView.setText(R.string.android_turn);
                        int move = mGame.getComputerMove();
                        setMove(mGame.Android_Player, move);
                        winner = mGame.checkForWinner();
                    }

                    if (winner == 0)
                        mInfoTextView.setText(R.string.human_turn);
                    else if (winner == 1) {
                        mInfoTextView.setText(R.string.ties);
                        mTieCounter++;
                        mTieCount.setText(Integer.toString(mTieCounter));
                        mGameOver = true;

                    } else if (winner == 2)
                        mInfoTextView.setTag(R.string.human_win);
                        mHumanCounter++;
                        mHumanCount.setText(Integer.toString(mHumanCounter));
                        mGameOver = true;
                }
                else {
                    mInfoTextView.setTag(R.string.android_win);
                    mAndroidCounter++;
                    mAndroidCount.setText(Integer.toString(mAndroidCounter));
                    mGameOver = true;
                }
            }
        }

    }

    private void setMove(char player, int location) {
        mGame.setMove(player, location);
        mBoardButtons[location].setEnabled(false);
        mBoardButtons[location].setText(String.valueOf(player));

        if (player == mGame.Human_Player)
            mBoardButtons[location].setTextColor(Color.GREEN);
        else
            mBoardButtons[location].setTextColor(Color.RED);

    }
}



import android.app.Activity;

public class MainActivity extends Activity {

    private char mBoard[];
    private final static int Board_Size = 9;

    public final char Human_Player = 'X';
    public final char Android_Player = 'O';
    public static final char Empty_space = ' ';

    private Random mRand;

    public int getBoardSize() {
        return Board_Size;
    }

    public MainActivity() {
        mBoard = new char[Board_Size];

        for (int i = 0; i < Board_Size; i++)
            mBoard[i] = Empty_space;

        mRand = new Random();

    }

    public void clearBoard() {
        for (int i = 0; i < Board_Size; i++) {
            mBoard[i] = Empty_space;
        }
    }

    public void setMove(char player, int location) {
        mBoard[location] = player;
    }

    public int getComputerMove() {

        int move;

        for (int i = 0; i < Board_Size; i++) {
            if (mBoard[i] != Human_Player && mBoard[i] != Android_Player) {
                char c = mBoard[i];
                mBoard[i] = Empty_space;

                if (checkForWinner() == 3) {
                    setMove(Android_Player, i);
                    return i;
                } else
                    mBoard[i] = c;
            }
        }
        for (int i = 0; i < Board_Size; i++) {
            if (mBoard[i] != Human_Player && mBoard[i] != Human_Player) {
                char c = mBoard[i];
                mBoard[i] = Empty_space;

                if (checkForWinner() == 2) {
                    setMove(Android_Player, i);
                    return i;
                } else
                    mBoard[i] = c;
            }

        }
        do {
            move = mRand.nextInt(getBoardSize());
        } while (mBoard[move] == Human_Player || mBoard[move] == Android_Player);
        setMove(Android_Player, move);
        return move;
    }

    public int checkForWinner() {
        for (int i = 0; i < 6; i += 3) {
            if (mBoard[i] == Human_Player && mBoard[i + 1] == Human_Player
                    && mBoard[i + 2] == Human_Player)
                return 2;
            if (mBoard[i] == Android_Player && mBoard[i + 1] == Android_Player
                    && mBoard[i + 2] == Android_Player)
                return 3;

        }
        for (int i = 0; i < 2; i += 3) {
            if (mBoard[i] == Human_Player && mBoard[i + 3] == Human_Player
                    && mBoard[i + 6] == Human_Player)
                return 2;
            if (mBoard[i] == Android_Player && mBoard[i + 3] == Android_Player
                    && mBoard[i + 6] == Android_Player)
                return 3;
        }
        if ((mBoard[0] == Human_Player && mBoard[4] == Human_Player && mBoard[8] == Human_Player)
                || mBoard[2] == Human_Player
                && mBoard[4] == Human_Player
                && mBoard[6] == Human_Player)
            return 2;
        if ((mBoard[0] == Android_Player && mBoard[4] == Android_Player && mBoard[8] == Android_Player)
                || mBoard[2] == Android_Player
                && mBoard[4] == Android_Player
                && mBoard[6] == Android_Player)
            return 3;

        for (int i = 0; i < Board_Size; i++) {
            if (mBoard[i] != Human_Player && mBoard[i] != Android_Player)
                return 0;

        }
        return 1;

    }
}

Please help me.
Thanks

Emulator is notoriously slow and developers avoid it and use real device. Your machine should have more 8GB of RAM so you can assign extra memory for emulator when you create/edit it so it has at least 2GB. You should also make sure that you are using Intel images for emulator

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.