android.content.res.Resources$NotFoundException: String resource ID #0x6错误的解决办法

在开发过程当中遇到这个问题

08-17 18:12:24.835: E/AndroidRuntime(17951): FATAL EXCEPTION: main
08-17 18:12:24.835: E/AndroidRuntime(17951): android.content.res.Resources$NotFoundException: String resource ID #0x0
08-17 18:12:24.835: E/AndroidRuntime(17951): 	at android.content.res.Resources.getText(Resources.java:201)
08-17 18:12:24.835: E/AndroidRuntime(17951): 	at android.widget.TextView.setText(TextView.java:3102)
08-17 18:12:24.835: E/AndroidRuntime(17951): 	at com.yang.listviewclick.adapter.ListViewAdapter.getView(ListViewAdapter.java:65)
08-17 18:12:24.835: E/AndroidRuntime(17951): 	at android.widget.AbsListView.obtainView(AbsListView.java:1452)
08-17 18:12:24.835: E/AndroidRuntime(17951): 	at android.widget.ListView.measureHeightOfChildren(ListView.java:1216)
08-17 18:12:24.835: E/AndroidRuntime(17951): 	at android.widget.ListView.onMeasure(ListView.java:1127)
08-17 18:12:24.835: E/AndroidRuntime(17951): 	at android.view.View.measure(View.java:8313)
08-17 18:12:24.835: E/AndroidRuntime(17951): 	at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
08-17 18:12:24.835: E/AndroidRuntime(17951): 	at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1017)
08-17 18:12:24.835: E/AndroidRuntime(17951): 	at android.widget.LinearLayout.measureVertical(LinearLayout.java:386)
08-17 18:12:24.835: E/AndroidRuntime(17951): 	at android.widget.LinearLayout.onMeasure(LinearLayout.java:309)
08-17 18:12:24.835: E/AndroidRuntime(17951): 	at android.view.View.measure(View.java:8313)
08-17 18:12:24.835: E/AndroidRuntime(17951): 	at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
08-17 18:12:24.835: E/AndroidRuntime(17951): 	at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
08-17 18:12:24.835: E/AndroidRuntime(17951): 	at android.view.View.measure(View.java:8313)
08-17 18:12:24.835: E/AndroidRuntime(17951): 	at android.widget.LinearLayout.measureVertical(LinearLayout.java:531)
08-17 18:12:24.835: E/AndroidRuntime(17951): 	at android.widget.LinearLayout.onMeasure(LinearLayout.java:309)
08-17 18:12:24.835: E/AndroidRuntime(17951): 	at android.view.View.measure(View.java:8313)
08-17 18:12:24.835: E/AndroidRuntime(17951): 	at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
08-17 18:12:24.835: E/AndroidRuntime(17951): 	at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
08-17 18:12:24.835: E/AndroidRuntime(17951): 	at android.view.View.measure(View.java:8313)
08-17 18:12:24.835: E/AndroidRuntime(17951): 	at android.view.ViewRoot.performTraversals(ViewRoot.java:839)
08-17 18:12:24.835: E/AndroidRuntime(17951): 	at android.view.ViewRoot.handleMessage(ViewRoot.java:1859)
08-17 18:12:24.835: E/AndroidRuntime(17951): 	at android.os.Handler.dispatchMessage(Handler.java:99)
08-17 18:12:24.835: E/AndroidRuntime(17951): 	at android.os.Looper.loop(Looper.java:130)
08-17 18:12:24.835: E/AndroidRuntime(17951): 	at android.app.ActivityThread.main(ActivityThread.java:3809)
08-17 18:12:24.835: E/AndroidRuntime(17951): 	at java.lang.reflect.Method.invokeNative(Native Method)
08-17 18:12:24.835: E/AndroidRuntime(17951): 	at java.lang.reflect.Method.invoke(Method.java:507)
08-17 18:12:24.835: E/AndroidRuntime(17951): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-17 18:12:24.835: E/AndroidRuntime(17951): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-17 18:12:24.835: E/AndroidRuntime(17951): 	at dalvik.system.NativeStart.main(Native Method)
源代码如下:

public void compareID(){

    if (userInput.equals(LoginID)){
        //phone screen unlocked
        //continue
        Toast.makeText(ScreenLockActivity.this, "Success!", Toast.LENGTH_SHORT).show();
    }
    else{
        count += 1;
        input.setText("");
        Toast.makeText(ScreenLockActivity.this, count, Toast.LENGTH_SHORT).show();
    }
}
看一下
Toast.makeText(ScreenLockActivity.this, count, Toast.LENGTH_SHORT).show();
的API


这里text是CharSequence而不是int类型,只要将更改为

count+""
或者
Integer.toString(count)
即可


注意:在开发当中一定不要太相信Android对字符串的处理,同样的,如果你对textView.setText(IntValue)虽然其没有提示类型错误,也会报同样的错误。

因此,对于赋值操作一定要赋予其类型兼容的值。


你可能感兴趣的:(android.content.res.Resources$NotFoundException: String resource ID #0x6错误的解决办法)