android.content.res.Resources $ NotFoundException 가져 오기 : Android에 리소스가있는 경우에도 예외
오류가 발생하는 곳을 알려주십시오.
가로 모드에서만 활동하는 앱을 만들고 있습니다. 그래서 AndroidManifest.xml 파일에 다음을 추가했습니다.
<activity android:name=".LandScapeImageActivity" android:screenOrientation="landscape"></activity>
다음과 같은 폴더를 만들었습니다.
/ res / layout-land
여기에 see_today_landscape_layout이라는 레이아웃을 추가합니다.
그리고 onCreate()
다음을 추가했습니다.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.see_today_landscape_layout);
....
}
하지만 내 앱을 실행할 때 다음 오류가 발생합니다.
02-06 13:46:14.358: E/AndroidRuntime(13286): FATAL EXCEPTION: main
02-06 13:46:14.358: E/AndroidRuntime(13286): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mid.kew.activities/com.mid.kew.activities.LandScapeImageActivity}: android.content.res.Resources$NotFoundException: Resource ID #0x7f03002b
02-06 13:46:14.358: E/AndroidRuntime(13286): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2787)
02-06 13:46:14.358: E/AndroidRuntime(13286): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2803)
02-06 13:46:14.358: E/AndroidRuntime(13286): at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4066)
02-06 13:46:14.358: E/AndroidRuntime(13286): at android.app.ActivityThread.access$2400(ActivityThread.java:135)
02-06 13:46:14.358: E/AndroidRuntime(13286): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2140)
02-06 13:46:14.358: E/AndroidRuntime(13286): at android.os.Handler.dispatchMessage(Handler.java:99)
02-06 13:46:14.358: E/AndroidRuntime(13286): at android.os.Looper.loop(Looper.java:144)
02-06 13:46:14.358: E/AndroidRuntime(13286): at android.app.ActivityThread.main(ActivityThread.java:4937)
02-06 13:46:14.358: E/AndroidRuntime(13286): at java.lang.reflect.Method.invokeNative(Native Method)
02-06 13:46:14.358: E/AndroidRuntime(13286): at java.lang.reflect.Method.invoke(Method.java:521)
02-06 13:46:14.358: E/AndroidRuntime(13286): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
02-06 13:46:14.358: E/AndroidRuntime(13286): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
02-06 13:46:14.358: E/AndroidRuntime(13286): at dalvik.system.NativeStart.main(Native Method)
02-06 13:46:14.358: E/AndroidRuntime(13286): Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f03002b
02-06 13:46:14.358: E/AndroidRuntime(13286): at android.content.res.Resources.getValue(Resources.java:892)
02-06 13:46:14.358: E/AndroidRuntime(13286): at android.content.res.Resources.loadXmlResourceParser(Resources.java:1869)
02-06 13:46:14.358: E/AndroidRuntime(13286): at android.content.res.Resources.getLayout(Resources.java:731)
02-06 13:46:14.358: E/AndroidRuntime(13286): at android.view.LayoutInflater.inflate(LayoutInflater.java:318)
02-06 13:46:14.358: E/AndroidRuntime(13286): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
02-06 13:46:14.358: E/AndroidRuntime(13286): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
02-06 13:46:14.358: E/AndroidRuntime(13286): at android.app.Activity.setContentView(Activity.java:1654)
02-06 13:46:14.358: E/AndroidRuntime(13286): at com.mid.kew.activities.LandScapeImageActivity.onCreate(LandScapeImageActivity.java:103)
02-06 13:46:14.358: E/AndroidRuntime(13286): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1069)
02-06 13:46:14.358: E/AndroidRuntime(13286): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2751)
02-06 13:46:14.358: E/AndroidRuntime(13286): ... 12 more
나는 R.java 에서 확인했고 예외가 찾고있는 ID 7f03002b의 리소스를 가지고 있으며 거기에 있습니다 ...
5 번 정도 프로젝트를 청소하고 다시 빌드했지만 여전히 문제가 발생합니다.
이상한 점은 이것이 어제 작동했고 오늘은 작동하지 않는다는 것입니다. 코드는 동일합니다.
- Eclipse에서 프로젝트> 정리 ...로 이동하십시오.
- 프로젝트를 선택한 다음 확인을 누릅니다.
- 앱 다시 시작
다시 발생하면 r.java 파일을 삭제하십시오. 자동으로 생성됩니다.
내 조건에 대한 원인은 복용했다 int
위해 매개 변수를 TextView
. 예를 하나 보여 드리겠습니다
int i = 5;
myTextView.setText(i);
위의 오류 정보를 가져옵니다.
이것은 다음 과 같이 변환 int
하여 해결할 수 있습니다.String
myTextView.setText(String.valueOf(i));
를 작성할 때 작성 int
중인 텍스트가 아닌 리소스를 기대합니다. 따라서 Android에서 int
as 를 설정하는 데주의하십시오 String
.
레이아웃을 명시 적으로 설정하고 있으므로 Android가 자동으로 회전을 처리하도록하려면 / layout-land가 아닌 기본 / layout 폴더에 배치 할 수 있습니다.
Try moving your layout xml from res/layout-land
to res/layout
folder
This can happen due to a different language in the phone for which your code doesn't have the asset for. For example your preference.xml is placed in xml-en and you are trying to run your app in a phone which has French selected, the app will crash.
In my case my Build Tools version in my build.gradle for the app module was outdated on an old project. Updating it fixed the issue:
android {
...
buildToolsVersion "19.0.1"
...
Updated to the latest build tools version (25.0.1) and sync'd the project and all was well again.
Check to make sure that your imports are correct. I had a similar problem where R
was pointing to the Android system R
file, not my local one.
I got this error from yet another reason:
I had the file res/xml/data.xml
and I was trying to load it with Resources
class like this:
Resources.getSystem().getXml(R.xml.data);
However this is incorrect as the method Resources.getSystem()
returns a global shared Resources object that provides access to only system resources.
The correct way is as follows (from inside Activity):
this.getResources().getXml(R.xml.data);
This can also cause some trouble: Accidentally one of my layouts was parked in my tablet resources folder, so I got this error only with phone layout. The phone layout simply had no suitable layout file.
I worked again after moving the layout file in the correct standard folder and a following project rebuild.
Make sure that the R you are pointing to is the correct one. I had a problem very similar to this, where an import got inserted by Eclipse that pointed to the System R file rather than the project one. It took a lot of head scratching. Hope this helps.
You have screen orientation set to landscape in your xml. If you have used eclipse to generate this file it would have created under res/layout-land/ folder.But when you open activity in Portrait mode application will search for xml in res/layout-port/ folder or the regular res/layout/. If you didn't have xml for portrait mode your application will crash.
I deleted folders build
inside a project. After cleaned and rebuilt it in Android Studio. Then corrected errors in build.gradle and AndroidManifest.
I have fixed the by this way:
Create a folder in your resource directory name "drawable-nodpi"
and then move yours all resources in this directory from others drawable directory.
Now clean your project and then rebuilt. Run again hopefully it will work this time without any resource not found exception.
I got this error when I was trying to access Bundle data from One Intent by using getInt("ID").
I solved it by using getString("ID").
From Activity1 i had
Intent intent=new Intent(this,ActivityB.class);
intent.putExtra("data",data)//
startActivity(intent);
On Activity B,
Bundle bundle=getIntent().getExtras();
if(extras!=null){
// int x=extras.getInt("Data"); This Line gave me error int
x=Integer.parseInt(extras.getString("Data")); // This solved the problem.
}
'Programing' 카테고리의 다른 글
젠킨스에서 빌드 번호를 재설정하는 방법은 무엇입니까? (0) | 2020.10.11 |
---|---|
PHP GuzzleHttp. (0) | 2020.10.11 |
CSS에서 텍스트를 배경으로 사용하는 방법이 있습니까? (0) | 2020.10.11 |
오류 ITMS-90164 / 90046 : 유효하지 않은 코드 서명 자격 (0) | 2020.10.11 |
프로그래밍 방식으로 TextView 텍스트 중앙에 배치 (0) | 2020.10.11 |