我的android应用程序在没有这两行的情况下工作正常:
layMain= (LinearLayout) findViewById(R.id.layout_main);
layMain.setOnTouchListener((OnTouchListener) this);
调试显示系统在第一行之后被迫关闭。 什么原因?谢谢。
这是我的onCreate()方法,
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Set main.XML as the layout for this Activity
setContentView(R.layout.main);
// Add these two lines
layMain= (LinearLayout) findViewById(R.id.layout_main);
layMain.setOnTouchListener((OnTouchListener) this);
// Add a few countries to the spinner
Spinner spinnerCountries = (Spinner) findViewById(R.id.spinner_country);
@SuppressWarnings({ "unchecked", "rawtypes" })
ArrayAdapter countryArrayAdapter = new ArrayAdapter(this,
android.R.layout.simple_spinner_dropdown_item,
new String[] { "Canada", "USA" });
spinnerCountries.setAdapter(countryArrayAdapter);
}
堆栈追踪:
04-19 19:31:12.146: DEBUG/AndroidRuntime(484): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
04-19 19:31:12.146: DEBUG/AndroidRuntime(484): CheckJNI is ON
04-19 19:31:13.834: DEBUG/AndroidRuntime(484): Calling main entry com.android.commands.pm.Pm
04-19 19:31:13.934: DEBUG/AndroidRuntime(484): Shutting down VM
04-19 19:31:13.954: INFO/AndroidRuntime(484): NOTE: attach of thread 'Binder Thread #3' failed
04-19 19:31:13.967: DEBUG/dalvikvm(484): GC_CONCURRENT freed 101K, 71% free 297K/1024K, external 0K/0K, paused 2ms+2ms
04-19 19:31:13.967: DEBUG/jdwp(484): Got wake-up signal, bailing out of select
04-19 19:31:13.974: DEBUG/dalvikvm(484): Debugger has detached; object registry had 1 entries
04-19 19:31:15.246: DEBUG/AndroidRuntime(495): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
04-19 19:31:15.246: DEBUG/AndroidRuntime(495): CheckJNI is ON
04-19 19:31:16.904: DEBUG/AndroidRuntime(495): Calling main entry com.android.commands.am.Am
04-19 19:31:16.984: INFO/ActivityManager(74): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=zaid.project.SlidingActivity/.SlidingActivityActivity } from pid 495
04-19 19:31:17.074: DEBUG/AndroidRuntime(495): Shutting down VM
04-19 19:31:17.124: INFO/AndroidRuntime(495): NOTE: attach of thread 'Binder Thread #3' failed
04-19 19:31:17.236: DEBUG/dalvikvm(495): GC_CONCURRENT freed 102K, 69% free 318K/1024K, external 0K/0K, paused 2ms+4ms
04-19 19:31:17.274: DEBUG/jdwp(495): Got wake-up signal, bailing out of select
04-19 19:31:17.274: DEBUG/dalvikvm(495): Debugger has detached; object registry had 1 entries
04-19 19:31:17.564: INFO/ActivityManager(74): Start proc zaid.project.SlidingActivity for activity zaid.project.SlidingActivity/.SlidingActivityActivity: pid=505 uid=10034 gids={}
04-19 19:31:19.584: DEBUG/AndroidRuntime(505): Shutting down VM
04-19 19:31:19.584: WARN/dalvikvm(505): threadid=1: thread exiting with uncaught exception (group=0x40015560)
04-19 19:31:19.634: ERROR/AndroidRuntime(505): FATAL EXCEPTION: main
04-19 19:31:19.634: ERROR/AndroidRuntime(505): java.lang.RuntimeException: Unable to start activity ComponentInfo{zaid.project.SlidingActivity/zaid.project.SlidingActivity.SlidingActivityActivity}: java.lang.ClassCastException: android.widget.ViewFlipper
04-19 19:31:19.634: ERROR/AndroidRuntime(505): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
04-19 19:31:19.634: ERROR/AndroidRuntime(505): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
04-19 19:31:19.634: ERROR/AndroidRuntime(505): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
04-19 19:31:19.634: ERROR/AndroidRuntime(505): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
04-19 19:31:19.634: ERROR/AndroidRuntime(505): at android.os.Handler.dispatchMessage(Handler.java:99)
04-19 19:31:19.634: ERROR/AndroidRuntime(505): at android.os.Looper.loop(Looper.java:123)
04-19 19:31:19.634: ERROR/AndroidRuntime(505): at android.app.ActivityThread.main(ActivityThread.java:3683)
04-19 19:31:19.634: ERROR/AndroidRuntime(505): at java.lang.reflect.Method.invokeNative(Native Method)
04-19 19:31:19.634: ERROR/AndroidRuntime(505): at java.lang.reflect.Method.invoke(Method.java:507)
04-19 19:31:19.634: ERROR/AndroidRuntime(505): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-19 19:31:19.634: ERROR/AndroidRuntime(505): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-19 19:31:19.634: ERROR/AndroidRuntime(505): at dalvik.system.NativeStart.main(Native Method)
04-19 19:31:19.634: ERROR/AndroidRuntime(505): Caused by: java.lang.ClassCastException: android.widget.ViewFlipper
04-19 19:31:19.634: ERROR/AndroidRuntime(505): at zaid.project.SlidingActivity.SlidingActivityActivity.onCreate(SlidingActivityActivity.java:28)
04-19 19:31:19.634: ERROR/AndroidRuntime(505): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-19 19:31:19.634: ERROR/AndroidRuntime(505): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
04-19 19:31:19.634: ERROR/AndroidRuntime(505): ... 11 more
04-19 19:31:19.664: WARN/ActivityManager(74): Force finishing activity zaid.project.SlidingActivity/.SlidingActivityActivity
04-19 19:31:20.344: WARN/ActivityManager(74): Activity pause timeout for HistoryRecord{405f6c20 zaid.project.SlidingActivity/.SlidingActivityActivity}
04-19 19:31:31.898: WARN/ActivityManager(74): Activity destroy timeout for HistoryRecord{405f6c20 zaid.project.SlidingActivity/.SlidingActivityActivity}
04-19 19:32:12.944: INFO/Process(505): Sending signal. PID: 505 SIG: 9
04-19 19:32:12.985: INFO/ActivityManager(74): Process zaid.project.SlidingActivity (pid 505) has died.
04-19 19:32:13.676: WARN/InputManagerService(74): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@406e5518
答案 0 :(得分:0)
我怀疑问题出在这一行:
layMain = (LinearLayout) findViewById(R.id.layout_main);
(SlidingActivityActivity.java中的第28行?)
你没有发布你的XML文件,所以我只是在这里猜测。最有可能的是,R.id.layout_main
指向包含ViewFlipper
的{{1}}。检查您的XML以确保使用正确的ID。
答案 1 :(得分:0)
我认为它可以解决xml文件中的配置问题。这里有一个类似的线程:
<TableLayout><TableRow><LinearLayout> hates me. Force close on run. Android