IllegalStateException

Android Studio를 무작정 돌파중인 학생입니다.

/* — MainActivity — */
package com.example.readingtalk;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.Signature;
import android.os.Bundle;
import android.util.Base64;
import android.util.Log;
import android.view.View;
import android.widget.EditText;

import com.kakao.sdk.newtoneapi.TextToSpeechClient;
import com.kakao.sdk.newtoneapi.TextToSpeechListener;
import com.kakao.sdk.newtoneapi.TextToSpeechManager;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import static com.kakao.util.helper.Utility.getPackageInfo;

public class MainActivity extends AppCompatActivity implements TextToSpeechListener{

private TextToSpeechClient ttsClient;
final String TAG = "KAKAO_TTS_APP";
final String APIKEY = "2a71e7d054c119e30b2cf8e0442873f5";

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

    TextToSpeechManager.getInstance().initializeLibrary(getApplicationContext());
    // Log.w("KAKAO_TTS_HASH", getKeyHash(getApplicationContext()));
}

@Override
protected void onDestroy() {
    super.onDestroy();
    TextToSpeechManager.getInstance().finalizeLibrary();
}

@Override
public void onError(int code, String message) {
    Log.e(TAG, "code: " + code);
}

@Override
public void onFinished() {
    int intSentSize = ttsClient.getSentDataSize();      //세션 중에 전송한 데이터 사이즈
    int intRecvSize = ttsClient.getReceivedDataSize();  //세션 중에 전송받은 데이터 사이즈

    final String strInacctiveText = "handleFinished() SentSize : " + intSentSize + "  RecvSize : " + intRecvSize;

    Log.i(TAG, strInacctiveText);
}

public void mOnClick(View v) {

    switch(v.getId()) {
        case R.id.button:
            ttsClient = new TextToSpeechClient.Builder()
                    .setAppKey(APIKEY)
                    .setSpeechMode(TextToSpeechClient.NEWTONE_TALK_1)     // 음성합성방식
                    .setSpeechSpeed(1.0)            // 발음 속도(0.5~4.0)
                    .setSpeechVoice(TextToSpeechClient.VOICE_WOMAN_READ_CALM)  //TTS 음색 모드 설정(여성 차분한 낭독체)
                    .setListener(this)
                    .build();

            EditText editText = findViewById(R.id.editText);
            String strText = editText.getText().toString();

            if (ttsClient.play(strText)) {
                Log.d(TAG, "playTTS");
            }
    }
}

public static String getKeyHash(final Context context) {
    PackageInfo packageInfo = getPackageInfo(context, PackageManager.GET_SIGNATURES);
    if (packageInfo == null)
        return null;

    for (Signature signature : packageInfo.signatures) {
        try {
            MessageDigest md = MessageDigest.getInstance("SHA");
            md.update(signature.toByteArray());
            return Base64.encodeToString(md.digest(), Base64.NO_WRAP);
        } catch (NoSuchAlgorithmException e) {
            Log.w("KAKAO_TTS_APP", "Unable to get MessageDigest. signature=" + signature, e);
        }
    }
    return null;
}

}

/* — Manifest — */

<?xml version="1.0" encoding="utf-8"?>

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<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">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <meta-data
        android:name="com.kakao.sdk.AppKey"
        android:value="@string/kakao_app_key" />
</application>

2019-09-29 23:36:50.457 11789-11789/com.example.readingtalk E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.readingtalk, PID: 11789
java.lang.IllegalStateException: Could not execute method for android:onClick
at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:402)
at android.view.View.performClick(View.java:6597)
at android.view.View.performClickInternal(View.java:6574)
at android.view.View.access$3100(View.java:778)
at android.view.View$PerformClick.run(View.java:25885)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:397)
at android.view.View.performClick(View.java:6597)
at android.view.View.performClickInternal(View.java:6574)
at android.view.View.access$3100(View.java:778)
at android.view.View$PerformClick.run(View.java:25885)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method ‘android.content.pm.PackageManager android.content.Context.getPackageManager()’ on a null object reference
at com.kakao.util.helper.Utility.getPackageInfo(Utility.java:140)
at com.kakao.util.helper.Utility.getKeyHash(Utility.java:160)
at com.kakao.util.helper.SystemInfo.initialize(SystemInfo.java:37)
at com.kakao.sdk.newtoneapi.TextToSpeechClient.play(TextToSpeechClient.java:347)
at com.kakao.sdk.newtoneapi.TextToSpeechClient.play(TextToSpeechClient.java:384)
at com.example.readingtalk.MainActivity.mOnClick(MainActivity.java:75)
at java.lang.reflect.Method.invoke(Native Method)
at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:397)
at android.view.View.performClick(View.java:6597)
at android.view.View.performClickInternal(View.java:6574)
at android.view.View.access$3100(View.java:778)
at android.view.View$PerformClick.run(View.java:25885)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

keyhash 설정 등등 다 했습니다. 도무지 해결방안과 오류이유를 알 수 없어 질문드립니다.

layout 파일 코드도 올려주실 수 있나요? onClick 메소드 정의한 부분에 오타가 없는지 한번 확인해 주시겠어요?