2014-09-25 82 views
0

我的程序將不再運行。它只是迫使關閉。我之前有兩張照片,我從互聯網上下載並放在我的可繪製文件夾中。但我刪除了雖然並添加了一些我從旅途中拍攝的照片。我更新了XML和Java代碼,但現在它不會打開。這是我的代碼。如何在android中創建照片應用程序?

package com.example.photoalbum;

import android.app.Activity; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.Button; 
import android.widget.ImageView; 


public class DisplayPhotos extends Activity 
{ 
ImageView iv1, iv2, iv3, iv4; 
private Integer [] imageArray = {R.drawable.nepal1, 
R.drawable.nepal2,R.drawable.nepal3, R.drawable.nepal4}; 

int imageCount = 0; 

//******************onCreate()******************************* 
@Override 
public void onCreate(Bundle b) 
{ 
    super.onCreate(b); 
    setContentView(R.layout.activity_display_photos); 
    Button btn1 = (Button) findViewById(R.id.previous_btn); 
    Button btn2 = (Button) findViewById(R.id.next_btn); 
    iv1 = (ImageView) findViewById(R.id.nepal1); 
    iv2 = (ImageView) findViewById(R.id.nepal2); 
    iv3 = (ImageView) findViewById(R.id.nepal3); 
    iv4 = (ImageView) findViewById(R.id.nepal4); 
    ImageView imgs [] = new ImageView[4]; 
    imgs[0] = iv1; 
    imgs[1] = iv2; 
    imgs[2] = iv3; 
    imgs[3] = iv4; 

    showImage(); 
} 
//*************************showImage()********************* 
public void showImage() 
{ 
    iv1.setImageResource(imageArray[imageCount]); 
} 


//***************************doit************************** 
    public void doit(View v) 
{ 
    switch (v.getId()) 
    { 
     case (R.id.previous_btn): 
      imageCount--; 
      if (imageCount == -1) 
       imageCount = 3; 
      showImage(); 
      break; 

     case (R.id.next_btn): 
      imageCount++; 
      if (imageCount == 4) 
       imageCount = 0; 
      showImage(); 
      break; 
    } 
} 
} 

我的XML代碼

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

<ImageView 
    android:id="@+id/nepal1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 

<ImageView 
    android:id="@+id/nepal2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"/> 
<ImageView 
    android:id="@+id/nepal3" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"/> 
<ImageView 
    android:id="@+id/nepal4" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 

    <Button 
     android:id="@+id/previous_btn" 
     android:layout_width="163dp" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom|left" 
     android:onClick="doit" 
     android:text="@string/previous" /> 

    <Button 
     android:id="@+id/next_btn" 
     android:layout_width="163dp" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom|right" 
     android:onClick="doit" 
     android:text="@string/next" /> 

</FrameLayout> 

我logcat的

09-24 20:09:42.243: D/dalvikvm(1750): GC_FOR_ALLOC freed 61K, 5% free 2941K/3084K, paused 44ms, total 47ms 
09-24 20:09:42.243: I/dalvikvm-heap(1750): Forcing collection of SoftReferences for 55987216-byte allocation 
09-24 20:09:42.303: D/dalvikvm(1750): GC_BEFORE_OOM freed 12K, 6% free 2929K/3084K, paused 62ms, total 62ms 
09-24 20:09:42.303: E/dalvikvm-heap(1750): Out of memory on a 55987216-byte allocation. 
09-24 20:09:42.313: I/dalvikvm(1750): "main" prio=5 tid=1 RUNNABLE 
09-24 20:09:42.313: I/dalvikvm(1750): | group="main" sCount=0 dsCount=0 obj=0xb3a76ca8 self=0xb75e2398 
09-24 20:09:42.313: I/dalvikvm(1750): | sysTid=1750 nice=0 sched=0/0 cgrp=apps handle=-1225387692 
09-24 20:09:42.323: I/dalvikvm(1750): | state=R schedstat=(570000000 1280000000 122) utm=31 stm=25 core=0 
09-24 20:09:42.323: I/dalvikvm(1750): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method) 
09-24 20:09:42.323: I/dalvikvm(1750): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:587) 
09-24 20:09:42.333: I/dalvikvm(1750): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:422) 
09-24 20:09:42.333: I/dalvikvm(1750): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:840) 
09-24 20:09:42.333: I/dalvikvm(1750): at android.content.res.Resources.loadDrawable(Resources.java:2110) 
09-24 20:09:42.333: I/dalvikvm(1750): at android.content.res.Resources.getDrawable(Resources.java:700) 
09-24 20:09:42.333: I/dalvikvm(1750): at android.widget.ImageView.resolveUri(ImageView.java:638) 
09-24 20:09:42.333: I/dalvikvm(1750): at android.widget.ImageView.setImageResource(ImageView.java:367) 
09-24 20:09:42.333: I/dalvikvm(1750): at com.example.photoalbum.DisplayPhotos.showImage(DisplayPhotos.java:50) 
09-24 20:09:42.333: I/dalvikvm(1750): at com.example.photoalbum.DisplayPhotos.onCreate(DisplayPhotos.java:45) 
09-24 20:09:42.333: I/dalvikvm(1750): at android.app.Activity.performCreate(Activity.java:5231) 
09-24 20:09:42.333: I/dalvikvm(1750): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 
09-24 20:09:42.333: I/dalvikvm(1750): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159) 
09-24 20:09:42.333: I/dalvikvm(1750): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245) 
09-24 20:09:42.333: I/dalvikvm(1750): at android.app.ActivityThread.access$800(ActivityThread.java:135) 
09-24 20:09:42.343: I/dalvikvm(1750): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 
09-24 20:09:42.343: I/dalvikvm(1750): at android.os.Handler.dispatchMessage(Handler.java:102) 
09-24 20:09:42.343: I/dalvikvm(1750): at android.os.Looper.loop(Looper.java:136) 
09-24 20:09:42.343: I/dalvikvm(1750): at android.app.ActivityThread.main(ActivityThread.java:5017) 
09-24 20:09:42.343: I/dalvikvm(1750): at java.lang.reflect.Method.invokeNative(Native Method) 
09-24 20:09:42.343: I/dalvikvm(1750): at java.lang.reflect.Method.invoke(Method.java:515) 
09-24 20:09:42.343: I/dalvikvm(1750): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) 
09-24 20:09:42.343: I/dalvikvm(1750): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) 
09-24 20:09:42.343: I/dalvikvm(1750): at dalvik.system.NativeStart.main(Native Method) 
09-24 20:09:42.343: D/skia(1750): --- decoder->decode returned false 
09-24 20:09:42.343: D/AndroidRuntime(1750): Shutting down VM 
09-24 20:09:42.343: W/dalvikvm(1750): threadid=1: thread exiting with uncaught exception (group=0xb3a75ba8) 
09-24 20:09:42.383: E/AndroidRuntime(1750): FATAL EXCEPTION: main 
09-24 20:09:42.383: E/AndroidRuntime(1750): Process: com.example.photoalbum, PID: 1750 
09-24 20:09:42.383: E/AndroidRuntime(1750): java.lang.OutOfMemoryError 
09-24 20:09:42.383: E/AndroidRuntime(1750):  at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method) 
09-24 20:09:42.383: E/AndroidRuntime(1750):  at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:587) 
09-24 20:09:42.383: E/AndroidRuntime(1750):  at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:422) 
09-24 20:09:42.383: E/AndroidRuntime(1750):  at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:840) 
09-24 20:09:42.383: E/AndroidRuntime(1750):  at android.content.res.Resources.loadDrawable(Resources.java:2110) 
09-24 20:09:42.383: E/AndroidRuntime(1750):  at android.content.res.Resources.getDrawable(Resources.java:700) 
09-24 20:09:42.383: E/AndroidRuntime(1750):  at android.widget.ImageView.resolveUri(ImageView.java:638) 
09-24 20:09:42.383: E/AndroidRuntime(1750):  at android.widget.ImageView.setImageResource(ImageView.java:367) 
09-24 20:09:42.383: E/AndroidRuntime(1750):  at com.example.photoalbum.DisplayPhotos.showImage(DisplayPhotos.java:50) 
09-24 20:09:42.383: E/AndroidRuntime(1750):  at com.example.photoalbum.DisplayPhotos.onCreate(DisplayPhotos.java:45) 
09-24 20:09:42.383: E/AndroidRuntime(1750):  at android.app.Activity.performCreate(Activity.java:5231) 
09-24 20:09:42.383: E/AndroidRuntime(1750):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 
09-24 20:09:42.383: E/AndroidRuntime(1750):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159) 
09-24 20:09:42.383: E/AndroidRuntime(1750):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245) 
09-24 20:09:42.383: E/AndroidRuntime(1750):  at android.app.ActivityThread.access$800(ActivityThread.java:135) 
09-24 20:09:42.383: E/AndroidRuntime(1750):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 
09-24 20:09:42.383: E/AndroidRuntime(1750):  at android.os.Handler.dispatchMessage(Handler.java:102) 
09-24 20:09:42.383: E/AndroidRuntime(1750):  at android.os.Looper.loop(Looper.java:136) 
09-24 20:09:42.383: E/AndroidRuntime(1750):  at android.app.ActivityThread.main(ActivityThread.java:5017) 
09-24 20:09:42.383: E/AndroidRuntime(1750):  at java.lang.reflect.Method.invokeNative(Native Method) 
09-24 20:09:42.383: E/AndroidRuntime(1750):  at java.lang.reflect.Method.invoke(Method.java:515) 
09-24 20:09:42.383: E/AndroidRuntime(1750):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) 
09-24 20:09:42.383: E/AndroidRuntime(1750):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) 
09-24 20:09:42.383: E/AndroidRuntime(1750):  at dalvik.system.NativeStart.main(Native Method) 
09-24 20:09:51.043: I/Process(1750): Sending signal. PID: 1750 SIG: 9 

回答

相關問題