Это ошибка в logcat 1]: https://i.stack.imgur.com/m5nOz.png Поток программы идет из splash ---> player ---> MainActivity, а также из-за активности приложения, пожалуйста, помогите мне. Splash.xml В основном содержитошибка!java
package com.vishwas.tictactoe;
import android.content.DialogInterface;
import android.content.Intent;
import android.media.Image;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageButton;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.MobileAds;
public class player extends AppCompatActivity {
private AdView myAdView;
private EditText et1;
private EditText et2;
private ImageButton ibt1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_player);
// Sample AdMob app ID: ca-app-pub-7866343935318771~9805549476 banner2
MobileAds.initialize(this, "ca-app-pub-7866343935318771~9805549476");
AdView adView = new AdView(this);
adView.setAdSize(AdSize.BANNER);
adView.setAdUnitId("ca-app-pub-7866343935318771/3173472761");
myAdView = findViewById(R.id.adView3);
AdRequest adRequest = new AdRequest.Builder().build();
myAdView.loadAd(adRequest);
//
et1 = findViewById(R.id.editText);
et2 = findViewById(R.id.editText4);
ibt1 = findViewById(R.id.imageButton5);
}
public void pass(View view)
{
if(et1.getText().toString().equals(et2.getText().toString()))
{
AlertDialog.Builder builder = new AlertDialog.Builder(player.this);
builder.setMessage("Both Name can't be equal!!!").setPositiveButton("Ok", null);
AlertDialog alert = builder.create();
alert.show();
}
else
{
Intent intent = new Intent(this, MainActivity.class);
String p1 = et1.getText().toString();
String p2 = et2.getText().toString();
intent.putExtra("player1", p1);
intent.putExtra("player2", p2);
startActivity(intent);
}
}
@Override
public void onBackPressed()
{
AlertDialog.Builder builder = new AlertDialog.Builder(player.this);
builder.setMessage("Do you really want to Exit?").setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which)
{
player.super.onBackPressed();
}
}).setNegativeButton("Cancel",null).setCancelable(false);
AlertDialog alert = builder.create();
alert.show();
}
public void abt(View view)
{
startActivity(new Intent(this,about.class));
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/bkcolor"
android:orientation="vertical"
tools:context=".MainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="64dp">
<TextView
android:id="@+id/text_view_p1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_marginStart="47dp"
android:freezesText="true"
android:textColor="@color/colorPrimaryDark"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="@+id/text_view_p2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/text_view_p1"
android:layout_alignParentStart="true"
android:layout_marginStart="47dp"
android:layout_marginTop="2dp"
android:freezesText="true"
android:textColor="@color/colorPrimaryDark"
android:textSize="18sp"
android:textStyle="bold" />
<Button
android:id="@+id/button_reset"
android:layout_width="116dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_marginEnd="5dp"
android:background="@drawable/bt_mainback"
android:text="reset"
android:textStyle="bold" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="121dp"
android:layout_weight="1">
<Button
android:id="@+id/button_00"
android:layout_width="0dp"
android:layout_height="180dp"
android:layout_margin="2dp"
android:layout_weight="1"
android:background="@color/colorPrimaryDark"
android:freezesText="true"
android:textColor="@color/textcolor"
android:textSize="60sp" />
<Button
android:id="@+id/button_01"
android:layout_width="0dp"
android:layout_height="180dp"
android:layout_margin="2dp"
android:layout_weight="1"
android:background="@color/colorPrimaryDark"
android:freezesText="true"
android:textColor="@color/textcolor"
android:textSize="60sp" />
<Button
android:id="@+id/button_02"
android:layout_width="0dp"
android:layout_height="180dp"
android:layout_margin="2dp"
android:layout_weight="1"
android:background="@color/colorPrimaryDark"
android:freezesText="true"
android:textColor="@color/textcolor"
android:textSize="60sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="123dp"
android:layout_weight="1">
<Button
android:id="@+id/button_10"
android:layout_width="0dp"
android:layout_height="180dp"
android:layout_margin="2dp"
android:layout_weight="1"
android:background="@color/colorPrimaryDark"
android:freezesText="true"
android:textColor="@color/textcolor"
android:textSize="60sp" />
<Button
android:id="@+id/button_11"
android:layout_width="0dp"
android:layout_height="180dp"
android:layout_margin="2dp"
android:layout_weight="1"
android:background="@color/colorPrimaryDark"
android:freezesText="true"
android:textColor="@color/textcolor"
android:textSize="60sp" />
<Button
android:id="@+id/button_12"
android:layout_width="0dp"
android:layout_height="180dp"
android:layout_margin="2dp"
android:layout_weight="1"
android:background="@color/colorPrimaryDark"
android:freezesText="true"
android:textColor="@color/textcolor"
android:textSize="60sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="138dp"
android:layout_weight="1">
<Button
android:id="@+id/button_20"
android:layout_width="0dp"
android:layout_height="180dp"
android:layout_margin="2dp"
android:layout_weight="1"
android:background="@color/colorPrimaryDark"
android:freezesText="true"
android:textColor="@color/textcolor"
android:textSize="60sp" />
<Button
android:id="@+id/button_21"
android:layout_width="0dp"
android:layout_height="180dp"
android:layout_margin="2dp"
android:layout_weight="1"
android:background="@color/colorPrimaryDark"
android:freezesText="true"
android:textColor="@color/textcolor"
android:textSize="60sp" />
<Button
android:id="@+id/button_22"
android:layout_width="0dp"
android:layout_height="180dp"
android:layout_margin="2dp"
android:layout_weight="1"
android:background="@color/colorPrimaryDark"
android:freezesText="true"
android:textColor="@color/textcolor"
android:textSize="60sp" />
</LinearLayout>
<com.google.android.gms.ads.AdView xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adView"
android:layout_width="match_parent"
android:layout_height="74dp"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-7866343935318771/5991207790" />
</LinearLayout>
MainActivity.java
package com.vishwas.tictactoe;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.InterstitialAd;
import com.google.android.gms.ads.MobileAds;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private AdView myAdView;
private InterstitialAd mInterstitialAd;
private final Button[][] buttons = new Button[3][3];
private boolean player1Turn = true;
private int roundCount;
String p1up;
String p2up;
String p1;
String p2;
public int player1Points;
public int player2Points;
public TextView textViewPlayer1;
public TextView textViewPlayer2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textViewPlayer1 = findViewById(R.id.text_view_p1);
textViewPlayer2 = findViewById(R.id.text_view_p2);
Intent intent = getIntent();
p1 = intent.getStringExtra("player1");
p2 = intent.getStringExtra("player2");
textViewPlayer1.setText(p1+":");
textViewPlayer2.setText(p2+":");
// Sample AdMob app ID:ca-app-pub-7866343935318771~9805549476 banner1
MobileAds.initialize(this, "ca-app-pub-7866343935318771~9805549476");
AdView adView = new AdView(this);
adView.setAdSize(AdSize.BANNER);
adView.setAdUnitId("ca-app-pub-7866343935318771/5991207790");
myAdView = findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
myAdView.loadAd(adRequest);
// Sample AdMob app ID: ca-app-pub-7866343935318771~9805549476 InterstitialAd
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId("ca-app-pub-7866343935318771/4056746387");
mInterstitialAd.loadAd(new AdRequest.Builder().build());
mInterstitialAd.setAdListener(new AdListener() {
@Override
public void onAdClosed() {
// Load the next interstitial.
mInterstitialAd.loadAd(new AdRequest.Builder().build());
}
});
//
//
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
String buttonID = "button_" + i + j;
int resID = getResources().getIdentifier(buttonID, "id", getPackageName());
buttons[i][j] = findViewById(resID);
buttons[i][j].setOnClickListener(this);
}
}
Button buttonReset = findViewById(R.id.button_reset);
buttonReset.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
resetGame();
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
} else {
Log.d("TAG", "The interstitial wasn't loaded yet.");
}
}
});
}
@Override
public void onClick(View v) {
if (!((Button) v).getText().toString().equals("")) {
return;
}
if (player1Turn) {
((Button) v).setText("X");
} else {
((Button) v).setText("O");
}
roundCount++;
if (checkForWin()) {
if (player1Turn) {
player1Wins();
} else {
player2Wins();
}
} else if (roundCount == 9) {
draw();
} else {
player1Turn = !player1Turn;
}
}
private boolean checkForWin() {
String[][] field = new String[3][3];
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
field[i][j] = buttons[i][j].getText().toString();
}
}
for (int i = 0; i < 3; i++) {
if (field[i][0].equals(field[i][1])
&& field[i][0].equals(field[i][2])
&& !field[i][0].equals("")) {
return true;
}
}
for (int i = 0; i < 3; i++) {
if (field[0][i].equals(field[1][i])
&& field[0][i].equals(field[2][i])
&& !field[0][i].equals("")) {
return true;
}
}
if (field[0][0].equals(field[1][1])
&& field[0][0].equals(field[2][2])
&& !field[0][0].equals("")) {
return true;
}
if (field[0][2].equals(field[1][1])
&& field[0][2].equals(field[2][0])
&& !field[0][2].equals("")) {
return true;
}
return false;
}
public void player1Wins() {
player1Points++;
Toast.makeText(this, p1+"wins!", Toast.LENGTH_SHORT).show();
p1up = String.valueOf(player1Points);
updatePointsText();
resetBoard();
}
public void player2Wins() {
player2Points++;
Toast.makeText(this, p2+"wins!", Toast.LENGTH_SHORT).show();
p2up = String.valueOf(player2Points);
updatePointsText();
resetBoard();
}
public void draw() {
Toast.makeText(this, "Draw!", Toast.LENGTH_SHORT).show();
resetBoard();
}
public void updatePointsText() {
textViewPlayer1.setText(p1+":"+p1up);
textViewPlayer2.setText(p2+":"+p2up);
}
private void resetBoard() {
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
buttons[i][j].setText("");
}
}
roundCount = 0;
player1Turn = true;
}
private void resetGame() {
player1Points = 0;
player2Points = 0;
p1up="0";
p2up="0";
updatePointsText();
resetBoard();
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putInt("roundCount", roundCount);
outState.putInt("player1Points", player1Points);
outState.putInt("player2Points", player2Points);
outState.putBoolean("player1Turn", player1Turn);
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
roundCount = savedInstanceState.getInt("roundCount");
player1Points = savedInstanceState.getInt("player1Points");
player2Points = savedInstanceState.getInt("player2Points");
player1Turn = savedInstanceState.getBoolean("player1Turn");
}
}
> here is the about app activity file which i think that is not creating any error
> This app runs perfectly on Nougat and Android Pie but it does crashes when it is un on APi Level less than 26 Though the min sdk is 18 and max is 28
ThisПриложение посвящено игре Tic Tac Toe, проблема в том, что когда приложение установлено, и я нажимаю на него, приложение вылетает и не открывается в Marshmallow, но оно отлично работает на Api больше 25