我的应用总是不幸的是应用已经停止当我使用任何媒体内容,例如 ImageView 每次我使用任何imageView停止时
我的应用程序是如此基本只有拖动活动 MainActivity 只有按下它时它会导致我 SecondActivity 第二个活动有 ImageView和TextView
如果我删除了ImageView它的工作完美,但是当我尝试使用它停止的imageview时:(任何想法?
activity_secound.xml
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/toggleButton1"
android:layout_centerHorizontal="true"
android:src="@drawable/img_compass" />
MainActivity.java
public class MainActivity extends Activity {
private static Button btn_med;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
OnClickButtonListener1();
}
public void OnClickButtonListener1() {
btn_med = (Button) findViewById(R.id.btn_med);
btn_med.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intentMed = new Intent("hayderhussien.apps.qruan.QuranMedia");
startActivity(intentMed);
}
}
);
}
}
ERRLOG
08-06 12:28:43.502: W/ApplicationPackageManager(16134): getCSCPackageItemText()
08-06 12:28:43.542: E/MoreInfoHPW_ViewGroup(16134): Parent view is not a TextView
08-06 12:28:43.592: I/Adreno-EGL(16134): <qeglDrvAPI_eglInitialize:410>: EGL 1.4 QUALCOMM build: ()
08-06 12:28:43.592: I/Adreno-EGL(16134): OpenGL ES Shader Compiler Version: E031.24.00.08+13
08-06 12:28:43.592: I/Adreno-EGL(16134): Build Date: 03/28/14 Fri
08-06 12:28:43.592: I/Adreno-EGL(16134): Local Branch: 0328_AU200_patches
08-06 12:28:43.592: I/Adreno-EGL(16134): Remote Branch:
08-06 12:28:43.592: I/Adreno-EGL(16134): Local Patches:
08-06 12:28:43.592: I/Adreno-EGL(16134): Reconstruct Branch:
08-06 12:28:43.622: D/OpenGLRenderer(16134): Enabling debug mode 0
08-06 12:28:45.322: W/ApplicationPackageManager(16134): getCSCPackageItemText()
08-06 12:28:45.332: E/MoreInfoHPW_ViewGroup(16134): Parent view is not a TextView
08-06 12:28:45.342: D/Switch(16134): mDensity : 480.0
08-06 12:28:45.642: D/dalvikvm(16134): GC_FOR_ALLOC freed 111K, 33% free 17749K/26256K, paused 13ms, total 13ms
08-06 12:28:45.642: I/dalvikvm-heap(16134): Forcing collection of SoftReferences for 370830040-byte allocation
08-06 12:28:45.662: D/dalvikvm(16134): GC_BEFORE_OOM freed 15K, 33% free 17733K/26256K, paused 19ms, total 19ms
08-06 12:28:45.662: E/dalvikvm-heap(16134): Out of memory on a 370830040-byte allocation.
08-06 12:28:45.662: I/dalvikvm(16134): "main" prio=5 tid=1 RUNNABLE
08-06 12:28:45.662: I/dalvikvm(16134): | group="main" sCount=0 dsCount=0 obj=0x4173eea0 self=0x4163eab0
08-06 12:28:45.662: I/dalvikvm(16134): | sysTid=16134 nice=0 sched=0/0 cgrp=apps handle=1074180436
08-06 12:28:45.662: I/dalvikvm(16134): | state=R schedstat=( 490381792 58729879 489 ) utm=33 stm=16 core=0
08-06 12:28:45.662: I/dalvikvm(16134): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
08-06 12:28:45.662: I/dalvikvm(16134): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:677)
08-06 12:28:45.672: I/dalvikvm(16134): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:507)
08-06 12:28:45.672: I/dalvikvm(16134): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:872)
08-06 12:28:45.672: I/dalvikvm(16134): at android.content.res.Resources.loadDrawable(Resources.java:3022)
08-06 12:28:45.672: I/dalvikvm(16134): at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
08-06 12:28:45.672: I/dalvikvm(16134): at android.widget.ImageView.<init>(ImageView.java:133)
08-06 12:28:45.672: I/dalvikvm(16134): at android.widget.ImageView.<init>(ImageView.java:123)
08-06 12:28:45.672: I/dalvikvm(16134): at java.lang.reflect.Constructor.constructNative(Native Method)
08-06 12:28:45.672: I/dalvikvm(16134): at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
08-06 12:28:45.672: I/dalvikvm(16134): at android.view.LayoutInflater.createView(LayoutInflater.java:600)
08-06 12:28:45.672: I/dalvikvm(16134): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
08-06 12:28:45.672: I/dalvikvm(16134): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:675)
08-06 12:28:45.672: I/dalvikvm(16134): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:700)
08-06 12:28:45.672: I/dalvikvm(16134): at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
08-06 12:28:45.672: I/dalvikvm(16134): at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
08-06 12:28:45.672: I/dalvikvm(16134): at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
08-06 12:28:45.672: I/dalvikvm(16134): at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
08-06 12:28:45.672: I/dalvikvm(16134): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:340)
08-06 12:28:45.672: I/dalvikvm(16134): at android.app.Activity.setContentView(Activity.java:1978)
08-06 12:28:45.672: I/dalvikvm(16134): at hayderhussien.apps.qruan.QuranMedia.onCreate(QuranMedia.java:14)
08-06 12:28:45.672: I/dalvikvm(16134): at android.app.Activity.performCreate(Activity.java:5394)
08-06 12:28:45.672: I/dalvikvm(16134): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
08-06 12:28:45.672: I/dalvikvm(16134): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2246)
08-06 12:28:45.672: I/dalvikvm(16134): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2340)
08-06 12:28:45.672: I/dalvikvm(16134): at android.app.ActivityThread.access$800(ActivityThread.java:157)
08-06 12:28:45.672: I/dalvikvm(16134): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1247)
08-06 12:28:45.672: I/dalvikvm(16134): at android.os.Handler.dispatchMessage(Handler.java:102)
08-06 12:28:45.672: I/dalvikvm(16134): at android.os.Looper.loop(Looper.java:157)
08-06 12:28:45.672: I/dalvikvm(16134): at android.app.ActivityThread.main(ActivityThread.java:5293)
08-06 12:28:45.672: I/dalvikvm(16134): at java.lang.reflect.Method.invokeNative(Native Method)
08-06 12:28:45.672: I/dalvikvm(16134): at java.lang.reflect.Method.invoke(Method.java:515)
08-06 12:28:45.672: I/dalvikvm(16134): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
08-06 12:28:45.672: I/dalvikvm(16134): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
08-06 12:28:45.672: I/dalvikvm(16134): at dalvik.system.NativeStart.main(Native Method)
08-06 12:28:45.672: D/skia(16134): --- allocation failed for scaled bitmap
08-06 12:28:45.692: D/AndroidRuntime(16134): Shutting down VM
08-06 12:28:45.692: W/dalvikvm(16134): threadid=1: thread exiting with uncaught exception (group=0x4173dda0)
08-06 12:28:45.692: E/AndroidRuntime(16134): FATAL EXCEPTION: main
08-06 12:28:45.692: E/AndroidRuntime(16134): Process: hayderhussien.apps.qruan, PID: 16134
08-06 12:28:45.692: E/AndroidRuntime(16134): java.lang.RuntimeException: Unable to start activity ComponentInfo{hayderhussien.apps.qruan/hayderhussien.apps.qruan.QuranMedia}: android.view.InflateException: Binary XML file line #48: Error inflating class <unknown>
08-06 12:28:45.692: E/AndroidRuntime(16134): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2282)
08-06 12:28:45.692: E/AndroidRuntime(16134): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2340)
08-06 12:28:45.692: E/AndroidRuntime(16134): at android.app.ActivityThread.access$800(ActivityThread.java:157)
08-06 12:28:45.692: E/AndroidRuntime(16134): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1247)
08-06 12:28:45.692: E/AndroidRuntime(16134): at android.os.Handler.dispatchMessage(Handler.java:102)
08-06 12:28:45.692: E/AndroidRuntime(16134): at android.os.Looper.loop(Looper.java:157)
08-06 12:28:45.692: E/AndroidRuntime(16134): at android.app.ActivityThread.main(ActivityThread.java:5293)
08-06 12:28:45.692: E/AndroidRuntime(16134): at java.lang.reflect.Method.invokeNative(Native Method)
08-06 12:28:45.692: E/AndroidRuntime(16134): at java.lang.reflect.Method.invoke(Method.java:515)
08-06 12:28:45.692: E/AndroidRuntime(16134): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
08-06 12:28:45.692: E/AndroidRuntime(16134): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
08-06 12:28:45.692: E/AndroidRuntime(16134): at dalvik.system.NativeStart.main(Native Method)
08-06 12:28:45.692: E/AndroidRuntime(16134): Caused by: android.view.InflateException: Binary XML file line #48: Error inflating class <unknown>
08-06 12:28:45.692: E/AndroidRuntime(16134): at android.view.LayoutInflater.createView(LayoutInflater.java:626)
08-06 12:28:45.692: E/AndroidRuntime(16134): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
08-06 12:28:45.692: E/AndroidRuntime(16134): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:675)
08-06 12:28:45.692: E/AndroidRuntime(16134): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:700)
08-06 12:28:45.692: E/AndroidRuntime(16134): at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
08-06 12:28:45.692: E/AndroidRuntime(16134): at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
08-06 12:28:45.692: E/AndroidRuntime(16134): at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
08-06 12:28:45.692: E/AndroidRuntime(16134): at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
08-06 12:28:45.692: E/AndroidRuntime(16134): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:340)
08-06 12:28:45.692: E/AndroidRuntime(16134): at android.app.Activity.setContentView(Activity.java:1978)
08-06 12:28:45.692: E/AndroidRuntime(16134): at hayderhussien.apps.qruan.QuranMedia.onCreate(QuranMedia.java:14)
08-06 12:28:45.692: E/AndroidRuntime(16134): at android.app.Activity.performCreate(Activity.java:5394)
08-06 12:28:45.692: E/AndroidRuntime(16134): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
08-06 12:28:45.692: E/AndroidRuntime(16134): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2246)
08-06 12:28:45.692: E/AndroidRuntime(16134): ... 11 more
08-06 12:28:45.692: E/AndroidRuntime(16134): Caused by: java.lang.reflect.InvocationTargetException
08-06 12:28:45.692: E/AndroidRuntime(16134): at java.lang.reflect.Constructor.constructNative(Native Method)
08-06 12:28:45.692: E/AndroidRuntime(16134): at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
08-06 12:28:45.692: E/AndroidRuntime(16134): at android.view.LayoutInflater.createView(LayoutInflater.java:600)
08-06 12:28:45.692: E/AndroidRuntime(16134): ... 24 more
08-06 12:28:45.692: E/AndroidRuntime(16134): Caused by: java.lang.OutOfMemoryError
08-06 12:28:45.692: E/AndroidRuntime(16134): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
08-06 12:28:45.692: E/AndroidRuntime(16134): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:677)
08-06 12:28:45.692: E/AndroidRuntime(16134): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:507)
08-06 12:28:45.692: E/AndroidRuntime(16134): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:872)
08-06 12:28:45.692: E/AndroidRuntime(16134): at android.content.res.Resources.loadDrawable(Resources.java:3022)
08-06 12:28:45.692: E/AndroidRuntime(16134): at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
08-06 12:28:45.692: E/AndroidRuntime(16134): at android.widget.ImageView.<init>(ImageView.java:133)
08-06 12:28:45.692: E/AndroidRuntime(16134): at android.widget.ImageView.<init>(ImageView.java:123)
08-06 12:28:45.692: E/AndroidRuntime(16134): ... 27 more
mysecound活动代码
import android.app.Activity;
import android.os.Bundle;
public class QuranMedia extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_quran_media);
}
}
的Manifest.xml
<application
android:allowBackup="true"
android:icon="@android:drawable/ic_media_play"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
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=".QuranMedia"
android:label="@string/title_activity_quran_media" >
<intent-filter>
<action android:name="hayderhussien.apps.qruan.QuranMedia" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
secound活动
<RelativeLayout 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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="hayderhussien.apps.qruan.QuranMedia" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<ImageView
android:id="@+id/img1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/toggleButton1"
android:layout_centerHorizontal="true"
android:src="@drawable/img_compass" />
</RelativeLayout>
答案 0 :(得分:2)
Intent intentMed = new Intent(MainActivity.this,SecoundActivity.class);
startActivity(intentMed);
请试试这个。
答案 1 :(得分:1)
java.lang.RuntimeException: Unable to start activity ComponentInfo{hayderhussien.apps.qruan/hayderhussien.apps.qruan.QuranMedia}: android.view.InflateException: Binary XML file line #48: Error inflating class <unknown>
以上错误原因是您的ImageView
尺寸。您是直接从drawable文件夹加载图片而不使用位图图片尺寸。请尝试使用位图并将图片调整为适合您应用的方便尺寸refere here并尝试开始第二个Activity
,如下所述。
'Intent intentMed = new Intent(MainActivity.this,SecoundActivity.class);
startActivity(intentMed);
注意:由于图像尺寸问题,您有另一个错误Caused by: java.lang.OutOfMemoryError
按照以下两个步骤解决错误。
Activity
,如上面的代码所示。