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, 登辉 黄 <huangdeng...@gmail.com> 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?
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to