我的应用程序在Nexus模拟器中运行良好,但在Pixel one上仍然崩溃

时间:2018-02-05 04:20:55

标签: android

我已在Android中制作了一个简单的计时器应用程序,例如每当传输10秒时,它会发出消息“DONE !!!”

text view中(计划添加哔声)并在另一个文本视图中显示CountdownTimer。但是我注意到我的应用程序在nexus模拟器上运行得非常好,只是在像素模拟器上崩溃了,

此外,它一直在我的真实手机上崩溃(Redmi note 4),

这可能是什么原因?

我的代码:

package com.example.pickachu.timerapp;

import android.media.MediaPlayer;
import android.os.CountDownTimer;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;

import java.sql.Time;

public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        final TextView time=(TextView)findViewById(R.id.Time);
        final TextView Status =(TextView)findViewById(R.id.Status);


       new CountDownTimer(10000, 1000) {

            @Override
            public void onTick(long l) {
                time.setText("SEC   :   "+String.valueOf(l/1000));
            }

            @Override
            public void onFinish() {
                Status.setText("DONE!!!");
                time.setText("SEC  :  0");
            }

        }.start();
    }
}

XML代码:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/clock"
    android:backgroundTint="@android:color/background_light"
    tools:context="com.example.pickachu.timerapp.MainActivity">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:contentDescription="@string/app_name"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.0"
        app:srcCompat="@drawable/clock" />

    <TextView
        android:id="@+id/Time"
        android:layout_width="188dp"
        android:layout_height="62dp"
        android:layout_marginBottom="8dp"
        android:layout_marginTop="8dp"
        android:background="@android:color/background_dark"
        android:paddingTop="12sp"
        android:text="@string/Time"
        android:textAlignment="center"
        android:textColor="#ffffff"
        android:textSize="30sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintStart_toStartOf="@+id/imageView"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.369" />

    <TextView
        android:id="@+id/Status"
        android:layout_width="105dp"
        android:layout_height="48dp"
        android:layout_marginBottom="8dp"
        android:layout_marginTop="8dp"
        android:paddingTop="11sp"
        android:text="@string/Status"
        android:textAlignment="center"
        android:textColor="#ffffff"
        android:textSize="18sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.501"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.567"
        tools:text="@string/Status" />

</android.support.constraint.ConstraintLayout>

Logcat错误消息:

02-05 10:49:51.001 4637-4637/com.example.pickachu.timerapp     E/AndroidRuntime: FATAL EXCEPTION: main
  Process: com.example.pickachu.timerapp, PID: 4637
  java.lang.RuntimeException: Canvas: trying to draw too large(128399328bytes) bitmap.
      at android.view.DisplayListCanvas.throwIfCannotDraw(DisplayListCanvas.java:260)
      at android.graphics.Canvas.drawBitmap(Canvas.java:1415)
      at android.graphics.drawable.BitmapDrawable.draw(BitmapDrawable.java:528)
      at android.view.View.getDrawableRenderNode(View.java:17428)
      at android.view.View.drawBackground(View.java:17364)
      at android.view.View.draw(View.java:17176)
      at android.view.View.updateDisplayListIfDirty(View.java:16167)
      at android.view.View.draw(View.java:16951)
      at android.view.ViewGroup.drawChild(ViewGroup.java:3727)
      at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3513)
      at android.view.View.updateDisplayListIfDirty(View.java:16162)
      at android.view.View.draw(View.java:16951)
      at android.view.ViewGroup.drawChild(ViewGroup.java:3727)
      at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3513)
      at android.view.View.updateDisplayListIfDirty(View.java:16162)
      at android.view.View.draw(View.java:16951)
      at android.view.ViewGroup.drawChild(ViewGroup.java:3727)
      at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3513)
      at android.view.View.updateDisplayListIfDirty(View.java:16162)
      at android.view.View.draw(View.java:16951)
      at android.view.ViewGroup.drawChild(ViewGroup.java:3727)
      at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3513)
      at android.view.View.updateDisplayListIfDirty(View.java:16162)
      at android.view.View.draw(View.java:16951)
      at android.view.ViewGroup.drawChild(ViewGroup.java:3727)
      at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3513)
      at android.view.View.draw(View.java:17188)
      at com.android.internal.policy.DecorView.draw(DecorView.java:753)
      at android.view.View.updateDisplayListIfDirty(View.java:16167)
      at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:648)
      at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:654)
      at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:762)
      at android.view.ViewRootImpl.draw(ViewRootImpl.java:2800)
      at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2608)
      at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2215)
      at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1254)
      at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6337)
      at android.view.Choreographer$CallbackRecord.run(Choreographer.java:874)
      at android.view.Choreographer.doCallbacks(Choreographer.java:686)
      at android.view.Choreographer.doFrame(Choreographer.java:621)
      at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:860)
      at android.os.Handler.handleCallback(Handler.java:751)
      at android.os.Handler.dispatchMessage(Handler.java:95)
      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)

Image

5 个答案:

答案 0 :(得分:0)

试试这个......

因为您的真实手机在运行时无法找到屏幕的可绘制图像。将图像放到手机的分辨率(可绘制)文件夹中。如果您通过所有设备运行应用程序,则应将图像添加到所有分辨率(可绘制)文件夹中。将可绘制的图像放到drawable-xxhdpi文件夹中。

答案 1 :(得分:0)

我猜,我正在使用的图像存在一些问题。我只是替换了图像,它工作正常。所以现在,任何人都可以解释我的问题是什么..

以及如何解决这些问题。提前谢谢......

答案 2 :(得分:0)

缩小图像尺寸..它会起作用

答案 3 :(得分:0)

尝试更改工具:text =&#34; @ string / Status&#34;进入android:text =&#34; @ string / Status&#34; for textview&#34; @ + id / Status&#34;。

答案 4 :(得分:0)

从imageview中移除app:srcCompat =“@ drawable / clock”,因为您已经将背景设置为布局。