不幸的是,应用程序已停止(Android Studio)

罗伊·库玛·杜拜(ROHIT KUMAR DUBEY)

我不知道为什么会出现此消息...应用程序可以正常打开,但是一旦我更改了应用程序中的搜索栏,消息就会弹出并停止运行。

我正在使用空白活动,并发布了.xml.java文件。请回复。

linearlayout.xml

 <?xml version="1.0" encoding="utf-8"?>
         <LinearLayout 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:orientation="vertical"
             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=".MainActivity" >

             <TextView
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:text="R" />

             <SeekBar
                 android:id="@+id/sb_red"
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
                 android:max="255"
                 android:progress="128" />

             <TextView
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:text="G" />

             <SeekBar
                 android:id="@+id/sb_green"
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
                 android:max="255"
                 android:progress="128" />

             <TextView
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:text="B" />

             <SeekBar
                 android:id="@+id/sb_blue"
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
                 android:max="255"
                 android:progress="128" />



             <ImageView
                 android:id="@+id/iv_show"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:src="@drawable/game" />

         </LinearLayout>

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.rohit2906.rgbvalues" >

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        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>
    </application>

</manifest>

MainActivity.java

package com.example.rohit2906.rgbvalues;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.Matrix;
import android.graphics.Paint;



public class MainActivity extends Activity {
    private SeekBar sb_red, sb_green, sb_blue;
    private ImageView iv_show;
    private Bitmap afterBitmap;
    private Paint paint;
    private Canvas canvas;
    private Bitmap baseBitmap;

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

        iv_show = (ImageView) findViewById(R.id.iv_show);
        sb_red = (SeekBar) findViewById(R.id.sb_red);
        sb_green = (SeekBar) findViewById(R.id.sb_green);
        sb_blue = (SeekBar) findViewById(R.id.sb_blue);


        sb_red.setOnSeekBarChangeListener(seekBarChange);
        sb_green.setOnSeekBarChangeListener(seekBarChange);
        sb_blue.setOnSeekBarChangeListener(seekBarChange);
        // Get a picture from a resource file
        baseBitmap = BitmapFactory.decodeResource(getResources(),
         R.drawable.game);
        // Empty picture gets a and baseBitmap the same size editable
        afterBitmap = Bitmap.createBitmap(baseBitmap.getWidth(),
        baseBitmap.getHeight(), baseBitmap.getConfig());
        canvas = new Canvas(afterBitmap);
        paint = new Paint();
    }
    private SeekBar.OnSeekBarChangeListener seekBarChange = new OnSeekBarChangeListener() {

                 @Override
                 public void onStopTrackingTouch(SeekBar seekBar) {
                     // Gets the current value of each SeekBar
                     float progressR = sb_red.getProgress()/128f;
                     float progressG = sb_green.getProgress()/128f;
                     float progressB = sb_blue.getProgress()/128f;

                     Log.i("main", "R: G: B="+progressR+": "+progressG+": "+progressB);
                     // According to the definition of the RGB matrix SeekBar
                     float[] src = new float[]{
                             progressR, 0, 0, 0, 0,
                             0, progressG, 0, 0, 0,
                             0, 0, progressB, 0, 0,
                           };
                     // The definition of ColorMatrix, and specify the RGB matrix
                     ColorMatrix colorMatrix = new ColorMatrix();
                     colorMatrix.set(src);
                     // Set the Paint color
                     paint.setColorFilter(new ColorMatrixColorFilter(src));
                    // By specifying the RGB matrix Paint of the original picture of the blank picture
                    canvas.drawBitmap(baseBitmap, new Matrix(), paint);
                    iv_show.setImageBitmap(afterBitmap);
               }

                 @Override
                 public void onStartTrackingTouch(SeekBar seekBar) {
                }
                        @Override
                public void onProgressChanged(SeekBar seekBar, int progress,
                         boolean fromUser) {
                }
             };


}

日志猫

02-22 15:45:37.334    1768-1768/com.example.rohit2906.rgbvalues I/art﹕ Not late-enabling -Xcheck:jni (already on)
02-22 15:45:38.684    1768-1780/com.example.rohit2906.rgbvalues I/art﹕ Background sticky concurrent mark sweep GC freed 7(272B) AllocSpace objects, 0(0B) LOS objects, 0% free, 26MB/26MB, paused 33.108ms total 56.416ms
02-22 15:45:38.804    1768-1804/com.example.rohit2906.rgbvalues D/OpenGLRenderer﹕ Render dirty regions requested: true
02-22 15:45:38.806    1768-1768/com.example.rohit2906.rgbvalues D/﹕ HostConnection::get() New Host Connection established 0xae0d2dc0, tid 1768
02-22 15:45:38.810    1768-1768/com.example.rohit2906.rgbvalues D/Atlas﹕ Validating map...
02-22 15:45:38.970    1768-1804/com.example.rohit2906.rgbvalues D/﹕ HostConnection::get() New Host Connection established 0xae0d2f00, tid 1804
02-22 15:45:38.972    1768-1804/com.example.rohit2906.rgbvalues I/OpenGLRenderer﹕ Initialized EGL, version 1.4
02-22 15:45:39.117    1768-1804/com.example.rohit2906.rgbvalues D/OpenGLRenderer﹕ Enabling debug mode 0
02-22 15:45:39.245    1768-1804/com.example.rohit2906.rgbvalues W/EGL_emulation﹕ eglSurfaceAttrib not implemented
02-22 15:45:39.245    1768-1804/com.example.rohit2906.rgbvalues W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xa6c8d660, error=EGL_SUCCESS
02-22 15:45:41.195    1768-1768/com.example.rohit2906.rgbvalues I/Choreographer﹕ Skipped 108 frames!  The application may be doing too much work on its main thread.
02-22 15:46:16.236    1768-1768/com.example.rohit2906.rgbvalues I/art﹕ Alloc sticky concurrent mark sweep GC freed 0(0B) AllocSpace objects, 0(0B) LOS objects, 3% free, 53MB/55MB, paused 1.103ms total 18.769ms
02-22 15:46:16.252    1768-1768/com.example.rohit2906.rgbvalues I/art﹕ Alloc partial concurrent mark sweep GC freed 201(9KB) AllocSpace objects, 0(0B) LOS objects, 6% free, 53MB/57MB, paused 1.110ms total 16.307ms
02-22 15:46:16.272    1768-1768/com.example.rohit2906.rgbvalues I/art﹕ Alloc concurrent mark sweep GC freed 8(12KB) AllocSpace objects, 0(0B) LOS objects, 6% free, 53MB/57MB, paused 11.662ms total 18.752ms
02-22 15:46:16.272    1768-1768/com.example.rohit2906.rgbvalues I/art﹕ Forcing collection of SoftReferences for 13MB allocation
02-22 15:46:16.344    1768-1768/com.example.rohit2906.rgbvalues I/art﹕ Alloc concurrent mark sweep GC freed 11(344B) AllocSpace objects, 0(0B) LOS objects, 6% free, 53MB/57MB, paused 879us total 71.595ms
02-22 15:46:16.344    1768-1768/com.example.rohit2906.rgbvalues E/art﹕ Throwing OutOfMemoryError "Failed to allocate a 13824012 byte allocation with 4194304 free bytes and 10MB until OOM"
02-22 15:46:16.344    1768-1768/com.example.rohit2906.rgbvalues D/AndroidRuntime﹕ Shutting down VM
    --------- beginning of crash
02-22 15:46:16.345    1768-1768/com.example.rohit2906.rgbvalues E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.example.rohit2906.rgbvalues, PID: 1768
    java.lang.OutOfMemoryError: Failed to allocate a 13824012 byte allocation with 4194304 free bytes and 10MB until OOM
            at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
            at android.graphics.Bitmap.nativeCreate(Native Method)
            at android.graphics.Bitmap.createBitmap(Bitmap.java:817)
            at android.graphics.Bitmap.createBitmap(Bitmap.java:794)
            at android.graphics.Bitmap.createBitmap(Bitmap.java:761)
            at com.example.rohit2906.rgbvalues.MainActivity.onCreate(MainActivity.java:46)
            at android.app.Activity.performCreate(Activity.java:5933)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
            at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3912)
            at android.app.ActivityThread.access$900(ActivityThread.java:144)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1284)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5221)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
康拉德·克拉科维克(Konrad Krakowiak)

您忘记了src数组中的Alpha线

代替:

  float[] src = new float[]{
         progressR, 0, 0, 0, 0,
         0, progressG, 0, 0, 0,
         0, 0, progressB, 0, 0,
  };

有了这个:

  float[] src = new float[]{
         progressR, 0, 0, 0, 0, //Red
         0, progressG, 0, 0, 0, //Green
         0, 0, progressB, 0, 0, //Blue
         0, 0, 0, 1, 0, //alpha
  };

set(float[])ColorMatrix对象调用方法时,如以下代码所示:

 ColorMatrix colorMatrix = new ColorMatrix();
 colorMatrix.set(src);

您会收到异常,并且应用程序崩溃了。所述src阵列必须是相同的长度在阵列ColorMartix对象。它必须有20个长度。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

“不幸的是,应用程序已停止错误” Android Studio

来自分类Dev

Android Studio Release构建给我:不幸的是,“应用程序名称”已停止

来自分类Dev

不幸的是,该应用程序已停止 Android Studio 并且没有错误

来自分类Dev

Android Studio:当我运行我的应用程序时,它说不幸的是应用程序已停止

来自分类Dev

Android Studio:不幸的是,应用已停止

来自分类Dev

Android Studio:如何调试在模拟器中显示错误“不幸的是,应用程序已停止工作”的Android应用程序?

来自分类Dev

Android Studio“不幸的是,该应用程序不得不停止”错误。

来自分类Dev

Android Studio-应用程序已停止

来自分类Dev

不幸的是“ App”已停止Android Studio

来自分类Dev

Android Studio错误:不幸的是“ App”已停止

来自分类Dev

Android Studio。MyApp不幸已停止

来自分类Dev

Android Studio:单击导航抽屉标题中的图像视图时“应用程序已停止”

来自分类Dev

对于某些版本的Android,“不幸的是,应用程序已停止”

来自分类Dev

Android模拟器:不幸的是,应用程序已停止

来自分类Dev

如何解决“不幸的是,Android应用程序已停止”

来自分类Dev

不幸的是,Android SQL应用程序已停止

来自分类Dev

不幸的是,Android sqLite ..应用程序已停止

来自分类Dev

不幸的是,我的android studio应用程序已在设备Redmi 2 Prime中停止,但在Nexus仿真器中可以正常工作

来自分类Dev

Android studio错误:不幸的是“ App”已停止。怎么解决呢?

来自分类Dev

不幸的是,应用程序已停止

来自分类Dev

应用已停止-Android Studio

来自分类Dev

单击按钮时,Android Studio 中的应用程序崩溃。显示应用名称已停止工作

来自分类Dev

如果“不幸的应用程序已停止”,则Android自动运行的应用程序

来自分类Dev

不幸的是停止了工作的Android应用程序

来自分类Dev

不幸的是,应用程序在调试时已停止

来自分类Dev

不幸的是,应用程序已停止工作?

来自分类Dev

不幸的是,(应用程序名称)已停止

来自分类Dev

从启动到实际的应用程序。不幸的是APP已停止

来自分类Dev

不幸的是,应用程序已停止-微调器中的错误

Related 相关文章

  1. 1

    “不幸的是,应用程序已停止错误” Android Studio

  2. 2

    Android Studio Release构建给我:不幸的是,“应用程序名称”已停止

  3. 3

    不幸的是,该应用程序已停止 Android Studio 并且没有错误

  4. 4

    Android Studio:当我运行我的应用程序时,它说不幸的是应用程序已停止

  5. 5

    Android Studio:不幸的是,应用已停止

  6. 6

    Android Studio:如何调试在模拟器中显示错误“不幸的是,应用程序已停止工作”的Android应用程序?

  7. 7

    Android Studio“不幸的是,该应用程序不得不停止”错误。

  8. 8

    Android Studio-应用程序已停止

  9. 9

    不幸的是“ App”已停止Android Studio

  10. 10

    Android Studio错误:不幸的是“ App”已停止

  11. 11

    Android Studio。MyApp不幸已停止

  12. 12

    Android Studio:单击导航抽屉标题中的图像视图时“应用程序已停止”

  13. 13

    对于某些版本的Android,“不幸的是,应用程序已停止”

  14. 14

    Android模拟器:不幸的是,应用程序已停止

  15. 15

    如何解决“不幸的是,Android应用程序已停止”

  16. 16

    不幸的是,Android SQL应用程序已停止

  17. 17

    不幸的是,Android sqLite ..应用程序已停止

  18. 18

    不幸的是,我的android studio应用程序已在设备Redmi 2 Prime中停止,但在Nexus仿真器中可以正常工作

  19. 19

    Android studio错误:不幸的是“ App”已停止。怎么解决呢?

  20. 20

    不幸的是,应用程序已停止

  21. 21

    应用已停止-Android Studio

  22. 22

    单击按钮时,Android Studio 中的应用程序崩溃。显示应用名称已停止工作

  23. 23

    如果“不幸的应用程序已停止”,则Android自动运行的应用程序

  24. 24

    不幸的是停止了工作的Android应用程序

  25. 25

    不幸的是,应用程序在调试时已停止

  26. 26

    不幸的是,应用程序已停止工作?

  27. 27

    不幸的是,(应用程序名称)已停止

  28. 28

    从启动到实际的应用程序。不幸的是APP已停止

  29. 29

    不幸的是,应用程序已停止-微调器中的错误

热门标签

归档