2022-04-29 18:44:15.759 13368-13368/com.appg.valueshopping E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.appg.valueshopping, PID: 13368
kotlin.UninitializedPropertyAccessException: lateinit property hosts has not been initialized
at com.kakao.sdk.common.KakaoSdk.getHosts(KakaoSdk.kt:38)
at com.kakao.sdk.network.ApiFactory$kapi$2.invoke(ApiFactory.kt:62)
at com.kakao.sdk.network.ApiFactory$kapi$2.invoke(ApiFactory.kt:31)
at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
at com.kakao.sdk.network.ApiFactory.getKapi(Unknown Source:7)
at com.kakao.sdk.link.LinkClient.(LinkClient.kt:34)
at com.kakao.sdk.link.LinkClient$Companion$instance$2.invoke(LinkClient.kt:179)
at com.kakao.sdk.link.LinkClient$Companion$instance$2.invoke(LinkClient.kt:174)
at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
at com.kakao.sdk.link.LinkClient$Companion.getInstance(Unknown Source:11)
at com.kakao.sdk.link.LinkClient.getInstance(Unknown Source:2)
at com.appg.valueshopping.main.MainActivity.sendKakaoLink(MainActivity.java:576)
at com.appg.valueshopping.main.MainActivity.shouldOverrideUrlLoading(MainActivity.java:160)
at com.github.windsekirun.baseapp.widget.EnhanceWebView$WebClient.shouldOverrideUrlLoading(EnhanceWebView.kt:389)
at android.webkit.WebViewClient.shouldOverrideUrlLoading(WebViewClient.java:83)
at org.chromium.android_webview.AwContentsClientBridge.shouldOverrideUrlLoading(chromium-TrichromeWebViewGoogle6432.aab-stable-489612734:48)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:335)
at android.os.Looper.loopOnce(Looper.java:186)
at android.os.Looper.loop(Looper.java:313)
at android.app.ActivityThread.main(ActivityThread.java:8663)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:567)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
구현하니까 이런 에러가 납니다.
아래가 카카오 링크 구현한 부분이구요.
public void sendKakaoLink(String title, String imageUrl, String link, String linkMessage) {
//최신 카카오 sdk버전용
FeedTemplate defaultFeed = new FeedTemplate(
new Content(title, imageUrl, new Link(link, link)),
null,
Arrays.asList(new Button(linkMessage, new Link(link, link)))
);
if(LinkClient.getInstance().isKakaoLinkAvailable(this)){ //카톡 설치 됨
LinkClient.getInstance().defaultTemplate(this, defaultFeed, null, (linkResult, error) -> {
if(error != null){
Log.e(TAG, "sendKakaoLink: 카카오링크 보내기 실패", error);
}else if(linkResult != null){
Log.d(TAG, "sendKakaoLink: 카카오링크 보내기 성공 " + linkResult.getIntent());
startActivity(linkResult.getIntent());
// 카카오링크 보내기에 성공했지만 아래 경고 메시지가 존재할 경우 일부 컨텐츠가 정상 동작하지 않을 수 있습니다.
Log.w("TAG", "Warning Msg: " + linkResult.getWarningMsg());
Log.w("TAG", "Argument Msg: " + linkResult.getArgumentMsg());
}
return null;
});
} else { //카톡 설치 안됨
Uri shareUrl = WebSharerClient.getInstance().defaultTemplateUri(defaultFeed);
try{
KakaoCustomTabsClient.INSTANCE.open(MainActivity.this, shareUrl);
}catch(ActivityNotFoundException e){
Log.e(TAG, "sendKakaoLink: can not find WebBrowser" + e);
}
}
}
LinkClient.getInstance() ← 이부분에서 앱이 터져버리네요;; 초기화 안됐다구요.
전 v2로 구현했는데도 이래요. 왜 그런걸까요?
매니페스트파일에
<queries> <package android:name="com.kakao.talk" /> </queries>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:host="kakaolink"
android:scheme="@string/kakao_scheme" />
</intent-filter>
요거 2개도 카카오 문서보고 추가했어요;;