在我正在制作的一个飞扬的鸟类游戏中,我之前遇到了java.lang.RuntimeException: Unable to start activity ComponentInfo{com.app.gb.socilizer_app/com.app.gb.socilizer.Activities.ProfileActivity}: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.get(ArrayList.java:411)
at com.app.garethbecker.socializer.Activities.ProfileActivity.onCreate(ProfileActivity.java:39)
at android.app.Activity.performCreate(Activity.java:6679)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
的问题。我在error #1009
之间解决了一些问题,同时在帧之间进行了切换,但仍然存在一些问题。Here's my file.。请帮忙。
问题出现在removeEventListeners
,slide
和obstposi
函数中。代码在这里:
range
和slide
函数:
obstposi
var start = false;
stage.addEventListener(Event.ENTER_FRAME, slide);
stage.addEventListener(Event.ENTER_FRAME, obstposi);
function slide(event: Event) {
if (dead != true) {
p1.x -= 5;
p2.x -= 5;
p3.x -= 5;
p4.x -= 5;
p5.x -= 5;
p6.x -= 5;
p7.x -= 5;
p8.x -= 5;
scorein1.x -= 5;
scorein2.x -= 5;
scorein3.x -= 5;
scorein4.x -= 5;
}
if (flappy.hitTestObject(p1)) {
dead = true;
} else if (flappy.hitTestObject(p2)) {
dead = true;
} else if (flappy.hitTestObject(p3)) {
dead = true;
} else if (flappy.hitTestObject(p4)) {
dead = true;
} else if (flappy.hitTestObject(p5)) {
dead = true;
} else if (flappy.hitTestObject(p6)) {
dead = true;
} else if (flappy.hitTestObject(p7)) {
dead = true;
} else if (flappy.hitTestObject(p8)) {
dead = true;
}
}
function obstposi(event: Event) {
if (flappy.hitTestObject(scorein4)) {
scorein1.x = 702.3;
p1.x = 650;
p2.x = 650;
p1.y = Math.ceil(Math.random() * 300) + 305;
p2.y = p1.y - 335;
start = true;
} else if (flappy.hitTestObject(scorein1) && start == true) {
scorein2.x = 702.3;
p3.x = 650;
p4.x = 650;
p4.y = Math.ceil(Math.random() * -300) + 305;
p3.y = p4.y - 335;
} else if (flappy.hitTestObject(scorein2) && start == true) {
scorein3.x = 702.3;
p5.x = 650;
p6.x = 650;
p6.y = Math.ceil(Math.random() * -300) + 305;
p5.y = p6.y - 335;
} else if (flappy.hitTestObject(scorein3) && start == true) {
scorein4.x = 702.3;
p7.x = 650;
p8.x = 650;
p8.y = Math.ceil(Math.random() * -300) + 305;
p7.y = p8.y - 335;
}
}
功能:
range
答案 0 :(得分:0)
您的代码问题在于,即使您的场景中不存在 StorageReference storageRef = storage.getReferenceFromUrl(---STORAGE_BUCKET---);
StorageReference imagePathReference = storageRef.child("image");
final Uri uri = data.getData();
Bitmap bmp = null;
try {
bmp = MediaStore.Images.Media.getBitmap(getContentResolver(), data.getData());
} catch (IOException e) {
e.printStackTrace();
}
// convert bitmap to byte array to save image in firebase storage
ByteArrayOutputStream bos = new ByteArrayOutputStream();
if (bmp != null) {
bmp.compress(Bitmap.CompressFormat.JPEG, 60, bos);
}
byte[] dataNew = bos.toByteArray();
uploadTask = imagePathReference.putBytes(dataNew);
try {
uploadTask.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
// success
}
});
}catch (Exception e){
}
,flappy
等对象,您也可以使该功能正常工作。因此,在开始之前,您可以添加ground
,以便只有在阶段中存在if(flappy != null)
时才能使代码正常工作。