问题描述
已经调试了一段时间...帮助?是的,我知道是什么原因引起的,但IDK的如何解决它......
公共无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState);
随机RAN =新的随机();
的String [] =命运{里斯,Maak,Buscarino,加斯东,佐久间,Namjoshi};
INT I = ran.nextInt(6);
如果(ⅰ!= 0){
字符串的东西=命运[I]
的TextView吨;
T =(的TextView)findViewById(R.id.textView1);
CharSequence的C =东西;
t.setText(C);
}
如果(我== 0){
字符串的东西=里斯;
的TextView吨;
T =(的TextView)findViewById(R.id.textView1);
CharSequence的C =东西;
t.setText(C);
}
}
logcat的数据:
一月七日至19日:58:54.850:信息/ ActivityManager(58):启动活动:意向{行动= android.intent.action.MAIN猫= [android.intent.category .LAUNCHER] FLG = 0x10000000的CMP = com.momentum.wheelofmisfortune / .WomActivity}
一月七日至19日:58:55.119:DEBUG / AndroidRuntime(439):关闭VM
一月七日至19日:58:55.130:DEBUG / dalvikvm(439):调试器分离;对象注册了1项
一月七日至19日:58:55.180:信息/ AndroidRuntime(439):注:连接线的捆扎线#3'失败
一月七日至19日:58:55.490:信息/ ActivityManager(58):启动PROC com.momentum.wheelofmisfortune的活动com.momentum.wheelofmisfortune / .WomActivity:PID = 446 UID = 10035导报= {}
一月七日至19日:58:59.160:信息/ ActivityManager(58):显示活动com.momentum.wheelofmisfortune / .WomActivity:3693毫秒(共556891毫秒)
一月七日至19日:59:05.509:DEBUG / dalvikvm(124):GC_EXPLICIT释放644对象/ 36600字节168ms
一月七日至19日:59:10.579:DEBUG / dalvikvm(204):GC_EXPLICIT释放在160毫秒88的对象/ 3816字节
一月七日至19日:59:15.499:DEBUG / dalvikvm(265):GC_EXPLICIT释放64的对象/ 3072字节66ms
2月7日至19日:02:37.709:调试/ AudioSink(33):bufferCount(4)太小而增加到12
2月7日至19日:02:37.729:信息/ ActivityManager(58):启动活动:意向{CMP = com.momentum.wheelofmisfortune / .generated}
2月7日至19日:02:37.879:DEBUG / AndroidRuntime(446):关闭VM
2月7日至19日:02:37.879:WARN / dalvikvm(446):主题ID = 1:螺纹未捕获的异常退出(组= 0x4001d800)
2月7日至19日:02:37.899:ERROR / AndroidRuntime(446):致命异常:主要
2月7日至19日:02:37.899:ERROR / AndroidRuntime(446):了java.lang.RuntimeException:无法启动活动ComponentInfo {com.momentum.wheelofmisfortune / com.momentum.wheelofmisfortune.generated}:显示java.lang.NullPointerException
2月7日至19日:02:37.899:ERROR / AndroidRuntime(446):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
2月7日至19日:02:37.899:ERROR / AndroidRuntime(446):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
2月7日至19日:02:37.899:ERROR / AndroidRuntime(446):在android.app.ActivityThread.access $ 2300(ActivityThread.java:125)
2月7日至19日:02:37.899:ERROR / AndroidRuntime(446):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:2033)
2月7日至19日:02:37.899:ERROR / AndroidRuntime(446):在android.os.Handler.dispatchMessage(Handler.java:99)
2月7日至19日:02:37.899:ERROR / AndroidRuntime(446):在android.os.Looper.loop(Looper.java:123)
2月7日至19日:02:37.899:ERROR / AndroidRuntime(446):在android.app.ActivityThread.main(ActivityThread.java:4627)
2月7日至19日:02:37.899:ERROR / AndroidRuntime(446):在java.lang.reflect.Method.invokeNative(本机方法)
2月7日至19日:02:37.899:ERROR / AndroidRuntime(446):在java.lang.reflect.Method.invoke(Method.java:521)
2月7日至19日:02:37.899:ERROR / AndroidRuntime(446):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:868)
2月7日至19日:02:37.899:ERROR / AndroidRuntime(446):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
2月7日至19日:02:37.899:ERROR / AndroidRuntime(446):在dalvik.system.NativeStart.main(本机方法)
2月7日至19日:02:37.899:ERROR / AndroidRuntime(446):致:显示java.lang.NullPointerException
2月7日至19日:02:37.899:ERROR / AndroidRuntime(446):在com.momentum.wheelofmisfortune.generated.onCreate(generated.java:22)
2月7日至19日:02:37.899:ERROR / AndroidRuntime(446):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
2月7日至19日:02:37.899:ERROR / AndroidRuntime(446):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
2月7日至19日:02:37.899:ERROR / AndroidRuntime(446):11 ...更多
2月7日至19日:02:37.929:WARN / ActivityManager(58):强制完成活动com.momentum.wheelofmisfortune / .generated
2月7日至19日:02:37.949:WARN / ActivityManager(58):强制完成活动com.momentum.wheelofmisfortune / .WomActivity
2月7日至19日:02:38.139:WARN / AudioFlinger(33):写阻塞84毫秒,10延迟写入,螺纹0xb3f0
2月7日至19日:02:38.449:WARN / ActivityManager(58):为HistoryRecord活动暂停超时{43f6fca0 com.momentum.wheelofmisfortune / .generated}
2月7日至19日:02:38.619:ERROR / MP3Extractor(33):无法重新同步。信令流的末尾。
2月7日至19日:02:39.939:信息/流程(446):发送信号。 PID:446 SIG:9
2月7日至19日:02:39.990:信息/ ActivityManager(58):过程com.momentum.wheelofmisfortune(PID 446)已经死亡。
2月7日至19日:02:39.999:信息/窗口管理器(58):WIN死亡:窗口{43f96690 com.momentum.wheelofmisfortune / com.momentum.wheelofmisfortune.WomActivity暂停= TRUE}
2月7日至19日:02:40.029:WARN / InputManagerService(58):GOT的RemoteException发送SETACTIVE(假)的通知为PID 446 UID 10035
2月7日至19日:02:48.926:WARN / ActivityManager(58):活动破坏了HistoryRecord超时{43e56010 com.momentum.wheelofmisfortune / .WomActivity}
2月7日至19日:02:48.930:WARN / ActivityManager(58):活动破坏了HistoryRecord超时{43f6fca0 com.momentum.wheelofmisfortune / .generated}
2月7日至19日:03:35.550:DEBUG / SntpClient(58):请求时失败:java.net.SocketException异常:地址协议不支持
2月7日至19日:03:45.629:DEBUG / dalvikvm(411):GC_EXPLICIT释放2426对象/在159ms 162784字节
您错过实际线路的数据,但我猜有一个错误在你的布局文件(即你没有之一)。
某处后 super.onCreate(savedInstanceState);
叫你需要调用的setContentView
与布局ID。因为你不设置布局 T =(的TextView)findViewById(R.id.textView1);
终止返回null,当你尝试调用的setText
这是失败的。
Been debugging for a while... Help? Yes, I know what caused it, but idk how to fix it...
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Random ran = new Random();
String[] fate = {"Reese","Maak","Buscarino","Gaston","Sakuma","Namjoshi"};
int i = ran.nextInt(6);
if(i!=0){
String stuff = fate[i];
TextView t;
t =(TextView) findViewById(R.id.textView1);
CharSequence c = stuff;
t.setText(c);
}
if(i==0){
String stuff = "Reese";
TextView t;
t =(TextView) findViewById(R.id.textView1);
CharSequence c = stuff;
t.setText(c);
}
}
Logcat data:
07-19 01:58:54.850: INFO/ActivityManager(58): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.momentum.wheelofmisfortune/.WomActivity }
07-19 01:58:55.119: DEBUG/AndroidRuntime(439): Shutting down VM
07-19 01:58:55.130: DEBUG/dalvikvm(439): Debugger has detached; object registry had 1 entries
07-19 01:58:55.180: INFO/AndroidRuntime(439): NOTE: attach of thread 'Binder Thread #3' failed
07-19 01:58:55.490: INFO/ActivityManager(58): Start proc com.momentum.wheelofmisfortune for activity com.momentum.wheelofmisfortune/.WomActivity: pid=446 uid=10035 gids={}
07-19 01:58:59.160: INFO/ActivityManager(58): Displayed activity com.momentum.wheelofmisfortune/.WomActivity: 3693 ms (total 556891 ms)
07-19 01:59:05.509: DEBUG/dalvikvm(124): GC_EXPLICIT freed 644 objects / 36600 bytes in 168ms
07-19 01:59:10.579: DEBUG/dalvikvm(204): GC_EXPLICIT freed 88 objects / 3816 bytes in 160ms
07-19 01:59:15.499: DEBUG/dalvikvm(265): GC_EXPLICIT freed 64 objects / 3072 bytes in 66ms
07-19 02:02:37.709: DEBUG/AudioSink(33): bufferCount (4) is too small and increased to 12
07-19 02:02:37.729: INFO/ActivityManager(58): Starting activity: Intent { cmp=com.momentum.wheelofmisfortune/.generated }
07-19 02:02:37.879: DEBUG/AndroidRuntime(446): Shutting down VM
07-19 02:02:37.879: WARN/dalvikvm(446): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
07-19 02:02:37.899: ERROR/AndroidRuntime(446): FATAL EXCEPTION: main
07-19 02:02:37.899: ERROR/AndroidRuntime(446): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.momentum.wheelofmisfortune/com.momentum.wheelofmisfortune.generated}: java.lang.NullPointerException
07-19 02:02:37.899: ERROR/AndroidRuntime(446): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
07-19 02:02:37.899: ERROR/AndroidRuntime(446): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
07-19 02:02:37.899: ERROR/AndroidRuntime(446): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
07-19 02:02:37.899: ERROR/AndroidRuntime(446): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
07-19 02:02:37.899: ERROR/AndroidRuntime(446): at android.os.Handler.dispatchMessage(Handler.java:99)
07-19 02:02:37.899: ERROR/AndroidRuntime(446): at android.os.Looper.loop(Looper.java:123)
07-19 02:02:37.899: ERROR/AndroidRuntime(446): at android.app.ActivityThread.main(ActivityThread.java:4627)
07-19 02:02:37.899: ERROR/AndroidRuntime(446): at java.lang.reflect.Method.invokeNative(Native Method)
07-19 02:02:37.899: ERROR/AndroidRuntime(446): at java.lang.reflect.Method.invoke(Method.java:521)
07-19 02:02:37.899: ERROR/AndroidRuntime(446): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-19 02:02:37.899: ERROR/AndroidRuntime(446): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-19 02:02:37.899: ERROR/AndroidRuntime(446): at dalvik.system.NativeStart.main(Native Method)
07-19 02:02:37.899: ERROR/AndroidRuntime(446): Caused by: java.lang.NullPointerException
07-19 02:02:37.899: ERROR/AndroidRuntime(446): at com.momentum.wheelofmisfortune.generated.onCreate(generated.java:22)
07-19 02:02:37.899: ERROR/AndroidRuntime(446): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-19 02:02:37.899: ERROR/AndroidRuntime(446): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
07-19 02:02:37.899: ERROR/AndroidRuntime(446): ... 11 more
07-19 02:02:37.929: WARN/ActivityManager(58): Force finishing activity com.momentum.wheelofmisfortune/.generated
07-19 02:02:37.949: WARN/ActivityManager(58): Force finishing activity com.momentum.wheelofmisfortune/.WomActivity
07-19 02:02:38.139: WARN/AudioFlinger(33): write blocked for 84 msecs, 10 delayed writes, thread 0xb3f0
07-19 02:02:38.449: WARN/ActivityManager(58): Activity pause timeout for HistoryRecord{43f6fca0 com.momentum.wheelofmisfortune/.generated}
07-19 02:02:38.619: ERROR/MP3Extractor(33): Unable to resync. Signalling end of stream.
07-19 02:02:39.939: INFO/Process(446): Sending signal. PID: 446 SIG: 9
07-19 02:02:39.990: INFO/ActivityManager(58): Process com.momentum.wheelofmisfortune (pid 446) has died.
07-19 02:02:39.999: INFO/WindowManager(58): WIN DEATH: Window{43f96690 com.momentum.wheelofmisfortune/com.momentum.wheelofmisfortune.WomActivity paused=true}
07-19 02:02:40.029: WARN/InputManagerService(58): Got RemoteException sending setActive(false) notification to pid 446 uid 10035
07-19 02:02:48.926: WARN/ActivityManager(58): Activity destroy timeout for HistoryRecord{43e56010 com.momentum.wheelofmisfortune/.WomActivity}
07-19 02:02:48.930: WARN/ActivityManager(58): Activity destroy timeout for HistoryRecord{43f6fca0 com.momentum.wheelofmisfortune/.generated}
07-19 02:03:35.550: DEBUG/SntpClient(58): request time failed: java.net.SocketException: Address family not supported by protocol
07-19 02:03:45.629: DEBUG/dalvikvm(411): GC_EXPLICIT freed 2426 objects / 162784 bytes in 159ms
You're missing actual line data, but I'd guess there is an error in your layout file (namely that you don't have one).
Somewhere after the super.onCreate(savedInstanceState);
call you need to call setContentView
with a layout id. Because you aren't setting a layout t =(TextView) findViewById(R.id.textView1);
is returning null, and when you try and call setText
it is failing.
这篇关于NullPointerException异常扔在TextView中的setText()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!