Latest Posts

[Android] Kotlin으로 Realm 사용하기

Posted on 2017-04-23 23:38:48

최근에 Java에서 Kotlin으로 갈아탔는데, Kotlin으로 Realm을 사용하는 예제가 많지 않아서 포스트를 작성하였다.   Realm을 사용하려면 먼저 Realm library를 초기화해야 한다. class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) // Initializes the Realm library and creates a default configuration that is ready to use. // It is required to call this method before interacting with any other of the Realm API's. Realm.init(this) } }   그리고 그 다음은 model class...

[Android] Only the original thread that created a view hierarchy can touch its views 에러의 해결방법

Posted on 2017-03-30 23:51:57

오늘 안드로이드 개발중에 아래와 같은 exception이 떴다. 에러메시지의 내용을 보니, view hierarchy를 생성한 쓰레드만이 해당 view을 수정할 수 있다는 내용이었다. CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.   이 문제의 해결책은 UI를 수정하는 코드를 runOnUiThread()의 run() 함수 안에 넣으면 된다. runOnUiThread()는 current thread가 UI thread가 아닌 경우, UI thread의 이벤트큐에 실행할 작업을 넣어준다고 한다. runOnUiThread(new Runnable() { @Override public void run() { // UI 코드를 이 안으로 옮긴다. } }); &...

[Android] 인터넷접속 퍼미션 설정

Posted on 2017-03-20 20:24:22

안드로이드 프로젝트를 생성하고 앱에서 서버로 http request를 보내려고 했는데, 다음과 같은 에러가 발생하였다. 에러 메시지의 내용대로 INTERNET permission 설정이 누락되어 있어서 발생한 문제이다. java.lang.SecurityException: Permission denied (missing INTERNET permission?)   안드로이드 앱에서 인터넷에 접속할 수 있도록 허용하려면 AndroidManifest.xml 파일에 android.permission.INTERNET 설정을 추가해야 한다. • app/src/main/AndroidManifest.xml <?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.examp...