当前位置: 首页 > 知识库问答 >
问题:

我的意图不起作用,应用程序每次都崩溃

司空俊雄
2023-03-14

objectName.java

package randomexcessor.foutuneteller;

import android.content.Intent;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class objectName extends AppCompatActivity {

EditText objectInput;
FloatingActionButton actionButton;
TextView text;

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

// An intent received and hence been written bellow the Edit_text input to 
be shown as consideration.
    Intent toAgeInput = getIntent();
    final String name = toAgeInput.getStringExtra("users name");
    final String display = toAgeInput.getStringExtra("alphabet");

    TextView show = (TextView) findViewById(R.id.disclaimer);
    show.setText("Please type the name starting with the alphabet, Capital ' 
" + display+ " '");

    objectInput = (EditText) findViewById(R.id.inputName);
    actionButton = (FloatingActionButton) findViewById(R.id.outputButton);

    LayoutInflater inflater = getLayoutInflater();
    final View layout = inflater.inflate(R.layout.toast_layout,
            (ViewGroup) findViewById(R.id.custom_toast_container));



    actionButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            /*condition layout which allows user to dial only an alphabet
             starting with random selected alphabet from baseInt activity 
   input.*/
            if (!objectInput.getText().toString().matches(display+ "[a-zA-
   Z]+"))
            {
                text = (TextView) layout.findViewById(R.id.errorReport);
                text.setText("You have to Start with 'Capital " + 
  display+"'.");

                Toast toast = new Toast(objectName.this);
                toast.setDuration(Toast.LENGTH_LONG);
                toast.setGravity(Gravity.CENTER_HORIZONTAL,0,0);
                toast.setView(layout);
                toast.show();
            }
            else if (!objectInput.getText().toString().matches("[a-zA-Z]+"))
            {
                text = (TextView) layout.findViewById(R.id.errorReport);
                text.setText("Your name must be in words");

                Toast toast = new Toast(objectName.this);
                toast.setDuration(Toast.LENGTH_LONG);
                toast.setGravity(Gravity.CENTER_HORIZONTAL,0,0);
                toast.setView(layout);
                toast.show();
            }
            else
            {
                Intent openAge = new Intent(objectName.this, 
 ageInput.class);
                String input = objectInput.getText().toString();
                openAge.putExtra("alphabet", display);//alphabet to use
                openAge.putExtra("users name", name);//name of the user.
                openAge.putExtra("belonging", input);//the object name 
 provided in this class.
                startActivity(openAge);//running activity.

            }
        }

    });

   }}
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/object1bg">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:id="@+id/detail"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_below="@+id/appbar2"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="15dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="45dp"
        app:srcCompat="@drawable/type15"
        tools:ignore="ContentDescription" />

    <LinearLayout
        android:id="@+id/appbar2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:layout_marginTop="5sp"
        android:background="@drawable/edit_background"
        android:padding="2dp"
        android:weightSum="1">

        <EditText
            android:id="@+id/inputName"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:background="@drawable/edit_text"
            android:ems="10"
            android:inputType="text"
            android:padding="10dp"
            android:textSize="18sp"
            android:layout_margin="3dp"
            android:layout_weight="1.02"
            android:hint="@string/Object"
            android:textColor="#A52A2A"/>

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/outputButton"
            android:layout_marginEnd="10dp"
            android:layout_marginTop="3dp"
            android:layout_marginBottom="3dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:clickable="true"
            app:backgroundTint="#32CD32"
            app:elevation="2dp"
            app:fabSize="normal"
            app:srcCompat="@drawable/ic_keyboard_arrow_right_white_24dp" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/appbar2"
        android:layout_centerHorizontal="true"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:layout_marginTop="10dp"
        android:background="@drawable/button"
        tools:ignore="UnknownIdInLayout">

        <TextView
            android:id="@+id/disclaimer"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="12dp"
            android:textColor="#FFFFFF"
            android:textSize="15sp" />
    </LinearLayout>

</RelativeLayout>

</android.support.design.widget.CoordinatorLayout>

主要问题是我无法转到“ageinput.java”文件,

activity_ageinput.xml

package randomexcessor.foutuneteller;

import android.content.Intent;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class ageInput extends AppCompatActivity {

TextView text;

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

    final EditText ageFind = (EditText) findViewById(R.id.inputAge);
    FloatingActionButton ageButton = (FloatingActionButton) 
findViewById(R.id.ageButton);

    LayoutInflater inflater = getLayoutInflater();
    final View layout = inflater.inflate(R.layout.toast_layout,
            (ViewGroup) findViewById(R.id.custom_toast_container));



    ageButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if(ageFind.getText().toString().isEmpty())
            {

                text = (TextView) layout.findViewById(R.id.errorReport);
                text.setText("Please type your age or System error.");

                text = (TextView) layout.findViewById(R.id.errorReport);
                Toast toast = new Toast(ageInput.this);
                toast.setDuration(Toast.LENGTH_LONG);
                toast.setGravity(Gravity.CENTER_HORIZONTAL,0,0);
                toast.setView(layout);
                toast.show();
            }
            else if(ageFind.getText().length() > 2)
            {
                text = (TextView) layout.findViewById(R.id.errorReport);
                text.setText("Your age cannot be " + 
 ageFind.getText().toString() +"!!");

                text = (TextView) layout.findViewById(R.id.errorReport);
                Toast toast = new Toast(ageInput.this);
                toast.setDuration(Toast.LENGTH_LONG);
                toast.setGravity(Gravity.CENTER_HORIZONTAL,0,0);
                toast.setView(layout);
                toast.show();
            }
            else
            {
                Intent runResult = getIntent();
                final String alpha = runResult.getStringExtra("alphabet");
                final String name = runResult.getStringExtra("users name");
                final String belong = runResult.getStringExtra("belonging");

                Intent finalPage = new Intent(ageInput.this, result.class);
                finalPage.putExtra("alphabet", alpha);
                finalPage.putExtra("users name", name);
                finalPage.putExtra("belonging", belong);
                finalPage.putExtra("users age", 
 ageFind.getText().toString());
                startActivity(finalPage);

            }
        }
    });
 }

}

activity_ageinput.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/agefact2">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">


    <ImageView
        android:id="@+id/imageView4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        app:srcCompat="@drawable/type13"
        tools:ignore="ContentDescription" />



    <LinearLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:layout_marginTop="6sp"
        android:background="@drawable/edit_background"
        android:padding="2dp"
        android:weightSum="1">

        <EditText
            android:id="@+id/inputAge"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:background="@drawable/edit_text"
            android:ems="10"
            android:hint="@string/age"
            android:inputType="text"
            android:padding="10dp"
            android:textSize="18sp"
            android:layout_margin="3dp"
            android:layout_weight="1.02"
            android:textColor="@color/colorAccent"/>

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/ageButton"
            android:layout_marginEnd="10dp"
            android:layout_marginTop="3dp"
            android:layout_marginBottom="3dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:clickable="true"
            app:backgroundTint="#32CD32"
            app:elevation="2dp"
            app:fabSize="normal"
            app:rippleColor="#7FFF00"
            app:srcCompat="@drawable/ic_keyboard_arrow_right_white_24dp" />
    </LinearLayout>

  </RelativeLayout>

</android.support.design.widget.CoordinatorLayout>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="1dp">

<stroke
    android:color="#696969"
    android:width="2dp"/>
<solid android:color="#FFFFFF"></solid>

<corners
    android:radius="25dp" />

</shape>

edit_text.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android">

</shape>

崩溃报告

共有1个答案

葛修真
2023-03-14

您的崩溃报告的第一级显示一个OOM,意思是OutOfMemory。放在activity_ageinput.xml中的任何位图,或者在toast布局中使用的任何位图都太大(或者所有位图都太大)。您应该考虑减小位图的大小。阅读有关处理位图的以下内容:

https://developer.android.com/topic/performance/graphics/index.html

 类似资料:
  • 对于某些活动的意图是有效的,对于某些特定的活动意图是崩溃的,我已经改变并尝试了不同的方法,但是对于某些活动意图是无效的,应用程序正在构建,但是在手机上运行之后,它在调试期间没有显示出任何错误?我尝试了不同的方法,但它仍然崩溃,谁能帮助我解决它? MainActivity java 清单文件

  • E/AndroidRuntime:致命异常:主进程:com。维内特。计算器,PID:29435 java。lang.NullPointerException:尝试调用虚拟方法的布尔java。朗,布尔<代码>在此输入代码booleanValue()”在com的空对象引用上。维内特。计算器主要活动16美元。android上的onClick(MainActivity.java:177)。看法看法andr

  • 我是android新手,我正在学习一些教程,在这一点上,当我点击登录按钮时,应用程序不断崩溃。当我运行应用程序并单击登录按钮时,应用程序崩溃,在logcat中,它显示java RuntimeException的这个错误。这是我的logcat,loginactivity。xml和loginactivity。JAVA JAVAlang.RuntimeException:无法启动活动组件信息{com.e

  • 我在手机上构建应用程序时遇到了以下错误:

  • 注意:在我添加广告之前,我的应用程序运行良好,使用相同的方法 当我试图将adview添加到我的应用程序时,它会使我的应用程序崩溃,所以我删除了它,但仍然给我这个这是logcat 10-12 21:33:19.765 4993-4993/com。fm360。almorfis E/AndroidRuntime:致命异常:主进程:com。fm360。阿尔莫菲斯,PID:4993爪哇。lang.Runti