Android:Troubleshooting:Exception
InvocationTargetException
Activity 클래스의 private 변수를 선언할 때 findViewById 함수를 호출하여 발생.
R은 프로젝트를 실행한 후에 생성이되기 때문에 onCreate()와 같은 함수 내에서 findViewById()를 호출해야 한다.
IllegalStateException: Could not find a method in the activity class
- could not find a method in the activity class
- Stackoverflow: Could not find a method in the activity class
- android:onClick과 Activity Context
ListView와 ListViewAdapter(extends BaseAdapter 외 ListView에 상응하는 모든 Adapter), 그리고 xml에서 선언한 android:onClick
에 대한 이슈가 조금 있다.
사용자가 재정의한 Adapter에서 inflater를 사용하여 View를 생성한 뒤 이 View를 돌려줄 때, Inflater로 가져온 XML Layout내에 android:onClick
을 통해 onClickListener를 할당한 경우가 종종있다.
이 때, Adapter를 만들 때 사용하는 Context가 굉장히 중요한데, 만약 늘 하던대로 this를 넘겨줄 경우 Adapter에서 생성된 View가 해당 Context를 제대로 인식하지 못하는 경우가 있다.
때문에 onClick이 발생하면 연결된 method를 찾지 못하고 앱 자체가 죽어버린다.
java.lang.IllegalStateException: Could not find a method true(View) in the activity class android.test.ResultList for onClick handler on view class android.widget.Button with id 'addFavorite'
정확한 재현경로는 아마도 상위의 다른 부모가 존재할 경우라고 생각된다. this를 Adapter를 생성한 Activity가 아닌 부모의 Activity로 넘겨주게되어서 onClick에 대응되는 method를 찾지 못하는 것 같다.
때문에 Adapter를 생성할 때 주는 Context는 Activity.this 를 건네주는 게 맞다. ex) MainActivity.this
이렇게 하면 넘겨진 Context가 어느 Activity로부터 파생되었는 지 바로 이해하기 때문에 순조롭게 onClick에 대응하는 method를 호출하게 된다.
You need to use a Theme.AppCompat theme
안드로이드 스튜디오에서 처음 프로젝트를 생성하면 발생되는 에러이다. AndroidManifest.xml
에 아래의 코드를 추가하면 된다.
NoClassDefFoundError
- ClassNotFound when trying to implement AdMob banner
- http://android.foxykeep.com/dev/how-to-fix-the-classdefnotfounderror-with-adt-17
안드로이드(Android) 개발중 NoClassDefFoundError 예외가 발생될 경우가 있다. 이 경우는 아래와 같이 해결하면 된다.
Turns out r17 of Android Tools requires the /lib folder to be /libs, and the SDK has to be placed in there and referenced internally in order for it to be included in the apk.
즉, 라이브러리 파일들은 /libs
디렉터리에 넣어야 한다는 의미이다.