2017-09-16 62 views
0

我初學的Android development.I我水平orientation.The應用使時鐘運行良好,沒有TextView的。我已經在清單文件中將屏幕方向更改爲水平。但是,無論何時在活動中設置文本視圖時,它都會崩潰應用程序。編譯器構建apk時不會出現任何錯誤。的TextView在水平方向崩潰的應用程序

這裏的清單文件

<?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); 






} 
} 

機器人監控錯誤

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) 

對於這個問題的任何幫助將是非常appreciated.Thank你

+1

發佈您的崩潰日誌 –

+1

請分享您的logcat。 –

+0

顯示您的日誌! – Xenolion

回答

-1

你將此添加到您的gradle這個依賴呢?

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

這已經添加到我的gradle這個依賴 –

0

試試這個

  • manifest這一行下添加applicationandroid:largeHeap="true"

enter image description here

`

+1

我這樣做,但它仍然不能正常工作 –

+0

加入這一行in'build.gradle'下'安卓{ dexOptions { javaMaxHeapSize「4G」 preDexLibraries =假 }}' –

+0

它畢竟是我看這個錯誤的logcat –