添加多个活动android studio时崩溃的应用程序

时间:2018-11-02 05:49:38

标签: java android android-studio

大家好,当我尝试在物理电话中运行我的应用程序时遇到一个问题,只是在运行时崩溃了。这是我制作此应用程序的5倍时间,这种情况刚好在安装应用程序时结束。我试图在主活动中创建一个应用程序,其中有两个“图像”按钮,然后打开另一个“花药”活动,但我没有创建图像按钮就检查了自己。但是当我按下图片按钮时,应用程序便崩溃了。

这是我的代码。

ActivityMain.xml

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="@drawable/blurred"
tools:context=".MainActivity">


<ImageView
    android:id="@+id/blurbackground"
    android:layout_width="match_parent"
    android:layout_height="97dp"
    android:layout_alignParentStart="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginStart="0dp"
    android:layout_marginLeft="0dp"
    android:layout_marginTop="0dp"
    android:scaleType="centerCrop"
    app:srcCompat="@drawable/backmain" />

<TextView
    android:id="@+id/txt1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentStart="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginStart="18dp"
    android:layout_marginLeft="18dp"
    android:layout_marginTop="62dp"
    android:text="Welcome!"
    android:textColor="@android:color/white"
    android:textSize="22sp" />

<TextView
    android:id="@+id/txt2"
    android:layout_width="345dp"
    android:layout_height="wrap_content"
    android:layout_alignParentStart="true"
    android:layout_alignParentTop="true"
    android:layout_marginStart="7dp"
    android:layout_marginTop="114dp"
    android:gravity="center"
    android:text="Master all professions in the professions guide"
    android:textColor="@android:color/white"
    android:textColorHighlight="@android:color/black"
    android:textSize="18sp"
    android:typeface="sans" />

<TextView
    android:id="@+id/txt4"
    android:layout_width="350dp"
    android:layout_height="wrap_content"
    android:layout_alignParentStart="true"
    android:layout_alignParentBottom="true"
    android:layout_marginStart="10dp"
    android:layout_marginBottom="348dp"
    android:textColorHighlight="@android:color/black"
    android:text="Be part of the game and be the master of professions, these guides are collected from users who offer great help in your adventure throughout Azeroth!"
    android:textColor="@android:color/white"
    android:textStyle="italic"
    android:typeface="sans" />

<TextView
    android:id="@+id/txt7"
    android:layout_width="322dp"
    android:layout_height="64dp"
    android:layout_alignParentStart="true"
    android:layout_alignParentBottom="true"
    android:layout_marginStart="20dp"
    android:layout_marginBottom="75dp"
    android:text="We have classroom guides available for you to master your character if you are fresh and new to the world of Warcraft, dominate your enemies and take the victory!"
    android:textColor="@android:color/white"
    android:textColorHighlight="@android:color/black" />

<ImageView
    android:id="@+id/imageView"
    android:layout_width="227dp"
    android:layout_height="103dp"
    android:layout_alignParentStart="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginStart="66dp"
    android:layout_marginLeft="66dp"
    android:layout_marginTop="223dp"
    app:srcCompat="@drawable/alchem"
    tools:scaleType="centerCrop" />

<ImageButton
    android:id="@+id/buthorde"
    android:layout_width="68dp"
    android:layout_height="75dp"
    android:layout_alignStart="@+id/imageView"
    android:layout_alignParentBottom="true"
    android:layout_marginStart="3dp"
    android:layout_marginBottom="155dp"
    android:background="@android:color/transparent"
    android:scaleType="centerCrop"
    app:srcCompat="@drawable/horde" />

<ImageButton
    android:id="@+id/butally"
    android:layout_width="70dp"
    android:layout_height="73dp"
    android:layout_alignEnd="@+id/imageView"
    android:layout_alignBottom="@+id/buthorde"
    android:layout_marginEnd="5dp"
    android:layout_marginBottom="3dp"
    android:background="@android:color/transparent"
    android:scaleType="centerCrop"
    app:srcCompat="@drawable/ally" />

<Button
    android:id="@+id/butshow"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="21dp"
    android:text="Show me!"
    android:textAllCaps="false"
    android:textStyle="italic"
    android:typeface="sans" />

ActivityMain.java

package hordemuzzle.wowprofessions;

import android.content.Intent;
import android.graphics.Typeface;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
private Button butonhorde;
private Button butonally;

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

//---------------------------------------------------------------------------    -------------------------
    TextView textView = (TextView) findViewById(R.id.txt1);
        textView.setTypeface(Typeface.createFromAsset(getAssets(),"fonts/contm.ttf"));
    textView.setText("Welcome!");

    TextView textView1 = (TextView) findViewById(R.id.txt2);
    textView1.setTypeface(Typeface.createFromAsset(getAssets(),"fonts/contm.ttf"));
    textView1.setText("Master all professions in the professions guide");
//----------------------------------------------------------------------------------------------------



    butonally=(Button) findViewById(R.id.butally);
    butonally.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            openActally();
        }
    });
    butonhorde=(Button) findViewById(R.id.buthorde);
    butonhorde.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            openActhorde();
        }
    });

}
public void openActhorde(){
    Intent intenth = new Intent(this, Activityhorde.class);
    startActivity(intenth);
}
public  void openActally(){
    Intent intenta = new Intent(this, Activityally.class);
    startActivity(intenta);
}

}

Logcat

2018-11-01 23:30:05.204 1051-19358/system_process I/OpenGLRenderer: Initialized EGL, version 1.4
2018-11-01 23:30:05.204 1051-19358/system_process D/OpenGLRenderer: Swap behavior 1
2018-11-01 23:30:05.291 1051-12094/system_process D/GraphicsStats: Buffer count: 4
2018-11-01 23:30:05.291 1051-4361/system_process I/WindowManager: WIN DEATH: Window{3382c8d u0 hordemuzzle.wowprofessions/hordemuzzle.wowprofessions.SplashScreenActivity}
2018-11-01 23:30:05.291 1051-12088/system_process I/ActivityManager: Process hordemuzzle.wowprofessions (pid 24362) has died
2018-11-01 23:30:05.291 1051-12088/system_process D/ActivityManager: cleanUpApplicationRecord -- 24362

启动画面活动

package hordemuzzle.wowprofessions;

import android.graphics.Color;
import android.graphics.Typeface;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

import gr.net.maroulis.library.EasySplashScreen;

import static android.support.v4.os.LocaleListCompat.create;    

public class SplashScreenActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    EasySplashScreen config = new EasySplashScreen(SplashScreenActivity.this)
            .withFullScreen()
            .withTargetActivity(MainActivity.class)
            .withSplashTimeOut(4000)
            .withBackgroundResource(android.R.color.background_dark)
            .withLogo(R.drawable.logo);


    View easysplashscreen = config.create();
    setContentView(easysplashscreen);


}
}

1 个答案:

答案 0 :(得分:0)

尝试

package hordemuzzle.wowprofessions;

import android.content.Intent;
import android.graphics.Typeface;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

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

//---------------------------------------------------------------------------    -------------------------
    TextView textView = (TextView) findViewById(R.id.txt1);
        textView.setTypeface(Typeface.createFromAsset(getAssets(),"fonts/contm.ttf"));
    textView.setText("Welcome!");

    TextView textView1 = (TextView) findViewById(R.id.txt2);
    textView1.setTypeface(Typeface.createFromAsset(getAssets(),"fonts/contm.ttf"));
    textView1.setText("Master all professions in the professions guide");
//----------------------------------------------------------------------------------------------------




    ((ImageButton) findViewById(R.id.butally)).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            openActally();
        }
    });
    ((ImageButton) findViewById(R.id.buthorde)).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            openActhorde();
        }
    });

}
public void openActhorde(){
    Intent intenth = new Intent(this, Activityhorde.class);
    startActivity(intenth);
}
public  void openActally(){
    Intent intenta = new Intent(this, Activityally.class);
    startActivity(intenta);
}

}