마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

apk파일을 실행하면 "애플리케이션이 예상치 않게 중지되었습니다"라고 뜹니다.

0 추천

학교에서 안드로이드 어플을 만들어야 되서 만드는 중인데 에뮬레이터(Nexus 5X_API)로 실행할 때는 잘만 되는데 핸드폰에 옮겨서 설치한 뒤 실행한 뒤 버튼을 클릭하면 "애플리케이션이 예상치 않게 중지되었습니다"라는 팝업창이 뜨고 종료가 됩니다. 

(첫 화면은 뜨는데 이제 제가 하고 싶었던 것이 아무 화면이나 누르면 다음 화면으로 넘어가는 것을 하고 싶어서 버튼을 전체화면 크기로 만들었습니다. 그러니까 그 버튼을 누르면 저 팝업창이 뜨면서 종료가 됩니다.)

혹시 핸드폰이랑 뭔가 안 맞아서 그런가 싶어서 간단한 소스코드로 apk파일을 만들어서 핸드폰에 다운로드 한뒤 실행해보니 이상이 없었습니다. 오히려 실행이 잘 되더라고요.

안드로이드 스튜디오 초보라 코드를 보면 "버튼을 통한 화면간 이동"이 이 어플리케이션에서 주로 하는 일입니다. 어떻게 해야 에뮬레이터처럼 핸드폰에도 똑같이 실행할 수 있을까요?

우선 코드랑 로그캣 올립니다.

 

─────

 

 

<Intro.java>

package kr.ac.cau.educationapp;

import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.support.v4.app.FragmentActivity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

public class Intro extends FragmentActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_intro);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    }

    public void onButton(View v) {
        Intent intent = new Intent(getApplicationContext(), second.class);
        startActivity(intent);
    }
}

<activity_intro.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/intro"
    tools:context=".Intro">

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/intro"
        android:onClick="onButton"
        android:textSize="200sp"
        android:visibility="visible"
        tools:layout_editor_absoluteX="0dp"
        tools:layout_editor_absoluteY="0dp" />

</android.support.constraint.ConstraintLayout>

<second.java>

package kr.ac.cau.educationapp;

import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.support.v4.app.FragmentActivity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

public class second extends FragmentActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    }

    public void onButton2(View v) {
        Intent intent = new Intent(this, third.class);
        startActivity(intent);
    }

    public void onButton3(View v) {
        Intent intent = new Intent(this, sixth.class);
        startActivity(intent);
    }
}

<activity_second.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/second"
    tools:context=".second">

    <Button
        android:id="@+id/button2"
        android:layout_width="303dp"
        android:layout_height="202dp"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:background="@drawable/geulza"
        android:onClick="onButton2"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.027"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.797" />

    <Button
        android:id="@+id/button3"
        android:layout_width="308dp"
        android:layout_height="213dp"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:background="@drawable/word"
        android:onClick="onButton3"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="1.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="1.0" />

</android.support.constraint.ConstraintLayout>

<AndroidManifest.xml>

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="kr.ac.cau.educationapp">

    <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="@android:style/Theme.NoTitleBar.Fullscreen">
        <activity android:name=".Intro">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".second" />
        <activity android:name=".third" />
        <activity android:name=".fourth" />
        <activity android:name=".fifth" />
        <activity android:name=".sixth"></activity>
    </application>

</manifest>

 

────────

 

그리고 추가로 설명드리자면 "전체화면"과 "가로화면을 고정"하려고 인터넷에서 찾은 방법으로 코드를 작성했습니다.

"전체화면"의 경우 AndroidManifest.xml에서 

 android:theme="@android:style/Theme.NoTitleBar.Fullscreen">

을 추가하였고 이제 모든 java파일에서 AppCompatActivity를 상속받지 않고 FragmentActivity를 상속받았습니다. 

"가로화면 고정"의 경우 모든 java코드의 onCreate() 메소드에다가

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

을 추가하였습니다. 그래서 화면이 가로로 고정하였고요.

 

에뮬레이터에서는 잘 돌아가지만 핸드폰에서는 돌아가지 않습니다. 이유를 알려주시면 감사하겠습니다.

 

+) 질문이 안올려져서 코드를 짤랐습니다. 저 위의 third, fourth, fifth, sixth는 그냥 다른 화면으로 이동하는게 주로 하는 일입니다.

+) 글자수가 넘어서 로그캣을 댓글에다 달았습니다.

뚱뚱한고양이 (120 포인트) 님이 2018년 6월 6일 질문
뚱뚱한고양이님이 2018년 6월 6일 수정
글자수가 넘어서 로그캣은 여기에다 남깁니다!

06-06 08:37:16.362 4138-4138/? I/zygote: Not late-enabling -Xcheck:jni (already on)
06-06 08:37:16.415 4138-4138/? W/zygote: Unexpected CPU variant for X86 using defaults: x86
06-06 08:37:17.218 4138-4154/kr.ac.cau.educationapp D/OpenGLRenderer: HWUI GL Pipeline
06-06 08:37:17.337 4138-4154/kr.ac.cau.educationapp I/zygote: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0
06-06 08:37:17.338 4138-4154/kr.ac.cau.educationapp I/OpenGLRenderer: Initialized EGL, version 1.4
06-06 08:37:17.338 4138-4154/kr.ac.cau.educationapp D/OpenGLRenderer: Swap behavior 1
06-06 08:37:17.338 4138-4154/kr.ac.cau.educationapp W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
06-06 08:37:17.338 4138-4154/kr.ac.cau.educationapp D/OpenGLRenderer: Swap behavior 0
06-06 08:37:17.373 4138-4154/kr.ac.cau.educationapp D/EGL_emulation: eglCreateContext: 0xa0884120: maj 3 min 0 rcv 3
06-06 08:37:17.410 4138-4154/kr.ac.cau.educationapp D/EGL_emulation: eglMakeCurrent: 0xa0884120: ver 3 0 (tinfo 0xa0883290)
06-06 08:37:17.568 4138-4154/kr.ac.cau.educationapp D/EGL_emulation: eglMakeCurrent: 0xa0884120: ver 3 0 (tinfo 0xa0883290)
06-06 08:37:33.502 4138-4154/kr.ac.cau.educationapp D/EGL_emulation: eglMakeCurrent: 0xa0884120: ver 3 0 (tinfo 0xa0883290)
06-06 08:37:39.510 4138-4154/kr.ac.cau.educationapp D/EGL_emulation: eglMakeCurrent: 0xa0884120: ver 3 0 (tinfo 0xa0883290)
06-06 08:37:42.392 4138-4154/kr.ac.cau.educationapp D/EGL_emulation: eglMakeCurrent: 0xa0884120: ver 3 0 (tinfo 0xa0883290)
06-06 08:37:45.042 4138-4154/kr.ac.cau.educationapp D/EGL_emulation: eglMakeCurrent: 0xa0884120: ver 3 0 (tinfo 0xa0883290)
06-06 08:37:47.637 4138-4154/kr.ac.cau.educationapp D/EGL_emulation: eglMakeCurrent: 0xa0884120: ver 3 0 (tinfo 0xa0883290)
06-06 08:38:09.598 4138-4154/kr.ac.cau.educationapp D/EGL_emulation: eglMakeCurrent: 0xa0884120: ver 3 0 (tinfo 0xa0883290)
06-06 08:38:11.362 4138-4154/kr.ac.cau.educationapp D/EGL_emulation: eglMakeCurrent: 0xa0884120: ver 3 0 (tinfo 0xa0883290)
06-06 08:38:12.385 4138-4154/kr.ac.cau.educationapp D/EGL_emulation: eglMakeCurrent: 0xa0884120: ver 3 0 (tinfo 0xa0883290)
06-06 08:38:13.286 4138-4154/kr.ac.cau.educationapp D/EGL_emulation: eglMakeCurrent: 0xa0884120: ver 3 0 (tinfo 0xa0883290)
06-06 08:38:13.962 4138-4143/kr.ac.cau.educationapp I/zygote: Do partial code cache collection, code=25KB, data=30KB
06-06 08:38:13.963 4138-4143/kr.ac.cau.educationapp I/zygote: After code cache collection, code=25KB, data=30KB
    Increasing code cache capacity to 128KB
06-06 08:38:17.488 4138-4154/kr.ac.cau.educationapp D/EGL_emulation: eglMakeCurrent: 0xa0884120: ver 3 0 (tinfo 0xa0883290)
06-06 08:38:21.295 4138-4154/kr.ac.cau.educationapp D/EGL_emulation: eglMakeCurrent: 0xa0884120: ver 3 0 (tinfo 0xa0883290)
06-06 08:38:23.375 4138-4154/kr.ac.cau.educationapp D/EGL_emulation: eglMakeCurrent: 0xa0884120: ver 3 0 (tinfo 0xa0883290)
06-06 08:38:25.192 4138-4143/kr.ac.cau.educationapp I/zygote: Do partial code cache collection, code=50KB, data=56KB
06-06 08:38:25.194 4138-4143/kr.ac.cau.educationapp I/zygote: After code cache collection, code=50KB, data=56KB
    Increasing code cache capacity to 256KB
06-06 08:38:25.394 4138-4154/kr.ac.cau.educationapp D/EGL_emulation: eglMakeCurrent: 0xa0884120: ver 3 0 (tinfo 0xa0883290)

답변 달기

· 글에 소스 코드 보기 좋게 넣는 법
· 질문에 대해 추가적인 질문이나 의견이 있으면 답변이 아니라 댓글로 달아주시기 바랍니다.
표시할 이름 (옵션):
개인정보: 당신의 이메일은 이 알림을 보내는데만 사용됩니다.
스팸 차단 검사:
스팸 검사를 다시 받지 않으려면 로그인하거나 혹은 가입 하세요.
...