我的申请有时会停止

时间:2014-12-06 17:27:37

标签: java android

我的Android应用程序当点击按钮它必须转到另一个布局..有时它正确,有时它已经停止.. 在某些设备中,它每次都可以工作,而在其他设备中,它有时可以工作,有时也不起作用。

这是我必须去的布局的xml文件:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".weddingActivity" >

<LinearLayout 
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:context=".weddingActivity" >

 <TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="enter your text here"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<EditText
    android:id="@+id/etFName"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ems="10" />
<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="choose your frame"
    android:textAppearance="?android:attr/textAppearanceLarge" />

   <ImageView
    android:id="@+id/w1"
    android:layout_width="122dp"
    android:layout_height="111dp"
    android:clickable="true"
    android:onClick="onClick"
    android:src="@drawable/w1" />

<ImageView
    android:id="@+id/w3"
    android:layout_width="122dp"
    android:layout_height="111dp"
    android:clickable="true"
    android:onClick="onClick"
    android:src="@drawable/w3" />
 <ImageView
    android:id="@+id/w4"
    android:layout_width="122dp"
    android:layout_height="111dp"
    android:clickable="true"
    android:onClick="onClick"
    android:src="@drawable/w4" />
  <ImageView
    android:id="@+id/w5"
    android:layout_width="122dp"
    android:layout_height="111dp"
    android:clickable="true"
    android:onClick="onClick"
    android:src="@drawable/w5" />
  <ImageView
    android:id="@+id/w6"
    android:layout_width="122dp"
    android:layout_height="111dp"
    android:clickable="true"
    android:onClick="onClick"
    android:src="@drawable/w6" />
   <ImageView
    android:id="@+id/w7"
    android:layout_width="122dp"
    android:layout_height="111dp"
    android:clickable="true"
    android:onClick="onClick"
    android:src="@drawable/w7" />
     <ImageView
    android:id="@+id/w8"
    android:layout_width="122dp"
    android:layout_height="111dp"
    android:clickable="true"
    android:onClick="onClick"
    android:src="@drawable/w8" />
       <ImageView
    android:id="@+id/w9"
    android:layout_width="122dp"
    android:layout_height="111dp"
    android:clickable="true"
    android:onClick="onClick"
    android:src="@drawable/w9" />
            <ImageView
    android:id="@+id/w10"
    android:layout_width="122dp"
    android:layout_height="111dp"
    android:clickable="true"
    android:onClick="onClick"
    android:src="@drawable/w10" />
                     <ImageView
    android:id="@+id/w11"
    android:layout_width="122dp"
    android:layout_height="111dp"
    android:clickable="true"
    android:onClick="onClick"
    android:src="@drawable/w11" />
  <ImageView
    android:id="@+id/w12"
    android:layout_width="122dp"
    android:layout_height="111dp"
    android:clickable="true"
    android:onClick="onClick"
    android:src="@drawable/w12" />
  <ImageView
    android:id="@+id/w14"
    android:layout_width="122dp"
    android:layout_height="111dp"
    android:clickable="true"
    android:onClick="onClick"
    android:src="@drawable/w14" />
  <ImageView
    android:id="@+id/w15"
    android:layout_width="122dp"
    android:layout_height="111dp"
    android:clickable="true"
    android:onClick="onClick"
    android:src="@drawable/w15" />
   <ImageView
    android:id="@+id/w16"
    android:layout_width="122dp"
    android:layout_height="111dp"
    android:clickable="true"
    android:onClick="onClick"
    android:src="@drawable/w16" />
</LinearLayout>
</ScrollView>

这是我的weddingActivity.java((我必须去)):

package com.example.invitationcard;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.Toast;
import android.widget.ImageView;


public class weddingActivity extends ActionBarActivity {
Button button;
ImageView imageView ;
 EditText etFName;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.wedding);
addListenerOnImagew1() ;  

etFName = (EditText) findViewById(R.id.etFName);
}

public void addListenerOnImagew1() {

    final Context context = this;

    imageView = (ImageView) findViewById(R.id.w1);

    imageView.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {

            Intent intent = new Intent(context, w1.class);
                        startActivity(intent);   
                        Intent intent1 = new Intent(context , w1.class); 
                        intent1.putExtra("fname" , etFName.getText().toString());
                        startActivity(intent1);

        }

    }); } 

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

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}

}

这是按钮的代码段,当我点击它时会出现问题:

 button = (Button) findViewById(R.id.buttonW);
 button.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {

            Intent intent = new Intent(context, weddingActivity.class);
                        startActivity(intent);   

        }

    }); } 

这是一个logcat

12-06 19:31:11.445: E/dalvikvm-heap(10195): Out of memory on a 30873616-byte allocation.
12-06 19:31:11.455: E/AndroidRuntime(10195): FATAL EXCEPTION: main
12-06 19:31:11.455: E/AndroidRuntime(10195): Process: com.example.invitationcard, PID: 10195
12-06 19:31:11.455: E/AndroidRuntime(10195): java.lang.RuntimeException: Unable to start             activity ComponentInfo{com.example.invitationcard/com.example.invitationcard.weddingActivity}:      android.view.InflateException: Binary XML file line #104: Error inflating class <unknown>
12-06 19:31:11.455: E/AndroidRuntime(10195):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2237)
12-06 19:31:11.455: E/AndroidRuntime(10195):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2286)
12-06 19:31:11.455: E/AndroidRuntime(10195):    at android.app.ActivityThread.access$800(ActivityThread.java:144)
12-06 19:31:11.455: E/AndroidRuntime(10195):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1246)
12-06 19:31:11.455: E/AndroidRuntime(10195):    at android.os.Handler.dispatchMessage(Handler.java:102)
12-06 19:31:11.455: E/AndroidRuntime(10195):    at android.os.Looper.loop(Looper.java:212)
12-06 19:31:11.455: E/AndroidRuntime(10195):    at android.app.ActivityThread.main(ActivityThread.java:5135)
12-06 19:31:11.455: E/AndroidRuntime(10195):    at java.lang.reflect.Method.invokeNative(Native Method)
12-06 19:31:11.455: E/AndroidRuntime(10195):    at java.lang.reflect.Method.invoke(Method.java:515)
12-06 19:31:11.455: E/AndroidRuntime(10195):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:877)
12-06 19:31:11.455: E/AndroidRuntime(10195):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)
12-06 19:31:11.455: E/AndroidRuntime(10195):    at dalvik.system.NativeStart.main(Native Method)
12-06 19:31:11.455: E/AndroidRuntime(10195): Caused by: android.view.InflateException: Binary XML file line #104: Error inflating class <unknown>
12-06 19:31:11.455: E/AndroidRuntime(10195):    at android.view.LayoutInflater.createView(LayoutInflater.java:620)
12-06 19:31:11.455: E/AndroidRuntime(10195):    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
12-06 19:31:11.455: E/AndroidRuntime(10195):    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
12-06 19:31:11.455: E/AndroidRuntime(10195):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
12-06 19:31:11.455: E/AndroidRuntime(10195):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
12-06 19:31:11.455: E/AndroidRuntime(10195):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
12-06 19:31:11.455: E/AndroidRuntime(10195):    at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
12-06 19:31:11.455: E/AndroidRuntime(10195):    at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
12-06 19:31:11.455: E/AndroidRuntime(10195):    at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
12-06 19:31:11.455: E/AndroidRuntime(10195):    at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:228)
12-06 19:31:11.455: E/AndroidRuntime(10195):    at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:102)
12-06 19:31:11.455: E/AndroidRuntime(10195):    at com.example.invitationcard.weddingActivity.onCreate(weddingActivity.java:27)
12-06 19:31:11.455: E/AndroidRuntime(10195):    at android.app.Activity.performCreate(Activity.java:5231)
12-06 19:31:11.455: E/AndroidRuntime(10195):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
12-06 19:31:11.455: E/AndroidRuntime(10195):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2201)
12-06 19:31:11.455: E/AndroidRuntime(10195):    ... 11 more
12-06 19:31:11.455: E/AndroidRuntime(10195): Caused by: java.lang.reflect.InvocationTargetException
12-06 19:31:11.455: E/AndroidRuntime(10195):    at java.lang.reflect.Constructor.constructNative(Native Method)
12-06 19:31:11.455: E/AndroidRuntime(10195):    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
12-06 19:31:11.455: E/AndroidRuntime(10195):    at android.view.LayoutInflater.createView(LayoutInflater.java:594)
12-06 19:31:11.455: E/AndroidRuntime(10195):    ... 25 more
12-06 19:31:11.455: E/AndroidRuntime(10195): Caused by: java.lang.OutOfMemoryError
12-06 19:31:11.455: E/AndroidRuntime(10195):    at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
12-06 19:31:11.455: E/AndroidRuntime(10195):    at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:594)
12-06 19:31:11.455: E/AndroidRuntime(10195):    at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:429)
12-06 19:31:11.455: E/AndroidRuntime(10195):    at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:856)
12-06 19:31:11.455: E/AndroidRuntime(10195):    at android.content.res.Resources.loadDrawable(Resources.java:2129)
12-06 19:31:11.455: E/AndroidRuntime(10195):    at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
12-06 19:31:11.455: E/AndroidRuntime(10195):    at android.widget.ImageView.<init>(ImageView.java:129)
12-06 19:31:11.455: E/AndroidRuntime(10195):    at android.widget.ImageView.<init>(ImageView.java:119)
12-06 19:31:11.455: E/AndroidRuntime(10195):    ... 28 more

1 个答案:

答案 0 :(得分:0)

  • 你有太多的图像视图,例如925 * 1300有点像维度,现在这不会总是在某些设备上运行但可能会运行或将在平板电脑上运行..所以修剪你的图像和它会一直工作..

    如果它适合修剪您的图像并将原始尺寸放在xxxhdpi文件夹中,并将图像修剪为较小的尺寸并将其放入您可能的hdpi文件夹中......或者如果您创建了一个&#34; drawable& #34;文件夹把它放在..所以android os将调用较小尺寸手机上的trimed图像调用平板电脑有点手机上的更大图像

  • 让事情变得更轻松google&#34;支持android中的屏幕尺寸&#34;你可以更好地预见如何在重新调整手机和平板电脑的尺寸方面做到这一点。

正如我所说,为了代表... 很好..