Question

Hi I am a rank amateur at coding in android yet I've managed to get so far but have come up with a problem with something relatively simple, first screen i plug in some text which is then printed to the next screen where there are also a few buttons, i have as yet only defined an intent to one of those, It used to display the second activity and then force close when i clicked a button on second activity, but now it cannot even get to secondactivity. all i want is the first activity to display the next activity where the buttons then open seperate activities can anybody tell me where i've gone wrong?

bathactviity.java

package com.example.myapplication;


import android.os.Bundle;
import android.app.Activity;
import android.widget.Button;

public class bathactivity extends Activity {
Button button;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_bath);
    button = (Button)findViewById(R.id.nextbutton);




     }



}

activity_bath.xml

<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">

<TextView
    android:layout_width="match_parent"
    android:layout_height="55dp"
    android:text="@string/bath"
    android:id="@+id/bath_text_View"
    android:textSize="20sp"
    android:gravity="center"
    android:textStyle="italic" />

<ImageView
    android:contentDescription="@string/bath"
    android:layout_width="match_parent"
    android:layout_height="404dp"
    android:id="@+id/imageView"
    android:layout_gravity="center"
    android:src="@drawable/getdressedimg" />

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/next"
    android:id="@+id/nextbutton"
    android:textSize="20sp"
    android:textStyle="bold|italic"
    android:layout_gravity="center" />
</LinearLayout>



secondactivity.java

package com.example.myapplication;

import android.content.Intent;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.Button;
import android.widget.TextView;

public class secondactivity extends Activity {
TextView t;
Button button;
Button button2;
Button button3;
Button button4;






 @Override
 protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_second);
    t = (TextView)findViewById(R.id.textView3);
    String n = this.getIntent().getStringExtra("NAMEDATA");
    t.setText(n);
    button = (Button)findViewById(R.id.button);
    button2 = (Button)findViewById(R.id.button2);
    button3 = (Button)findViewById(R.id.button3);
    button4 = (Button)findViewById(R.id.button4);

    setButtonOnClickListener();

  }


   private void setButtonOnClickListener(){
    Intent intent = new Intent(getApplicationContext(), bathactivity.class);
    startActivity(intent);
}






@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.second, menu);
    return true;
}

}

dont think its a manifest issue but just in case

android manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapplication"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="7"
    android:targetSdkVersion="18" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.myapplication.main"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.example.myapplication.secondactivity"
        android:label="@string/title_activity_second" >
    </activity>
    <activity
        android:name="com.example.myapplication.bathactivity"
        android:label="@string/title_activity_bath" >
    </activity>

  </application>

  </manifest>

this cant be the logcat your asking for is it?

09-24 23:35:55.286    9460-9460/com.example.myapplication I/dalvikvm-heap﹕ Grow heap (frag case) to 10.498MB for 6860716-byte allocation
09-24 23:35:55.546    9460-9460/com.example.myapplication I/dalvikvm-heap﹕ Grow heap (frag case) to 22.127MB for 12196816-byte allocation
09-24 23:35:55.716    9460-9460/com.example.myapplication E/﹕ file /data/data/com.nvidia.NvCPLSvc/files/driverlist.txt: not found!
09-24 23:35:55.716    9460-9460/com.example.myapplication I/﹕ Attempting to load EGL implementation /system/lib//egl/libEGL_tegra_impl
09-24 23:35:55.736    9460-9460/com.example.myapplication I/﹕ Loaded EGL implementation /system/lib//egl/libEGL_tegra_impl
09-24 23:35:55.796    9460-9460/com.example.myapplication I/﹕ Loading GLESv2 implementation /system/lib//egl/libGLESv2_tegra_impl
09-24 23:36:01.116    9460-9460/com.example.myapplication W/Editor﹕ GetLabel fail! Do framework orig behavior
09-24 23:36:05.191    9460-9460/com.example.myapplication I/dalvikvm-heap﹕ Grow heap (frag case) to 38.710MB for 24023056-byte allocation
09-24 23:36:05.471    9460-9460/com.example.myapplication I/dalvikvm-heap﹕ Forcing collection of SoftReferences for 42701840-byte allocation
09-24 23:36:05.496    9460-9460/com.example.myapplication E/dalvikvm-heap﹕ Out of memory on a 42701840-byte allocation.
09-24 23:36:05.496    9460-9460/com.example.myapplication I/dalvikvm﹕ "main" prio=5 tid=1 RUNNABLE
09-24 23:36:05.496    9460-9460/com.example.myapplication I/dalvikvm﹕ | group="main" sCount=0 dsCount=0 obj=0x41bf5538 self=0x40cff010
09-24 23:36:05.496    9460-9460/com.example.myapplication I/dalvikvm﹕ | sysTid=9460 nice=0 sched=0/0 cgrp=apps handle=1075005484
09-24 23:36:05.496    9460-9460/com.example.myapplication I/dalvikvm﹕ | schedstat=( 1258665000 280174000 1050 ) utm=92 stm=33 core=3
09-24 23:36:05.496    9460-9460/com.example.myapplication I/dalvikvm﹕ at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
09-24 23:36:05.501    9460-9460/com.example.myapplication I/dalvikvm﹕ at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:626)
09-24 23:36:05.501    9460-9460/com.example.myapplication I/dalvikvm﹕ at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:473)
09-24 23:36:05.506    9460-9460/com.example.myapplication I/dalvikvm﹕ at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:781)
09-24 23:36:05.506    9460-9460/com.example.myapplication I/dalvikvm﹕ at android.content.res.Resources.loadDrawable(Resources.java:1959)
09-24 23:36:05.506    9460-9460/com.example.myapplication I/dalvikvm﹕ at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
09-24 23:36:05.506    9460-9460/com.example.myapplication I/dalvikvm﹕ at android.widget.ImageView.<init>(ImageView.java:120)
09-24 23:36:05.506    9460-9460/com.example.myapplication I/dalvikvm﹕ at android.widget.ImageView.<init>(ImageView.java:110)
09-24 23:36:05.506    9460-9460/com.example.myapplication I/dalvikvm﹕ at java.lang.reflect.Constructor.constructNative(Native Method)
09-24 23:36:05.506    9460-9460/com.example.myapplication I/dalvikvm﹕ at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
09-24 23:36:05.511    9460-9460/com.example.myapplication I/dalvikvm﹕ at android.view.LayoutInflater.createView(LayoutInflater.java:587)
09-24 23:36:05.511    9460-9460/com.example.myapplication I/dalvikvm﹕ at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
09-24 23:36:05.511    9460-9460/com.example.myapplication I/dalvikvm﹕ at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
09-24 23:36:05.511    9460-9460/com.example.myapplication I/dalvikvm﹕ at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
09-24 23:36:05.511    9460-9460/com.example.myapplication I/dalvikvm﹕ at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
09-24 23:36:05.511    9460-9460/com.example.myapplication I/dalvikvm﹕ at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
09-24 23:36:05.511    9460-9460/com.example.myapplication I/dalvikvm﹕ at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
09-24 23:36:05.511    9460-9460/com.example.myapplication I/dalvikvm﹕ at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
09-24 23:36:05.511    9460-9460/com.example.myapplication I/dalvikvm﹕ at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:365)
09-24 23:36:05.516    9460-9460/com.example.myapplication I/dalvikvm﹕ at android.app.Activity.setContentView(Activity.java:1912)
09-24 23:36:05.521    9460-9460/com.example.myapplication I/dalvikvm﹕ at com.example.myapplication.bathactivity.onCreate(bathactivity.java:14)
09-24 23:36:05.521    9460-9460/com.example.myapplication I/dalvikvm﹕ at android.app.Activity.performCreate(Activity.java:5066)
09-24 23:36:05.521    9460-9460/com.example.myapplication I/dalvikvm﹕ at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1101)
09-24 23:36:05.521    9460-9460/com.example.myapplication I/dalvikvm﹕ at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2307)
09-24 23:36:05.521    9460-9460/com.example.myapplication I/dalvikvm﹕ at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
09-24 23:36:05.521    9460-9460/com.example.myapplication I/dalvikvm﹕ at android.app.ActivityThread.access$600(ActivityThread.java:151)
09-24 23:36:05.521    9460-9460/com.example.myapplication I/dalvikvm﹕ at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1331)
09-24 23:36:05.521    9460-9460/com.example.myapplication I/dalvikvm﹕ at android.os.Handler.dispatchMessage(Handler.java:99)
09-24 23:36:05.521    9460-9460/com.example.myapplication I/dalvikvm﹕ at android.os.Looper.loop(Looper.java:155)
09-24 23:36:05.521    9460-9460/com.example.myapplication I/dalvikvm﹕ at android.app.ActivityThread.main(ActivityThread.java:5485)
09-24 23:36:05.521    9460-9460/com.example.myapplication I/dalvikvm﹕ at java.lang.reflect.Method.invokeNative(Native Method)
09-24 23:36:05.521    9460-9460/com.example.myapplication I/dalvikvm﹕ at java.lang.reflect.Method.invoke(Method.java:511)
09-24 23:36:05.521    9460-9460/com.example.myapplication I/dalvikvm﹕ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1028)
09-24 23:36:05.521    9460-9460/com.example.myapplication I/dalvikvm﹕ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:795)
09-24 23:36:05.521    9460-9460/com.example.myapplication I/dalvikvm﹕ at dalvik.system.NativeStart.main(Native Method)
09-24 23:36:05.521    9460-9460/com.example.myapplication I/dalvikvm﹕ [ 09-24 23:36:05.521  9460: 9460 E/dalvikvm ]
        Out of memory: Heap Size=47011KB, Allocated=38523KB, Limit=65536KB
09-24 23:36:05.521    9460-9460/com.example.myapplication E/dalvikvm﹕ Extra info: Footprint=46947KB, Allowed Footprint=47011KB, Trimmed=1472KB
09-24 23:36:05.521    9460-9460/com.example.myapplication D/skia﹕ --- Unable to allocate space, reportSizeToVM = true
09-24 23:36:05.526    9460-9460/com.example.myapplication W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x41bf42d0)
09-24 23:36:05.531    9460-9460/com.example.myapplication E/AndroidRuntime﹕ FATAL EXCEPTION: main
        java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myapplication/com.example.myapplication.bathactivity}: android.view.InflateException: Binary XML file line #16: Error inflating class <unknown>
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2351)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
        at android.app.ActivityThread.access$600(ActivityThread.java:151)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1331)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:155)
        at android.app.ActivityThread.main(ActivityThread.java:5485)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:511)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1028)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:795)
        at dalvik.system.NativeStart.main(Native Method)
        Caused by: android.view.InflateException: Binary XML file line #16: Error inflating class <unknown>
        at android.view.LayoutInflater.createView(LayoutInflater.java:613)
        at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
        at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
        at      com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:365)
        at android.app.Activity.setContentView(Activity.java:1912)
        at com.example.myapplication.bathactivity.onCreate(bathactivity.java:14)
        at android.app.Activity.performCreate(Activity.java:5066)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1101)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2307)
        ... 11 more
        Caused by: java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Constructor.constructNative(Native Method)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
        at android.view.LayoutInflater.createView(LayoutInflater.java:587)
        ... 24 more
        Caused by: java.lang.OutOfMemoryError: (Heap Size=47011KB, Allocated=38523KB)
        at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
        at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:626)
        at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:473)
        at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:781)
        at android.content.res.Resources.loadDrawable(Resources.java:1959)
        at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
        at android.widget.ImageView.<init>(ImageView.java:120)
        at android.widget.ImageView.<init>(ImageView.java:110)
        ... 27 more

is this my error?;

 D/skia﹕ --- Unable to allocate space, reportSizeToVM = true 09-24 23:36:05.526 
9460-9460/com.example.myapplication W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x41bf42d0) 09-24 23:36:05.531 
9460-9460/com.example.myapplication E/AndroidRuntime﹕ FATAL EXCEPTION: main 
java.lang.RuntimeException: Unable to start activity 
ComponentInfo{com.example.myapplication/com.example.myapplication.bathactivity}: 
Was it helpful?

Solution

Out of memory on a 42701840-byte allocation. This looks like a Out of Memory issue when you try loading the android:src="@drawable/getdressedimg" for your imageview. How big is the Image? If its too big, you need to scale down to match the ImageView height and width. Check this page on how to do that.

OTHER TIPS

You did not mention the bathacivity as default. like this :

<activity
        android:name=".Bathactivity"
        android:label="@string/app_name"
        android:screenOrientation="portrait" >
        <intent-filter>
            <action android:name="com.example.myapplication.BATHACTIVITY" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

just copy and paste the above code in manifest .xml instead of

<activity
    android:name="com.example.myapplication.secondactivity"
    android:label="@string/title_activity_second" >
</activity>
<activity
    android:name="com.example.myapplication.bathactivity"
    android:label="@string/title_activity_bath" >
</activity>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top