-1

I found out, that when I create a layout, and Java file, I'm making a codes, so when I press button, it takes me to the another activity.

I have called already 9 methods to send me to the other activity, 3 or 4 in a MainJava class, and 4 in a layout, and everything works fine.

But now 1 button, in the new layout, doesn't work and says "Unfortunately app has stopped". I can't figure out where is the real problem, but the code is like the other buttons, which work well.

ac_phone

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


    <ImageView
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:id="@+id/imageView6"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:background="@drawable/phone"
        android:contentDescription="@string/phone" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="Xiaomi M4 16GB Mobile Phone"
        android:id="@+id/textView48"
        android:layout_below="@+id/imageView6"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:textColor="#852121" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="Description:"
        android:id="@+id/textView49"
        android:layout_below="@+id/textView48"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_marginLeft="36dp"
        android:layout_marginStart="36dp"
        android:textColor="#852121" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="Resolution:1920x1080 "
        android:id="@+id/textView50"
        android:layout_below="@+id/textView49"
        android:layout_alignLeft="@+id/textView49"
        android:layout_alignStart="@+id/textView49"
        android:textColor="#ffffff" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="Micro-SIM"
        android:id="@+id/textView51"
        android:layout_below="@+id/textView50"
        android:layout_alignLeft="@+id/textView50"
        android:layout_alignStart="@+id/textView50"
        android:textColor="#ffffff" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="Wi-Fi, dual-band, Wi-Fi Direct, DLNA, hotspot"
        android:id="@+id/textView52"
        android:layout_below="@+id/textView51"
        android:layout_alignLeft="@+id/textView51"
        android:layout_alignStart="@+id/textView51"
        android:textColor="#ffffff" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="13MP camera"
        android:id="@+id/textView53"
        android:layout_below="@+id/textView52"
        android:layout_alignLeft="@+id/textView52"
        android:layout_alignStart="@+id/textView52"
        android:textColor="#ffffff" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="3GB Ram"
        android:id="@+id/textView54"
        android:layout_below="@+id/textView53"
        android:layout_alignLeft="@+id/textView53"
        android:layout_alignStart="@+id/textView53"
        android:textColor="#ffffff" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/phoneStart"
        android:id="@+id/button3"
        android:layout_alignParentTop="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:layout_toRightOf="@+id/imageView6"
        android:layout_toEndOf="@+id/imageView6" />

</RelativeLayout>

I make the onClick button:

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

    <View
        android:layout_width="match_parent"
        android:layout_height="10dp"
        android:background="@android:color/background_dark"
        android:id="@+id/line1"
        android:layout_below="@+id/textView45"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="Level 3"
        android:id="@+id/textView45"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="23dp" />

    <ImageButton
        android:layout_width="120dp"
        android:layout_height="120dp"
        android:id="@+id/imageButton2"
        android:layout_marginTop="34dp"
        android:onClick="sendPhone"
        android:background="@drawable/phone"
        android:layout_below="@+id/line1"
        android:layout_toLeftOf="@+id/textView45"
        android:layout_toStartOf="@+id/textView45" />

</RelativeLayout>

Of course i make a command in the Java File:

 public void sendPhone(View view) {
    Intent intent = new Intent(getApplicationContext(), phoneclass.class);
    startActivity(intent);
}

And i create manifest file:

activity android:name=".phoneclass">

As i said before, other 9 buttons works well, but one button is getting: "Unfortunately, app has stoped working".

05-04 19:35:26.800 2437-2437/? E/AndroidRuntime: FATAL EXCEPTION: main
                                             Process: dynamochest.myapplication, PID: 2437
                                             java.lang.RuntimeException: Unable to start activity ComponentInfo{dynamochest.myapplication/dynamochest.myapplication.phoneclass}: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class <unknown>
                                                 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
                                                 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
                                                 at android.app.ActivityThread.-wrap11(ActivityThread.java)
                                                 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
                                                 at android.os.Handler.dispatchMessage(Handler.java:102)
                                                 at android.os.Looper.loop(Looper.java:148)
                                                 at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                 at java.lang.reflect.Method.invoke(Native Method)
                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
                                              Caused by: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class <unknown>
                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
                                                 at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:276)
                                                 at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
                                                 at dynamochest.myapplication.phoneclass.onCreate(phoneclass.java:12)
                                                 at android.app.Activity.performCreate(Activity.java:6237)
                                                 at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
                                                 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
                                                 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
                                                 at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                                                 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
                                                 at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                 at android.os.Looper.loop(Looper.java:148) 
                                                 at android.app.ActivityThread.main(ActivityThread.java:5417) 
                                                 at java.lang.reflect.Method.invoke(Native Method) 
                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
                                              Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
                                                 at android.view.LayoutInflater.createView(LayoutInflater.java:645)
                                                 at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
                                                 at android.view.LayoutInflater.onCreateView(LayoutInflater.java:694)
                                                 at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:762)
                                                 at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
                                                 at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:276) 
                                                 at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
                                                 at dynamochest.myapplication.phoneclass.onCreate(phoneclass.java:12) 
                                                 at android.app.Activity.performCreate(Activity.java:6237) 
                                                 at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
                                                 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
                                                 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
                                                 at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                                                 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
                                                 at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                 at android.os.Looper.loop(Looper.java:148) 
                                                 at android.app.ActivityThread.main(ActivityThread.java:5417) 
                                                 at java.lang.reflect.Method.invoke(Native Method) 
                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
                                              Caused by: java.lang.reflect.InvocationTargetException
                                                 at java.lang.reflect.Constructor.newInstance(Native Method)
                                                 at android.view.LayoutInflater.createView(LayoutInflater.java:619)
                                                 at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58) 
                                                 at android.view.LayoutInflater.onCreateView(LayoutInflater.java:694) 
                                                 at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:762) 
                                                 at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
                                                 at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:276) 
                                                 at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
                                                 at dynamochest.myapplication.phoneclass.onCreate(phoneclass.java:12) 
                                                 at android.app.Activity.performCreate(Activity.java:6237) 
                                                 at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
                                                 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
                                                 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
                                                 at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                                                 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
                                                 at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                 at android.os.Looper.loop(Looper.java:148) 
                                                 at android.app.ActivityThread.main(ActivityThread.java:5417) 
                                                 at java.lang.reflect.Method.invoke(Native Method) 
                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
                                              Caused by: java.lang.OutOfMemoryError: Failed to allocate a 12441612 byte allocation with 4194304 free bytes and 7MB 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:1080)
                                                 at android.content.res.Resources.loadDrawableForCookie(Resources.java:2635)
                                                 at android.content.res.Resources.loadDrawable(Resources.java:2540)
                                                 at android.content.res.TypedArray.getDrawable(TypedArray.java:870)
                                                 at android.view.View.<init>(View.java:3948)
                                                 at android.view.ViewGroup.<init>(ViewGroup.java:573)
                                                 at android.widget.LinearLayout.<init>(LinearLayout.java:203)
                                                 at android.widget.LinearLayout.<init>(LinearLayout.java:199)
                                                 at android.widget.LinearLayout.<init>(LinearLayout.java:195)
                                                 at java.lang.reflect.Constructor.newInstance(Native Method) 
                                                 at android.view.LayoutInflater.createView(LayoutInflater.java:619) 
                                                 at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58) 
                                                 at android.view.LayoutInflater.onCreateView(LayoutInflater.java:694) 
                                                 at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:762) 
                                                 at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
                                                 at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:276) 
                                                 at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
                                                 at dynamochest.myapplication.phoneclass.onCreate(phoneclass.java:12) 
                                                 at android.app.Activity.performCreate(Activity.java:6237) 
                                                 at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
                                                 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
                                                 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
                                                 at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                                                 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
                                                 at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                 at android.os.Looper.loop(Looper.java:148) 
                                                 at android.app.ActivityThread.main(ActivityThread.java:5417) 
                                                 at java.lang.reflect.Method.invoke(Native Method) 
                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 

This is really strange thing, everything works, but that 1 button.

Any Ideas where the problem hides?

Tadas
  • 166
  • 2
  • 12

3 Answers3

0

As I have traced your logcat, it's telling that the error seems to be caused by out of memory, which would usually occur when you have large sized images. Try to look at this link also, if this might help you. App crashes on change of ImageView.

Also, are you using an actual device or just an emulator? If you are using an emulator, try to increase size allocations. If you have a device that you can test, try it as well and check if you'll experience the same issue.

Community
  • 1
  • 1
fmpsagara
  • 485
  • 5
  • 17
0

I think you have large size images in your layout file which is causing the OutOfMemoryError. As the Android training guide states

If you're not careful, bitmaps can quickly consume your available memory budget leading to an application crash due to the dreaded exception: java.lang.OutofMemoryError: bitmap size exceeds VM budget.

You can try loading your images efficiently by following the lessons below

Displaying Bitmaps Efficiently

There are some good solutions to smiliar questions in SO

Out of memory error when inflating simple xml layout in android

Community
  • 1
  • 1
Prudhvi
  • 2,276
  • 7
  • 34
  • 54
-2

Try using "ActivityName.this" instead of just "this" in Intent intent = new Intent(this, phoneclass.class);

backslashN
  • 2,795
  • 3
  • 15
  • 25