水平方向的Textview会崩溃应用程序

时间:2017-09-16 05:47:28

标签: android

我是Android开发的初学者。我正在制作水平方向的时钟。应用程序在没有TextView的情况下运行良好。我已经在清单文件中将屏幕方向更改为水平。但是每当我在活动中设置Textview时,它都会崩溃应用程序。编译器会构建apk而不会出现任何错误。

这是清单文件

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

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity"
        android:screenOrientation="landscape"
       >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".Main2Activity"
        android:screenOrientation="landscape"
        >

    </activity>
</application>

这是我的Java活动代码。

 package com.example.soumyadeep.maclauncher;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.animation.Animation;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.RotateAnimation;
import android.widget.ImageView;
import android.widget.TextView;


public class Main2Activity extends AppCompatActivity {
 TextView mi,hr,sec;
 static int hrs,secs,min;
 RotateAnimation rotate;




@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main2);
    mi=(TextView)findViewById(R.id.min);
    sec=(TextView)findViewById(R.id.sec);
    hr=(TextView)findViewById(R.id.hr);
    rotate=new RotateAnimation(0.0f,359.0f,RotateAnimation.RELATIVE_TO_SELF,0.5f,RotateAnimation.RELATIVE_TO_SELF,0.5f);
    rotate.setFillAfter(true);
    rotate.setDuration(1000);
    rotate.setRepeatCount(Animation.INFINITE);
    rotate.setInterpolator(new DecelerateInterpolator());
    rotate.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {

        }

        @Override
        public void onAnimationEnd(Animation animation) {

        }

        @Override
        public void onAnimationRepeat(Animation animation) {
            secs=secs+1;
            if(secs>=60)
            {
                int a=secs/60;
                secs=0;
                min=min+a;
                mi.setText(mi+"");
            }
            if(min<10){
                mi.setText("0"+mi);
            }
            if (secs<10){
                sec.setText("0"+secs);
            }

            if(min>=60)
            {
                int a=min/60;
                min=0;
                hrs=hrs+a;
                hr.setText(hrs+"");
                mi.setText(min+"");
            }
            if(hrs==24)
            {
                hrs=0;
                hr.setText(00+"");
            }
            if(secs>=10){
                sec.setText(secs + "");
            }


        }
    });
    ImageView img=(ImageView)findViewById(R.id.blc);
    img.startAnimation(rotate);






}
}

android监视器错误

09-16 18:10:41.740 27619-27619/com.example.soumyadeep.maclauncher E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                Process: com.example.soumyadeep.maclauncher, PID: 27619
                                                                                java.lang.OutOfMemoryError: Failed to allocate a 132710412 byte allocation with 4185304 free bytes and 108MB until OOM
                                                                                    at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
                                                                                    at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
                                                                                    at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:655)
                                                                                    at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:483)
                                                                                    at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:1157)
                                                                                    at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:720)
                                                                                    at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:571)
                                                                                    at android.content.res.Resources.getDrawable(Resources.java:879)
                                                                                    at android.content.Context.getDrawable(Context.java:530)
                                                                                    at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:353)
                                                                                    at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:201)
                                                                                    at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:189)
                                                                                    at android.support.v7.content.res.AppCompatResources.getDrawable(AppCompatResources.java:100)
                                                                                    at android.support.v7.widget.AppCompatImageHelper.loadFromAttributes(AppCompatImageHelper.java:54)
                                                                                    at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:66)
                                                                                    at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:56)
                                                                                    at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:106)
                                                                                    at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1026)
                                                                                    at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1083)
                                                                                    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:769)
                                                                                    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
                                                                                    at android.view.LayoutInflater.rInflate(LayoutInflater.java:858)
                                                                                    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
                                                                                    at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
                                                                                    at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
                                                                                    at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
                                                                                    at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:289)
                                                                                    at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
                                                                                    at com.example.soumyadeep.maclauncher.Main2Activity.onCreate(Main2Activity.java:23)
                                                                                    at android.app.Activity.performCreate(Activity.java:6666)
                                                                                    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
                                                                                    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2677)
                                                                                    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2789)
                                                                                    at android.app.ActivityThread.-wrap12(ActivityThread.java)
                                                                                    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1527)
                                                                                    at android.os.Handler.dispatchMessage(Handler.java:110)
                                                                                    at android.os.Looper.loop(Looper.java:203)
                                                                                    at android.app.ActivityThread.main(ActivityThread.java:6251)
                                                                                    at java.lang.reflect.Method.invoke(Native Method)
                                                                                    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1075)
                                                                                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)

对此问题的任何帮助都将受到高度赞赏。谢谢。

1 个答案:

答案 0 :(得分:-1)

您是否已将此添加到您的gradle依赖项中?

compile 'com.android.support.constraint:constraint-layout:1.0.0'