2012-04-11 153 views
0

我并不是全新的eclipse android插件,但我从头开始编写一个项目是新的。所以我去了Android开发者网站,遵循'Hello World'教程。Android程序启动失败

当我运行我的程序时,模拟器出现一个屏幕,说 不幸的是,Android已停止工作。 我的代码是:

HelloAndroid.Java

package daniel.android.projects; 

import android.app.Activity; 
import android.os.Bundle; 

    public class HelloAndroid extends Activity { 
     /** Called when the activity is first created. */ 
     @Override 
     public void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
      Object o = null; 
      o.toString(); 
      setContentView(R.layout.main); 
     } 
    } 

main.xml中

<?xml version="1.0" encoding="utf-8"?> 
<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/textview" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:text="@string/hello"/> 

的strings.xml

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <string name="hello">Hello, Android! I am a string resource!</string> 
    <string name="app_name">Hello, Android</string> 
</resources> 

的Manifest.xml

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="daniel.android.projects" 
    android:versionCode="1" 
    android:versionName="1.0" > 

    <uses-sdk android:minSdkVersion="15" /> 

    <application 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" > 
     <activity 
      android:name=".AndroidTesterActivity" 
      android:label="@string/app_name" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
    </application> 

</manifest> 

回答

1

你有一个空指针异常,您分配它nullo,然后调用toString()

Object o = null; 
o.toString(); 

现在看来似乎没有什么服务在您的应用程序无论如何,它不应该存在。

另外,在看你的代码,创建HelloAndroid类,但在themanifest声明

android:name=".AndroidTesterActivity" 

应该

android:name=".HelloAndroid" 
+0

空指针是故意的,所以我可以看到它抛出一个错误 – kreeSeeker 2012-04-11 17:06:54

+0

当引发错误时,应用程序将无法加载。 – MByD 2012-04-11 17:07:50

+0

呵呵。该教程说,把它放在那里。 – kreeSeeker 2012-04-11 17:08:15