我必须动态地将一个String值设置为android中的textview,但不幸的是我得到了null值错误但是在日志中我可以打印String的值。所以我确信该字符串不是null但是非常大。 这是我的logcat结果:
2-06 16:05:39.930 11631-11631/sarath.com.reachmeE/from_address﹕ Sub Jail Rd, Talap
Kannur, Kerala 670002
11.877453, 75.372992
12-06 16:05:39.940 11631-11631/sarath.com.reachmeE/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{sarath.com.reachme/sarath.com.reachme.app.Mapview}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1970)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995)
at android.app.ActivityThread.access$600(ActivityThread.java:128)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4517)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at sarath.com.reachme.app.Mapview.onCreate(Mapview.java:95)
at android.app.Activity.performCreate(Activity.java:4470)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1053)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1934)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995)
at android.app.ActivityThread.access$600(ActivityThread.java:128)
这是我的代码段:
Log.e("addrs short", String.valueOf(from_address));
address.setText(String.valueOf(from_address));
textview显示的字符串的大小/长度是否有限制?
答案 0 :(得分:1)
您可能不会提及您的地址字段,这就是您收到此错误的原因。
address = (TextView) findElementById(R.id.your_address_id);
答案 1 :(得分:1)
对字符串大小没有限制。几乎可以肯定错误是地址TextView
为空,如果您执行findElementById(R.id.your_address_id);
但视图(R.id.your_address_id)
位于另一个活动中,则可能会发生此错误。