Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/181.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android Studio应用程序停止工作_Java_Android - Fatal编程技术网

Java Android Studio应用程序停止工作

Java Android Studio应用程序停止工作,java,android,Java,Android,我可以在我的项目中放多少活动多少张图片?我做了一个项目,现在有13个活动,当我有5到8个活动时,我的项目运行得非常好。没有堆叠,没有崩溃,现在我有13个活动,当我构建我的项目并打开它时,欢迎屏幕工作,我可以打开一个、两个或三个其他活动,但打开4个或5个活动,我的应用程序停止工作并崩溃。我认为这是内存不足,但我不明白为什么会发生这种情况,因为我已经调整了所有位图的大小并对其进行了压缩,当我在startActivity()之后启动新活动时,我将finish() 下面是nocnizivotActivi

我可以在我的项目中放多少活动多少张图片?我做了一个项目,现在有13个活动,当我有5到8个活动时,我的项目运行得非常好。没有堆叠,没有崩溃,现在我有13个活动,当我构建我的项目并打开它时,欢迎屏幕工作,我可以打开一个、两个或三个其他活动,但打开4个或5个活动,我的应用程序停止工作并崩溃。我认为这是内存不足,但我不明白为什么会发生这种情况,因为我已经调整了所有位图的大小并对其进行了压缩,当我在
startActivity()
之后启动新活动时,我将
finish()

下面是nocnizivotActivity.java中的一个java代码

package teslicinfo.teslic;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

public class nocnizivotActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_nocnizivot);

//tnt
LinearLayout lyt_tnt =(LinearLayout)findViewById(R.id.lyt_tnt);
lyt_tnt.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        Intent i = new Intent(getApplicationContext(), diskotekeActivity.class);
        i.putExtra("data", "tnt");
        startActivity(i);
        finish();
    }
});

//moja kafanica
LinearLayout lyt_mojakafanica =(LinearLayout)findViewById(R.id.lyt_mojakafanica);
lyt_mojakafanica.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        Intent i = new Intent(getApplicationContext(), diskotekeActivity.class);
        i.putExtra("data", "mojakafanica");
        startActivity(i);
        finish();
    }
});

//kaktus
LinearLayout lyt_kaktus =(LinearLayout)findViewById(R.id.lyt_kaktus);
lyt_kaktus.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        Intent i = new Intent(getApplicationContext(), diskotekeActivity.class);
        i.putExtra("data", "kaktus");
        startActivity(i);
        finish();
    }
});

//caffex
LinearLayout lyt_caffex =(LinearLayout)findViewById(R.id.lyt_caffex);
lyt_caffex.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        Intent i = new Intent(getApplicationContext(), diskotekeActivity.class);
        i.putExtra("data", "caffex");
        startActivity(i);
        finish();
    }
});

//faraon
LinearLayout lyt_faraon =(LinearLayout)findViewById(R.id.lyt_faraon);
lyt_faraon.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        Intent i = new Intent(getApplicationContext(), diskotekeActivity.class);
        i.putExtra("data", "faraon");
        startActivity(i);
        finish();
    }
});

//lane
LinearLayout lyt_trg =(LinearLayout)findViewById(R.id.lyt_trg);
lyt_trg.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        Intent i = new Intent(getApplicationContext(), diskotekeActivity.class);
        i.putExtra("data", "trg");
        startActivity(i);
        finish();
    }
});

//lane
LinearLayout lyt_lane =(LinearLayout)findViewById(R.id.lyt_lane);
lyt_lane.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        Intent i = new Intent(getApplicationContext(), diskotekeActivity.class);
        i.putExtra("data", "lane");
        startActivity(i);
        finish();
    }
});

//kastel
LinearLayout lyt_kastel =(LinearLayout)findViewById(R.id.lyt_kastel);
lyt_kastel.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        Intent i = new Intent(getApplicationContext(), diskotekeActivity.class);
        i.putExtra("data", "kastel");
        startActivity(i);
        finish();
    }
});

//cepelin
LinearLayout lyt_cepelin =(LinearLayout)findViewById(R.id.lyt_cepelin);
lyt_cepelin.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        Intent i = new Intent(getApplicationContext(), diskotekeActivity.class);
        i.putExtra("data", "cepelin");
        startActivity(i);
        finish();
    }
});


LinearLayout lyt_dzungla =(LinearLayout)findViewById(R.id.lyt_dzungla);
lyt_dzungla.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        Intent i = new Intent(getApplicationContext(), diskotekeActivity.class);
        i.putExtra("data","dzungla");
        startActivity(i);
        finish();
    }
});


ImageView imgnazad_nocnizivot =(ImageView)findViewById(R.id.imgnazad_nocnizivot);
imgnazad_nocnizivot.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        Intent i = new Intent(getApplicationContext(), pocetakActivity.class);
        startActivity(i);
        finish();
    }
});
}

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

@Override
public boolean onOptionsItemSelected(MenuItem item) {

int id = item.getItemId();

//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
    return true;
}

return super.onOptionsItemSelected(item);
}
}
这是nocnizivot_layout.xml代码

这是我的日志:

11-10 10:49:40.169    2704-2704/? I/art﹕ Not late-enabling -Xcheck:jni (already on)
11-10 10:49:40.169    2704-2704/? I/art﹕ Late-enabling JIT
11-10 10:49:40.169    2704-2704/? I/art﹕ JIT created with code_cache_capacity=2MB compile_threshold=1000
11-10 10:49:40.219    2704-2704/teslicinfo.teslic W/System﹕ ClassLoader referenced unknown path: /data/app/teslicinfo.teslic-2/lib/x86
11-10 10:49:40.547    2704-2717/teslicinfo.teslic I/art﹕ Background partial concurrent mark sweep GC freed 81(3KB) AllocSpace objects, 0(0B) LOS objects, 38% free, 6MB/10MB, paused 1.464ms total 120.600ms
11-10 10:49:40.677    2704-2713/teslicinfo.teslic W/art﹕ Suspending all threads took: 16.632ms
11-10 10:49:40.742    2704-2717/teslicinfo.teslic I/art﹕ Background sticky concurrent mark sweep GC freed 21(864B) AllocSpace objects, 0(0B) LOS objects, 0% free, 21MB/21MB, paused 1.278ms total 117.549ms
11-10 10:49:40.926    2704-2724/teslicinfo.teslic D/OpenGLRenderer﹕ Use EGL_SWAP_BEHAVIOR_PRESERVED: true
11-10 10:49:40.972    2704-2704/teslicinfo.teslic D/﹕ HostConnection::get() New Host Connection established 0xab9908d0, tid 2704
11-10 10:49:41.045    2704-2724/teslicinfo.teslic D/﹕ HostConnection::get() New Host Connection established 0xab990dd0, tid 2724
11-10 10:49:41.066    2704-2724/teslicinfo.teslic I/OpenGLRenderer﹕ Initialized EGL, version 1.4
11-10 10:49:41.151    2704-2724/teslicinfo.teslic W/EGL_emulation﹕ eglSurfaceAttrib not implemented
11-10 10:49:41.151    2704-2724/teslicinfo.teslic W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xad92c960, error=EGL_SUCCESS
11-10 10:49:44.407    2704-2724/teslicinfo.teslic W/EGL_emulation﹕ eglSurfaceAttrib not implemented
11-10 10:49:44.407    2704-2724/teslicinfo.teslic W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xac13e200, error=EGL_SUCCESS
11-10 10:49:44.893    2704-2724/teslicinfo.teslic E/Surface﹕ getSlotFromBufferLocked: unknown buffer: 0xab9ac980
11-10 10:49:46.143    2704-2717/teslicinfo.teslic W/art﹕ Suspending all threads took: 13.446ms
11-10 10:49:46.147    2704-2704/teslicinfo.teslic I/art﹕ Starting a blocking GC Alloc
11-10 10:49:46.147    2704-2704/teslicinfo.teslic I/art﹕ Starting a blocking GC Alloc
11-10 10:49:46.149    2704-2704/teslicinfo.teslic I/art﹕ Starting a blocking GC Alloc
11-10 10:49:46.149    2704-2704/teslicinfo.teslic I/art﹕ Clamp target GC heap from 34MB to 32MB
11-10 10:49:46.149    2704-2704/teslicinfo.teslic I/art﹕ Starting a blocking GC Alloc
11-10 10:49:46.178    2704-2704/teslicinfo.teslic I/art﹕ Clamp target GC heap from 34MB to 32MB
11-10 10:49:46.178    2704-2704/teslicinfo.teslic I/art﹕ Alloc concurrent mark sweep GC freed 267(24KB) AllocSpace objects, 0(0B) LOS objects, 3% free, 30MB/32MB, paused 1.195ms total 27.810ms
11-10 10:49:46.182    2704-2704/teslicinfo.teslic I/art﹕ Forcing collection of SoftReferences for 1447KB allocation
11-10 10:49:46.182    2704-2704/teslicinfo.teslic I/art﹕ Starting a blocking GC Alloc
11-10 10:49:46.195    2704-2704/teslicinfo.teslic I/art﹕ Clamp target GC heap from 34MB to 32MB
11-10 10:49:46.195    2704-2704/teslicinfo.teslic I/art﹕ Alloc concurrent mark sweep GC freed 11(344B) AllocSpace objects, 0(0B) LOS objects, 3% free, 30MB/32MB, paused 3.038ms total 12.420ms
11-10 10:49:46.198    2704-2704/teslicinfo.teslic W/art﹕ Throwing OutOfMemoryError "Failed to allocate a 1481772 byte allocation with 1096520 free bytes and 1070KB until OOM"
11-10 10:49:46.198    2704-2704/teslicinfo.teslic I/art﹕ Starting a blocking GC Alloc
11-10 10:49:46.199    2704-2704/teslicinfo.teslic I/art﹕ Starting a blocking GC Alloc
11-10 10:49:46.199    2704-2704/teslicinfo.teslic I/art﹕ Starting a blocking GC Alloc
11-10 10:49:46.199    2704-2704/teslicinfo.teslic I/art﹕ Clamp target GC heap from 34MB to 32MB
11-10 10:49:46.199    2704-2704/teslicinfo.teslic I/art﹕ Starting a blocking GC Alloc
11-10 10:49:46.211    2704-2704/teslicinfo.teslic I/art﹕ Clamp target GC heap from 34MB to 32MB
11-10 10:49:46.211    2704-2704/teslicinfo.teslic I/art﹕ Alloc concurrent mark sweep GC freed 3(96B) AllocSpace objects, 0(0B) LOS objects, 3% free, 30MB/32MB, paused 0 total 10.985ms
11-10 10:49:46.214    2704-2704/teslicinfo.teslic I/art﹕ Forcing collection of SoftReferences for 1447KB allocation
11-10 10:49:46.214    2704-2704/teslicinfo.teslic I/art﹕ Starting a blocking GC Alloc
11-10 10:49:46.227    2704-2704/teslicinfo.teslic I/art﹕ Clamp target GC heap from 34MB to 32MB
11-10 10:49:46.227    2704-2704/teslicinfo.teslic I/art﹕ Alloc concurrent mark sweep GC freed 3(96B) AllocSpace objects, 0(0B) LOS objects, 3% free, 30MB/32MB, paused 1.276ms total 12.712ms
11-10 10:49:46.229    2704-2704/teslicinfo.teslic W/art﹕ Throwing OutOfMemoryError "Failed to allocate a 1481772 byte allocation with 1096520 free bytes and 1070KB until OOM"
11-10 10:49:46.231    2704-2704/teslicinfo.teslic D/skia﹕ --- allocation failed for scaled bitmap
11-10 10:49:46.233    2704-2704/teslicinfo.teslic D/AndroidRuntime﹕ Shutting down VM
11-10 10:49:46.233    2704-2704/teslicinfo.teslic E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: teslicinfo.teslic, PID: 2704
java.lang.OutOfMemoryError: Failed to allocate a 1481772 byte allocation with 1096520 free bytes and 1070KB until OOM
        at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
        at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
        at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:609)
        at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444)
        at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:1080)
        at android.content.res.Resources.loadDrawableForCookie(Resources.java:2635)
        at android.content.res.Resources.loadDrawable(Resources.java:2540)
        at android.content.res.Resources.getDrawable(Resources.java:806)
        at android.content.Context.getDrawable(Context.java:458)
        at android.widget.ImageView.resolveUri(ImageView.java:811)
        at android.widget.ImageView.setImageResource(ImageView.java:418)
        at teslicinfo.teslic.diskotekeActivity.diskoteke_dzungla(diskotekeActivity.java:21)
        at teslicinfo.teslic.diskotekeActivity.onCreate(diskotekeActivity.java:437)
        at android.app.Activity.performCreate(Activity.java:6237)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
        at android.app.ActivityThread.-wrap11(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:148)
        at android.app.ActivityThread.main(ActivityThread.java:5417)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
11-10 10:49:47.991    2704-2704/? I/Process﹕ Sending signal. PID: 2704 SIG: 9

AFAIK支持13个活动,所以我想问题出在其他地方。也许你没有给你的AVD足够的内存。
无论如何,我建议您使用fragment。

试试看,这可能会帮助您在清单文件中添加此标记

<application
  ...
  ...
  android:largeHeap="true"
  ......
  ......

</application>

选中此项

在实际设备上测试您的应用程序,它将工作共享崩溃消息和日志。当我在android手机上测试它时,它工作正常,但在打开3或4个活动后,它将停止。。。
Bitmap bm;
bm = Bitmap.createScaledBitmap(BitmapFactory.decodeFile(filepath),100, 100, true);
mPicture = new ImageView(context);
mPicture.setImageBitmap(bm);