티스토리 뷰

오류

졸작 오류-1

상어악어 2022. 11. 21. 00:39
반응형

지금 까지 겪었던 오류 정리

 

 

1. Spring boot jpa mysql 연동 문제


 

오류 코드

jpa Caused by: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'sequence hibernate_sequence' at line 1

 

 

원인

mysql 버전 호환 문제

 

 

해결 방법

Mysql 8.0.30에서
8.0.20으로낮추니됨

 


 

 

 

 

 

2. 안드로이드 스튜디오에서 스프링부트 api 호출 오류


오류코드

2022-10-10 12:24:20.042 8328-8328/com.example.myapplication D/CONNECTION FAILURE:: Failed to connect to localhost/127.0.0.1:8080

 

 

원인

retrofit에선 localhost가 작동하지 않는다

 

 

해결

Url을 localhost에서
10.0.2.2로바꿈
혹은 내부아이피
192.168.1.189

 

 

예시

package com.codepalace.chatbot.Api

import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import retrofit2.converter.scalars.ScalarsConverterFactory

object RetrofitBuilder {
    var userapi: UserApi
    var corpusapi: CorpusApi
    init{
        val retrofit= Retrofit.Builder()
            .baseUrl("http://10.0.2.2:81/")   //요청 보내는 API 서버 url /로 끝나야 함
            .addConverterFactory(ScalarsConverterFactory.create() )
            .addConverterFactory(GsonConverterFactory.create())//Gson을 역직렬화
            .build()
        userapi=retrofit.create(UserApi::class.java)
        corpusapi=retrofit.create(CorpusApi::class.java)


    }
}

 

 

 

 

3. Return type 불일치 오류


오류코드

Android][error] retrofit Expected a string but was BEGIN_OBJECT at line 1 column 2 path $

 

 

원인

result를 스트링 바디로 받게 설정했더니 이런 에러가 났다

 

 

 

해결

implementation "com.squareup.retrofit2:converter-scalars:2.1.0"

build.gradle에 추가

 

 

.addConverterFactory(ScalarsConverterFactory.create())

retrofitbuild에 한 줄 추가(2번 오류에 예시 있어요)

 

 

혹은 파라미터로 받으면 가능

 


 

 

 

 

4. 상대방 에뮬레이터에서 서버 접속 안되는 오류


오류코드

not permitted by network security policy

 

 

 

원인

안드로이드는 기본적으로 HTTP 접근을 허용하지 않기 때문에

 

 

 

 

해결

android:usesCleartextTraffic="true"

Manifest.xml에 한 줄 추가해줌으로써 해결


 

 

 

5. JpaRepository query문 오류


오류코드

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'corpusRepository

' defined in com.example.imy_server.Repository.CorpusRepository defined in @EnableJpaRepositories declared on JpaR

epositoriesRegistrar.EnableJpaRepositoriesConfiguration: Invocation of init method failed; nested exception is org.springf

ramework.data.repository.query.QueryCreationException: Could not create query for public abstract java.lang.Long com.example.imy_server.Repository.Co

 

http://m.example.imy_server.Repository.Co

 

m.example.imy_server.Repository.Co

 

 

 

원인

1.

 @Query(value = "SELECT * FROM Corpus WHERE emotion_maincategory = ?슬픔")
    List<Corpus> findAllByEmotionmaincategory(String emotion_maincategory);

where 절에 ?=1로 안하고 ?=슬픔으로 해서 오류가 남

나중에 알게 된 건데 쿼리문에 값을 넣는거는 밑에 파라미터로 넣는거다

 

2.

SELECT * 을 하기위해선 추가 조건이 필요하다

 

 

 

 

해결

Select * 을 하기 위해선

nativequery = true를 추가해야 한다

 

package com.example.imy_server.Repository;

import com.example.imy_server.Domain.Corpus;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface CorpusRepository extends JpaRepository<Corpus, Long> {


    @Query(value = "SELECT * FROM Corpus WHERE emotion_maincategory = ?1", nativeQuery = true)
    List<Corpus> findAllByEmotionmaincategory(String emotion_maincategory);
}

옳게 동작하는 쿼리


 

 

 

6. 에뮬레이터 실행 오류


오류코드

11/08 17:27:19: Launching 'app' on Pixel 6 API 33.
Installation did not succeed.
The application could not be installed: INSTALL_FAILED_INSUFFICIENT_STORAGE

List of apks:
[0] 'D:\Chat-bot\app\build\intermediates\apk\debug\app-debug.apk'
The device needs more free storage to install the application (extra space is needed in addition to APK size).
Retry
Failed to launch an application on all devices

 

 

원인

에뮬레이터의 용량부족으로 추정

 

 

 

 

해결

에뮬레이터 용량 800 ->2000MB로 올리고
다시실행하니 해결됨


 

 

 

7. 비동기적 호출


오류코드

2022-11-08 20:10:35.295 10074-10074/com.codepalace.chatbot I/System.out: corpus = CorpusDto2(system_response1=test2)
2022-11-08 20:10:35.310 10074-10074/com.codepalace.chatbot I/System.out: third corpus = CorpusDto2(system_response1=test2)
2022-11-08 20:10:35.310 10074-10074/com.codepalace.chatbot I/System.out: first name = CorpusDto2(system_response1=test2)
2022-11-08 20:10:35.311 10074-10074/com.codepalace.chatbot I/System.out: second name = CorpusDto2(system_response1=test2)
2022-11-08 20:10:35.333 10074-10130/com.codepalace.chatbot D/TrafficStats: tagSocket(104) with statsTag=0xffffffff, statsUid=-1
2022-11-08 20:10:35.461 10074-10074/com.codepalace.chatbot I/System.out: response.body()?.get(0)!!.system_response1 = 직장에서 억울한 일을 겪으셨군요. 
2022-11-08 20:10:35.461 10074-10074/com.codepalace.chatbot I/System.out: second corpus = CorpusDto2(system_response1=직장에서 억울한 일을 겪으셨군요. )

 

 

문제

Corpuslist2() 호출시(데이터받아오는 api)
비동기적 호출로 그냥
hello에 대한 처리를 먼저해버리는듯

 

 

 

원인

appcompatActivity에서 api호출하지않고 

object내부에서 api호출을하니 비동기적으로 동작함

 

 

 

 

해결

appcompatActivity에서
Api호출해서 object로 파라미터로 넘겨줌

 


 

 

 

 

8. 챗봇화면 들어가면 강제종료되는 오류


오류코드

2022-11-10 14:47:12.865 28066-28066/com.codepalace.chatbot E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.codepalace.chatbot, PID: 28066
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.codepalace.chatbot/com.codepalace.chatbot.

ui.Chatbot}: java.lang.ArrayIndexOutOfBoundsException: length=3; index=3
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3676)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.jav

 

 

원인

챗봇화면 처음들어갈때
출력하는 랜덤 메시지 index초과오류
val random = (0..3).random()
원소가 3개였음

 

 

 

해결

val random = (0..2).random()

0...3에서 0...2로 수정함


 

반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함