Yeah, you are right. i already fix my problem through system log . In DDMS view, we can see exact reason cause the application be crashed
To Dianne Hackborn Sorry for disturbing your work. I know i should post my question to public forums. but i made a stupid mistake. It will not be happen again. 2009/10/13 Dianne Hackborn <[email protected]> > You need to provide the -full- stack crawl including, very importantly, all > of the "caused by" clauses which tell you the actual original errors that > happened. > > 2009/10/12 黄登辉 <[email protected]> > > Thanks for your warm reply. yeah, >> i know which line code cause this exception. >> the following is part of system log. >> 10-13 09:42:10.782: ERROR/AndroidRuntime(705): Caused by: >> java.lang.NullPointerException >> 10-13 09:42:10.782: ERROR/AndroidRuntime(705): at >> com.example.android.snake.Snake.onCreate(Snake.java:84) >> >> line 84 is :mSnakeView.setMode(SnakeView.READY); >> >> and the root reason is >> > try { >> > setContentView(R.layout.snake_layout); >> > } catch (Exception e) { >> > Log.d("SnakeView", "inside onCreate function -- >> setContentView!"); >> > >> > } >> > >> > >> > try { >> > mSnakeView.setTextView((TextView) >> findViewById(R.id.text)); >> > } catch (Exception e) { >> > Log.d("SnakeView", "inside onCreate function >> last!"); >> > >> > } >> >> because in system log, there are two log as following: >> >> 10-13 09:42:10.763: DEBUG/SnakeView(705): inside onCreate function -- >> setContentView! >> 10-13 09:42:10.763: DEBUG/SnakeView(705): inside onCreate function last! >> >> >> summary, i think there is a error in layout xml file, and cause android >> can't explain this layout xml file. >> >> then occur the above exception. But the just reuse the snake's layout xml >> from sdk sample. so i can't find any error in layout xml file. >> >> But i modify the implemented code of SnakeView and tileView . maybe the >> implemented code have some problems. >> >> and attachment is source code, if you have some time, please have a look >> at it. and i will continue to find this bug, which let me be in trouble two >> days. >> >> >> >> >> >> 2009/10/13 Marco Nelissen <[email protected]> >> >> >>> Look at the system log (either using "adb logcat" or with the ddms >>> perspective in eclipse), and it will tell you exactly where and why it >>> crashed. >>> >>> >>> On Mon, Oct 12, 2009 at 7:37 AM, 登辉 黄 <[email protected]> wrote: >>> > >>> > we modifid snake from sdk samples. there is a running exception >>> > "stopped unexpectedly". after step debug, i found that the statement >>> > setContentView(R.layout.snake_layout); and mSnakeView.setTextView >>> > ((TextView) findViewById(R.id.text));from snake.java file will throw >>> > exceptions. i think the layout xml file have a some error. but i can't >>> > find any error in this file. >>> > >>> > >>> > <?xml version="1.0" encoding="utf-8"?> >>> > <!-- Copyright (C) 2007 The Android Open Source Project >>> > >>> > Licensed under the Apache License, Version 2.0 (the "License"); >>> > you may not use this file except in compliance with the License. >>> > You may obtain a copy of the License at >>> > >>> > http://www.apache.org/licenses/LICENSE-2.0 >>> > >>> > Unless required by applicable law or agreed to in writing, >>> > software >>> > distributed under the License is distributed on an "AS IS" BASIS, >>> > WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or >>> > implied. >>> > See the License for the specific language governing permissions >>> > and >>> > limitations under the License. >>> > --> >>> > >>> > <FrameLayout xmlns:android="http://schemas.android.com/apk/res/ >>> > android" >>> > android:layout_width="fill_parent" >>> > android:layout_height="fill_parent" >>> > xmlns:app="http://schemas.android.com/apk/res/ >>> > com.example.android.snake"> >>> > >>> > <com.example.android.snake.SnakeView >>> > android:id="@+id/snake" >>> > android:layout_width="fill_parent" >>> > android:layout_height="fill_parent" >>> > app:tileSize="40" >>> > /> >>> > >>> > <RelativeLayout >>> > android:layout_width="fill_parent" >>> > android:layout_height="fill_parent" > >>> > >>> > <TextView >>> > android:id="@+id/text" >>> > android:text="@string/snake_layout_text_text" >>> > android:visibility="visible" >>> > android:layout_width="wrap_content" >>> > android:layout_height="wrap_content" >>> > android:layout_centerInParent="true" >>> > android:gravity="center_horizontal" >>> > android:textColor="#ff8888ff" >>> > android:textSize="24sp"/> >>> > </RelativeLayout> >>> > </FrameLayout> >>> > >>> > >>> > and snake.java as following: >>> > >>> > /* >>> > * Copyright (C) 2007 The Android Open Source Project >>> > * >>> > * Licensed under the Apache License, Version 2.0 (the "License"); >>> > * you may not use this file except in compliance with the License. >>> > * You may obtain a copy of the License at >>> > * >>> > * http://www.apache.org/licenses/LICENSE-2.0 >>> > * >>> > * Unless required by applicable law or agreed to in writing, software >>> > * distributed under the License is distributed on an "AS IS" BASIS, >>> > * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or >>> > implied. >>> > * See the License for the specific language governing permissions and >>> > * limitations under the License. >>> > */ >>> > >>> > package com.example.android.snake; >>> > >>> > import android.app.Activity; >>> > import android.os.Bundle; >>> > import android.util.Log; >>> > import android.view.Window; >>> > import android.widget.TextView; >>> > >>> > /** >>> > * Snake: a simple game that everyone can enjoy. >>> > * >>> > * This is an implementation of the classic Game "Snake", in which you >>> > control a >>> > * serpent roaming around the garden looking for apples. Be careful, >>> > though, >>> > * because when you catch one, not only will you become longer, but >>> > you'll move >>> > * faster. Running into yourself or the walls will end the game. >>> > * >>> > */ >>> > public class Snake extends Activity { >>> > >>> > private SnakeView mSnakeView; >>> > >>> > private static String ICICLE_KEY = "snake-view"; >>> > >>> > /** >>> > * Called when Activity is first created. Turns off the title bar, >>> > sets up >>> > * the content views, and fires up the SnakeView. >>> > * >>> > */ >>> > @Override >>> > public void onCreate(Bundle savedInstanceState) { >>> > super.onCreate(savedInstanceState); >>> > >>> > >>> > // No Title bar >>> > try{ >>> > requestWindowFeature(Window.FEATURE_NO_TITLE); >>> > }catch(Exception e){ >>> > Log.d("SnakeView", "inside onCreate function -- >>> > requestWindowFeature!"); >>> > >>> > } >>> > >>> > try { >>> > setContentView(R.layout.snake_layout); >>> > } catch (Exception e) { >>> > Log.d("SnakeView", "inside onCreate function -- >>> setContentView!"); >>> > >>> > } >>> > >>> > try { >>> > mSnakeView = (SnakeView) >>> findViewById(R.id.snake); >>> > } catch (Exception e) { >>> > Log.d("SnakeView", "inside onCreate function -- >>> findViewById >>> > (R.id.snake)!"); >>> > >>> > } >>> > >>> > try { >>> > mSnakeView.setTextView((TextView) >>> findViewById(R.id.text)); >>> > } catch (Exception e) { >>> > Log.d("SnakeView", "inside onCreate function >>> last!"); >>> > >>> > } >>> > >>> > >>> > >>> > >>> > if (savedInstanceState == null) { >>> > // We were just launched -- set up a new game >>> > mSnakeView.setMode(SnakeView.READY); >>> > } else { >>> > // We are being restored >>> > Bundle map = savedInstanceState.getBundle(ICICLE_KEY); >>> > if (map == null) { >>> > mSnakeView.setMode(SnakeView.PAUSE); >>> > } >>> > } >>> > } >>> > >>> > @Override >>> > protected void onPause() { >>> > super.onPause(); >>> > // Pause the game along with the activity >>> > mSnakeView.setMode(SnakeView.PAUSE); >>> > } >>> > >>> > >>> > >>> > } >>> > >>> > Please some peoples met this kind of problem or master in android >>> > development, give me some suggestion? >>> > >>> > By the way, how can i attach some code? >>> > >>> > > >>> > >>> >>> >>> >> >> >> > > > -- > Dianne Hackborn > Android framework engineer > [email protected] > > Note: please don't send private questions to me, as I don't have time to > provide private support, and so won't reply to such e-mails. All such > questions should be posted on public forums, where I and others can see and > answer them. > > > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---

