android.content.res.Resources $ NotFoundException : 문자열 리소스 ID # 0x0
MySQL 데이터베이스에서 데이터를 읽는 Android 앱을 개발 중이며이 오류에 직면했습니다. 이 XML 레이아웃이 있습니다.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView android:id="@+id/wardNumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:text="Ward Number"
android:textSize="22dp"/>
<TextView android:id="@+id/dateTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/wardNumber"
android:layout_alignParentRight="true"
android:layout_marginRight="3dp"
android:text="Date-Time" />
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/dateTime"
android:layout_alignBottom="@+id/dateTime"
android:layout_alignLeft="@+id/wardNumber"
android:layout_marginLeft="3dp"
android:text="Name" />
</RelativeLayout>
그리고 이것은 내 Java 파일입니다.
public ApplicationAdapter(Context context, List<Application> items) {
super(context, R.layout.app_custom_list, items);
this.items = items;
}
@Override
public int getCount() {
return items.size();
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if(v == null) {
LayoutInflater li = LayoutInflater.from(getContext());
v = li.inflate(R.layout.app_custom_list, null);
}
Application app = items.get(position);
if(app != null) {
// ImageView icon = (ImageView)v.findViewById(R.id.appIcon);
TextView wardNumber = (TextView)v.findViewById(R.id.wardNumber);
TextView name = (TextView)v.findViewById(R.id.name);
// LinearLayout ratingCntr = (LinearLayout)v.findViewById(R.id.ratingCntr);
TextView dateTime = (TextView)v.findViewById(R.id.dateTime);
// if(icon != null) {
// Resources res = getContext().getResources();
// String sIcon = "com.sj.jsondemo:drawable/" + app.getIcon();
// icon.setImageDrawable(res.getDrawable(res.getIdentifier(sIcon, null, null)));
// }
if(wardNumber != null) wardNumber.setText(app.getTitle());
if(name != null) name.setText(app.getTitle());
if(dateTime != null) {
dateTime.setText(app.getTotalDl());
// NumberFormat nf = NumberFormat.getNumberInstance();
// dateTime.setText(nf.format(app.getTotalDl())+" dl");
}
}
return v;
}
}
이 활동이 호출되면 다음과 같은 오류 메시지가 나타납니다.
11-24 21:12:03.633: E/AndroidRuntime(1251): FATAL EXCEPTION: main
11-24 21:12:03.633: E/AndroidRuntime(1251): android.content.res.Resources$NotFoundException: String resource ID #0x0
11-24 21:12:03.633: E/AndroidRuntime(1251): at android.content.res.Resources.getText(Resources.java:201)
11-24 21:12:03.633: E/AndroidRuntime(1251): at android.widget.TextView.setText(TextView.java:2863)
11-24 21:12:03.633: E/AndroidRuntime(1251): at com.sj.jsondemo.Appl icationAdapter.getView(ApplicationAdapter.java:53)
11-24 21:12:03.633: E/AndroidRuntime(1251): at android.widget.AbsListView.obtainView(AbsListView.java:1430)
11-24 21:12:03.633: E/AndroidRuntime(1251): at android.widget.ListView.measureHeightOfChildren(ListView.java:1216)
11-24 21:12:03.633: E/AndroidRuntime(1251): at android.widget.ListView.onMeasure(ListView.java:1127)
11-24 21:12:03.633: E/AndroidRuntime(1251): at android.view.View.measure(View.java:8313)
11-24 21:12:03.633: E/AndroidRuntime(1251): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
11-24 21:12:03.633: E/AndroidRuntime(1251): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1017)
11-24 21:12:03.633: E/AndroidRuntime(1251): at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:701)
11-24 21:12:03.633: E/AndroidRuntime(1251): at android.widget.LinearLayout.onMeasure(LinearLayout.java:311)
11-24 21:12:03.633: E/AndroidRuntime(1251): at android.view.View.measure(View.java:8313)
11-24 21:12:03.633: E/AndroidRuntime(1251): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
11-24 21:12:03.633: E/AndroidRuntime(1251): at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
11-24 21:12:03.633: E/AndroidRuntime(1251): at android.view.View.measure(View.java:8313)
11-24 21:12:03.633: E/AndroidRuntime(1251): at android.widget.LinearLayout.measureVertical(LinearLayout.java:531)
11-24 21:12:03.633: E/AndroidRuntime(1251): at android.widget.LinearLayout.onMeasure(LinearLayout.java:309)
11-24 21:12:03.633: E/AndroidRuntime(1251): at android.view.View.measure(View.java:8313)
11-24 21:12:03.633: E/AndroidRuntime(1251): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
11-24 21:12:03.633: E/AndroidRuntime(1251): at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
11-24 21:12:03.633: E/AndroidRuntime(1251): at android.view.View.measure(View.java:8313)
11-24 21:12:03.633: E/AndroidRuntime(1251): at android.view.ViewRoot.performTraversals(ViewRoot.java:839)
11-24 21:12:03.633: E/AndroidRuntime(1251): at android.view.ViewRoot.handleMessage(ViewRoot.java:1859)
11-24 21:12:03.633: E/AndroidRuntime(1251): at android.os.Handler.dispatchMessage(Handler.java:99)
11-24 21:12:03.633: E/AndroidRuntime(1251): at android.os.Looper.loop(Looper.java:130)
11-24 21:12:03.633: E/AndroidRuntime(1251): at android.app.ActivityThread.main(ActivityThread.java:3683)
11-24 21:12:03.633: E/AndroidRuntime(1251): at java.lang.reflect.Method.invokeNative(Native Method)
11-24 21:12:03.633: E/AndroidRuntime(1251): at java.lang.reflect.Method.invoke(Method.java:507)
11-24 21:12:03.633: E/AndroidRuntime(1251): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
11-24 21:12:03.633: E/AndroidRuntime(1251): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
11-24 21:12:03.633: E/AndroidRuntime(1251): at dalvik.system.NativeStart.main(Native Method)
11-24 21:12:08.922: I/Process(1251): Sending signal. PID: 1251 SIG: 9
이 오류를 해결하는 방법을 모르겠습니다.
변화
dateTime.setText(app.getTotalDl());
에
dateTime.setText(String.valueOf(app.getTotalDl()));
다른 버전이 있습니다 setText
-하나는 문자열을 사용하고 다른 하나는 int 리소스 ID를 사용합니다. 정수를 전달하면 찾을 수없는 해당 문자열 리소스 ID를 찾으려고 시도합니다. 이것은 오류입니다.
나는 app.getTotalDl()
int를 반환 한다고 생각한다 . setText
이 int의 String 값으로 설정 하도록 구체적으로 지시해야합니다 .
setText (int resid) 대 setText (CharSequence 텍스트)
바꾸다
dateTime.setText(app.getTotalDl());
와
dateTime.setText(""+app.getTotalDl());
When you try to set text in Edittext
or textview
you should pass only String format.
dateTime.setText(app.getTotalDl());
to
dateTime.setText(String.valueOf(app.getTotalDl()));
The evaluated value for settext was integer so it went to see a resource attached to it but it was not found, you wanted to set text so it should be string so convert integer into string by attaching .toStringe
or String.valueOf(int)
will solve your problem!
You can do it. this is a easy way.
txtTopicNo.setText(10+"");
If we get the value as int
and we set it to String
, the error occurs. PFB my solution,
Textview = tv_property_count;
int property_id;
tv_property_count.setText(String.valueOf(property_id));
'IT박스' 카테고리의 다른 글
루트 레이아웃을 기준으로 뷰의 좌표 얻기 (0) | 2020.06.30 |
---|---|
배쉬 : 무한 수면 (무한 차단) (0) | 2020.06.30 |
유닉스 콘솔 / Mac 터미널에서 C / C ++를 컴파일하고 실행하는 방법은 무엇입니까? (0) | 2020.06.30 |
Android-소수점 이하 2 자리로 반올림 (0) | 2020.06.30 |
서비스 참조 오류 : 서비스 참조에 대한 코드를 생성하지 못했습니다. (0) | 2020.06.30 |