0

嗨,我是 android 编码方面的业余爱好者,但到目前为止我已经设法做到了,但遇到了一个相对简单的问题,第一个屏幕我插入了一些文本,然后打印到下一个屏幕,那里还有几个按钮,我还只定义了其中一个的意图,它曾经显示第二个活动,然后当我单击第二个活动的按钮时强制关闭,但现在它甚至无法进入第二个活动。我想要的只是第一个活动来显示下一个活动,然后按钮打开单独的活动,谁能告诉我哪里出错了?

沐浴活动.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;
}

}

不要认为这是一个明显的问题,但以防万一

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>

这不可能是您要求的 logcat 吗?

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

这是我的错误吗?

 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}: 
4

2 回答 2

4

Out of memory on a 42701840-byte allocation. 当您尝试为您的图像视图加载时,这看起来像是内存不足问题android:src="@drawable/getdressedimg"。图片有多大?如果它太大,您需要按比例缩小以匹配 ImageView 的高度和宽度。检查此页面以了解如何执行此操作。

于 2013-09-25T00:26:39.573 回答
0

您没有提到默认的沐浴能力。像这样 :

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

只需将上面的代码复制并粘贴到清单 .xml 中,而不是

<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>
于 2013-09-25T00:29:58.607 回答