2
votes

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.

            }
        }

    });

   }}

This file is almost working great but whenever I click on the next button it crashes the app

activity_objectName.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/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>

Main problem is here I'm not able to go to this file "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>

edit_background.xml

<?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>

crash report

07-02 13:29:40.966 14586-14586/randomexcessor.foutuneteller E/AndroidRuntime: FATAL EXCEPTION: main Process: randomexcessor.foutuneteller, PID: 14586 java.lang.OutOfMemoryError: Failed to allocate a 19743564 byte allocation with 15898356 free bytes and 15MB until OOM at dalvik.system.VMRuntime.newNonMovableArray(Native Method) at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method) at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:609) at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444) at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:988) at android.content.res.Resources.loadDrawableForCookie(Resources.java:2477) at android.content.res.Resources.loadDrawable(Resources.java:2384) at android.content.res.Resources.getDrawable(Resources.java:787) at android.content.Context.getDrawable(Context.java:403) at android.support.v4.content.ContextCompatApi21.getDrawable(ContextCompatApi21.java:30) at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:372) at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:202) at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:190) at android.support.v7.content.res.AppCompatResources.getDrawable(AppCompatResources.java:100) at android.support.v7.widget.AppCompatImageHelper.loadFromAttributes(AppCompatImageHelper.java:54) at android.support.v7.widget.AppCompatImageView.(AppCompatImageView.java:66) at android.support.v7.widget.AppCompatImageView.(AppCompatImageView.java:56) at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:106) at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1029) at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1087) at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:47) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:725) at android.view.LayoutInflater.rInflate(LayoutInflater.java:806) at android.view.LayoutInflater.rInflate(LayoutInflater.java:809) at android.view.LayoutInflater.inflate(LayoutInflater.java:504) at android.view.LayoutInflater.inflate(LayoutInflater.java:414) at android.view.LayoutInflater.inflate(LayoutInflater.java:365) at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:292) at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) at randomexcessor.foutuneteller.ageInput.onCreate(ageInput.java:22) at android.app.Activity.performCreate(Activity.java:6010) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1129) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2292) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2413) at android.app.ActivityThread.access$800(ActivityThread.java:155) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1317) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5343) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)

1
just need crash logjagapathi
please add the crash report and reduce your post to relevant part.Opiatefuchs
crash says "that app has stooped unfortunately"Ashish
that´s not the crash report. In your IDE (for example Android Studio), there is a window called "Android Monitor". Here you see the crash report, it´s necessary to see the result when your app crashs. Otherwise, we can´t help. Please add it...Opiatefuchs
at randomexcessor.foutuneteller.ageInput.onCreate(ageInput.java:22) tht is the error. on line ->setContentView(R.layout.activity_age_input);Ashish

1 Answers

0
votes

The first level of your crash report shows an OOM, which means OutOfMemory. Any Bitmap that you put inside activity_ageInput.xml or that maybe you used in your Toast´s layout is too big (or all bitmaps). You should consider to reduce the size of your bitmaps. Read this thread about handling bitmaps:

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