2011-09-15 149 views
-1

我想在我的android手機上運行一個簡單的程序hello world。 但應用程序意外停止。 apk文件很容易安裝,但並未運行。 我不明白爲什麼會這樣爲什麼android手機沒有運行我的應用程序?

helloWorld.java

包com.hellos;

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

public class HelloAndroid extends Activity {  
/** Called when the activity is first created. */  
@Override  
     public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     TextView tv = new TextView(this); 
     tv.setText("Hello, Android"); 
     setContentView(tv);  
} 
} 
+0

是它在模擬器中運行? – Abhi

+0

LogCat說什麼? – DonGru

+1

它有時會在eclipse ide上成功運行,有時會顯示模擬器-5554取消錯誤 –

回答

0

按照Hello World Tutorial

如果你已經是和已正確執行了它(安裝模擬器等),然後一切都應該工作。

我知道這可能聽起來很奇怪,但是如果你確定所有的工作都已經完成,請嘗試將代碼複製並粘貼到一個新項目中,然後嘗試重新啓動它。 (其他人已經在SO上完成了這個工作,並且它已經工作了。)

我在其他方面有這樣的錯誤,而且它通常是電話/模擬器由於某種原因不喜歡的東西(當我認爲一切都應該工作時)。嘗試愚蠢(這將行爲,因爲它的你好世界)你的XML等,看看你是否可以讓它運行。

您的代碼應如下

package com.example.helloandroid; 
import android.app.Activity; 
import android.os.Bundle; 
import android.widget.TextView; 

public class HelloAndroid extends Activity { 
/** Called when the activity is first created. */ 
@Override 

public void onCreate(Bundle savedInstanceState) {  
super.onCreate(savedInstanceState);  
TextView tv = new TextView(this);  
tv.setText("Hello, Android");  
setContentView(tv); } 
} 
+1

我已經跟着它,並完全複製它 –

+2

包com.hellos; import android.app.Activity; import android.os.Bundle; public class HelloAndroid extends Activity當活動首次創建時調用。 */ @Override public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.main); } } –

+1

這是代碼 –

相關問題