我希望在将一些模式匹配到url
后使我的按钮可见每件事情都很顺利,但它没有将我的按钮的可见性设置为true 我正在尝试这个
try {
sleep((int)(Math.random() * 1000));
btn = (Button) findViewById(R.id.My_btn);
btn.requestFocus();
btn.setVisibility(0);
//here btn.setvisibility(View.VISIBLE) also not working
}
这是我的按钮
的日志05-04 10:30:12.212: WARN/InputManagerService(52): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@437da3e8
05-04 10:30:13.673: WARN/InputManagerService(52): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@4379d170
05-04 10:30:16.054: INFO/NotificationService(52): enqueueToast pkg=android.com.MobiintheMorning callback=android.app.ITransientNotification$Stub$Proxy@4376ae30 duration=0
05-04 10:30:16.064: INFO/System.out(677): button founded
05-04 10:30:16.629: WARN/dalvikvm(677): threadid=31: thread exiting with uncaught exception (group=0x4001aa28)
05-04 10:30:16.629: ERROR/AndroidRuntime(677): Uncaught handler: thread Thread-17 exiting due to uncaught exception
05-04 10:30:16.634: ERROR/AndroidRuntime(677): android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
05-04 10:30:16.634: ERROR/AndroidRuntime(677): at android.view.ViewRoot.checkThread(ViewRoot.java:2629)
05-04 10:30:16.634: ERROR/AndroidRuntime(677): at android.view.ViewRoot.focusableViewAvailable(ViewRoot.java:1519)
05-04 10:30:16.634: ERROR/AndroidRuntime(677): at android.view.ViewGroup.focusableViewAvailable(ViewGroup.java:448)
05-04 10:30:16.634: ERROR/AndroidRuntime(677): at android.view.ViewGroup.focusableViewAvailable(ViewGroup.java:448)
05-04 10:30:16.634: ERROR/AndroidRuntime(677): at android.view.ViewGroup.focusableViewAvailable(ViewGroup.java:448)
05-04 10:30:16.634: ERROR/AndroidRuntime(677): at android.view.ViewGroup.focusableViewAvailable(ViewGroup.java:448)
05-04 10:30:16.634: ERROR/AndroidRuntime(677): at android.view.View.setFlags(View.java:4270)
05-04 10:30:16.634: ERROR/AndroidRuntime(677): at android.view.View.setVisibility(View.java:2964)
05-04 10:30:16.634: ERROR/AndroidRuntime(677): at android.com.MobiintheMorning.MobiintheMorningActivity.btnvisibility(MobiintheMorningActivity.java:307)
05-04 10:30:16.634: ERROR/AndroidRuntime(677): at android.com.MobiintheMorning.MobiintheMorningActivity$temp.run(MobiintheMorningActivity.java:277)
05-04 10:30:16.644: INFO/Process(52): Sending signal. PID: 677 SIG: 3
05-04 10:30:16.644: INFO/dalvikvm(677): threadid=7: reacting to signal 3
05-04 10:30:16.644: ERROR/dalvikvm(677): Unable to open stack trace file '/data/anr/traces.txt': Permission denied
05-04 10:33:50.293: DEBUG/AndroidRuntime(893): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
05-04 10:33:50.293: DEBUG/AndroidRuntime(893): CheckJNI is ON
05-04 10:33:50.494: DEBUG/AndroidRuntime(893): --- registering native functions ---
05-04 10:33:50.494: INFO/jdwp(893): received file descriptor 20 from ADB
05-04 10:33:50.693: DEBUG/ddm-heap(893): Got feature list request
05-04 10:33:51.133: DEBUG/PackageParser(52): Scanning package: /data/app/vmdl65231.tmp
05-04 10:33:51.314: INFO/PackageManager(52): Removing non-system package:android.com.MobiintheMorning
05-04 10:33:51.314: DEBUG/PackageManager(52): Removing package android.com.MobiintheMorning
05-04 10:33:51.314: DEBUG/PackageManager(52): Activities: android.com.MobiintheMorning.MobiintheMorningActivity android.com.MobiintheMorning.FindFilesByType android.com.MobiintheMorning.EmailAct android.com.MobiintheMorning.DisplaySong
05-04 10:33:51.373: DEBUG/PackageManager(52): Scanning package android.com.MobiintheMorning
05-04 10:33:51.373: INFO/PackageManager(52): /data/app/vmdl65231.tmp changed; unpacking
05-04 10:33:51.383: DEBUG/installd(32): DexInv: --- BEGIN '/data/app/vmdl65231.tmp' ---
05-04 10:33:51.744: DEBUG/dalvikvm(900): DexOpt: load 36ms, verify 187ms, opt 2ms
05-04 10:33:51.774: DEBUG/installd(32): DexInv: --- END '/data/app/vmdl65231.tmp' (success) ---
05-04 10:33:51.774: DEBUG/PackageManager(52): Activities: android.com.MobiintheMorning.MobiintheMorningActivity android.com.MobiintheMorning.FindFilesByType android.com.MobiintheMorning.EmailAct android.com.MobiintheMorning.DisplaySong
05-04 10:33:51.793: DEBUG/ActivityManager(52): Uninstalling process android.com.MobiintheMorning
05-04 10:33:51.793: DEBUG/ActivityManager(52): Force removing process ProcessRecord{438e6a48 677:android.com.MobiintheMorning/10022} (android.com.MobiintheMorning/10022)
05-04 10:33:51.803: INFO/Process(52): Sending signal. PID: 677 SIG: 9
05-04 10:33:51.892: WARN/UsageStats(52): Unexpected resume of com.android.launcher while already resumed in android.com.MobiintheMorning
05-04 10:33:51.934: INFO/WindowManager(52): WIN DEATH: Window{438462b8 android.com.MobiintheMorning/android.com.MobiintheMorning.MobiintheMorningActivity paused=false}
05-04 10:33:51.943: DEBUG/ActivityManager(52): Received spurious death notification for thread android.os.BinderProxy@43845d50
05-04 10:33:51.963: WARN/InputManagerService(52): Got RemoteException sending setActive(false) notification to pid 677 uid 10022
05-04 10:33:52.194: INFO/installd(32): move /data/dalvik-cache/data@app@vmdl65231.tmp@classes.dex -> /data/dalvik-cache/data@app@android.com.MobiintheMorning.apk@classes.dex
05-04 10:33:52.204: DEBUG/PackageManager(52): New package installed in /data/app/android.com.MobiintheMorning.apk
05-04 10:33:52.284: DEBUG/AndroidRuntime(893): Shutting down VM
05-04 10:33:52.284: DEBUG/dalvikvm(893): DestroyJavaVM waiting for non-daemon threads to exit
05-04 10:33:52.294: DEBUG/ActivityManager(52): Uninstalling process android.com.MobiintheMorning
05-04 10:33:52.303: DEBUG/dalvikvm(893): DestroyJavaVM shutting VM down
05-04 10:33:52.303: DEBUG/dalvikvm(893): HeapWorker thread shutting down
05-04 10:33:52.303: DEBUG/dalvikvm(893): HeapWorker thread has shut down
05-04 10:33:52.303: DEBUG/jdwp(893): JDWP shutting down net...
05-04 10:33:52.303: DEBUG/jdwp(893): Got wake-up signal, bailing out of select
05-04 10:33:52.303: INFO/dalvikvm(893): Debugger has detached; object registry had 1 entries
05-04 10:33:52.313: DEBUG/dalvikvm(893): VM cleaning up
05-04 10:33:52.354: DEBUG/dalvikvm(893): LinearAlloc 0x0 used 665236 of 4194304 (15%)
05-04 10:33:52.454: WARN/ResourceType(52): No package identifier when getting value for resource number 0x7f060000
05-04 10:33:52.464: WARN/ResourceType(52): No package identifier when getting value for resource number 0x7f060001
05-04 10:33:52.643: DEBUG/dalvikvm(95): GC freed 131 objects / 5400 bytes in 231ms
05-04 10:33:52.643: DEBUG/HomeLoaders(95): application intent received: android.intent.action.PACKAGE_REMOVED, replacing=true
05-04 10:33:52.643: DEBUG/HomeLoaders(95): --> package:android.com.MobiintheMorning
05-04 10:33:52.653: DEBUG/HomeLoaders(95): application intent received: android.intent.action.PACKAGE_ADDED, replacing=true
05-04 10:33:52.653: DEBUG/HomeLoaders(95): --> package:android.com.MobiintheMorning
05-04 10:33:52.653: DEBUG/HomeLoaders(95): --> update package android.com.MobiintheMorning
05-04 10:33:52.813: DEBUG/dalvikvm(52): GC freed 10887 objects / 620232 bytes in 335ms
05-04 10:33:52.983: WARN/ResourceType(52): No package identifier when getting value for resource number 0x7f060000
05-04 10:33:53.012: WARN/ResourceType(52): No package identifier when getting value for resource number 0x7f060001
05-04 10:33:53.363: DEBUG/AndroidRuntime(907): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
05-04 10:33:53.363: DEBUG/AndroidRuntime(907): CheckJNI is ON
05-04 10:33:53.543: DEBUG/AndroidRuntime(907): --- registering native functions ---
05-04 10:33:53.543: INFO/jdwp(907): received file descriptor 20 from ADB
05-04 10:33:53.734: DEBUG/ddm-heap(907): Got feature list request
05-04 10:33:54.154: INFO/ActivityManager(52): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=android.com.MobiintheMorning/.MobiintheMorningActivity }
05-04 10:33:54.183: DEBUG/AndroidRuntime(907): Shutting down VM
05-04 10:33:54.183: DEBUG/dalvikvm(907): DestroyJavaVM waiting for non-daemon threads to exit
05-04 10:33:54.223: DEBUG/dalvikvm(907): DestroyJavaVM shutting VM down
05-04 10:33:54.223: DEBUG/dalvikvm(907): HeapWorker thread shutting down
05-04 10:33:54.223: DEBUG/dalvikvm(907): HeapWorker thread has shut down
05-04 10:33:54.233: DEBUG/jdwp(907): JDWP shutting down net...
05-04 10:33:54.233: DEBUG/jdwp(907): +++ peer disconnected
05-04 10:33:54.233: INFO/dalvikvm(907): Debugger has detached; object registry had 1 entries
05-04 10:33:54.243: DEBUG/dalvikvm(907): VM cleaning up
05-04 10:33:54.253: INFO/ActivityManager(52): Start proc android.com.MobiintheMorning for activity android.com.MobiintheMorning/.MobiintheMorningActivity: pid=915 uid=10022 gids={3003, 1015}
05-04 10:33:54.313: DEBUG/dalvikvm(907): LinearAlloc 0x0 used 676828 of 4194304 (16%)
05-04 10:33:54.423: INFO/jdwp(915): received file descriptor 20 from ADB
05-04 10:33:54.473: DEBUG/ddm-heap(915): Got feature list request
05-04 10:33:55.513: INFO/ActivityManager(52): Displayed activity android.com.MobiintheMorning/.MobiintheMorningActivity: 1312 ms (total 1312 ms)
05-04 10:34:05.163: DEBUG/dalvikvm(237): GC freed 43 objects / 2088 bytes in 54ms
05-04 10:34:10.253: DEBUG/dalvikvm(95): GC freed 2943 objects / 167248 bytes in 96ms
05-04 10:34:14.213: DEBUG/dalvikvm(915): GC freed 2995 objects / 320496 bytes in 79ms
05-04 10:34:16.112: WARN/InputManagerService(52): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@4394c950
05-04 10:34:17.414: WARN/InputManagerService(52): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@4394d7b8
05-04 10:34:19.334: INFO/NotificationService(52): enqueueToast pkg=android.com.MobiintheMorning callback=android.app.ITransientNotification$Stub$Proxy@4394d9f0 duration=0
05-04 10:34:19.344: INFO/System.out(915): button founded
05-04 10:34:19.778: WARN/dalvikvm(915): threadid=31: thread exiting with uncaught exception (group=0x4001aa28)
05-04 10:34:19.778: ERROR/AndroidRuntime(915): Uncaught handler: thread Thread-17 exiting due to uncaught exception
05-04 10:34:19.783: ERROR/AndroidRuntime(915): android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
05-04 10:34:19.783: ERROR/AndroidRuntime(915): at android.view.ViewRoot.checkThread(ViewRoot.java:2629)
05-04 10:34:19.783: ERROR/AndroidRuntime(915): at android.view.ViewRoot.focusableViewAvailable(ViewRoot.java:1519)
05-04 10:34:19.783: ERROR/AndroidRuntime(915): at android.view.ViewGroup.focusableViewAvailable(ViewGroup.java:448)
05-04 10:34:19.783: ERROR/AndroidRuntime(915): at android.view.ViewGroup.focusableViewAvailable(ViewGroup.java:448)
05-04 10:34:19.783: ERROR/AndroidRuntime(915): at android.view.ViewGroup.focusableViewAvailable(ViewGroup.java:448)
05-04 10:34:19.783: ERROR/AndroidRuntime(915): at android.view.ViewGroup.focusableViewAvailable(ViewGroup.java:448)
05-04 10:34:19.783: ERROR/AndroidRuntime(915): at android.view.View.setFlags(View.java:4270)
05-04 10:34:19.783: ERROR/AndroidRuntime(915): at android.view.View.setVisibility(View.java:2964)
05-04 10:34:19.783: ERROR/AndroidRuntime(915): at android.com.MobiintheMorning.MobiintheMorningActivity$temp.run(MobiintheMorningActivity.java:277)
05-04 10:34:19.793: INFO/Process(52): Sending signal. PID: 915 SIG: 3
05-04 10:34:19.793: INFO/dalvikvm(915): threadid=7: reacting to signal 3
05-04 10:34:19.793: ERROR/dalvikvm(915): Unable to open stack trace file '/data/anr/traces.txt': Permission denied
答案 0 :(得分:1)
您收到错误:
05-04 10:34:19.783: ERROR / AndroidRuntime(915): android.view.ViewRoot $ CalledFromWrongThreadException: 只创建了原始线程 视图层次结构可以触及它 views.05
这表明您正在尝试从非ui线程中显示按钮。如果是这样,那么你需要做这样的事情,让UI线程改变按钮的可见性:
try{
btn.post(new Runnable() {
public void run() {
btn.requestFocus();
btn.setVisibility(0); // Or: btn.setVisibility(View.VISIBLE)
}});
}catch (Exception e) {
Log.d("test", e.toString());
}
答案 1 :(得分:0)
你是在线程上做的吗?如果您需要使用处理程序或说
` runOnUiThread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
}
});
`
答案 2 :(得分:0)
尝试使用AsyncTask,
它有pre和post方法,您可以尝试在post方法中启用按钮!
私有类CallWebServiceInBackGround扩展 AsyncTask {
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected Void doInBackground(Void... arg0) {
return null;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
button.setvisibilty(View.INVISIBLE);
}
}