2011-05-17 82 views
0

任何人都看着這個簡單的代碼(?)並告訴我什麼是錯的? 我是一個完整的初學者到android開發,我不明白爲什麼我的應用程序甚至沒有啓動。我得到一個意外的錯誤..:( 這就是:AVD中的Android執行錯誤

package applicationTest.ppr.com; 

import android.app.Activity; 
import android.os.Bundle; 
import android.widget.LinearLayout; 
public class MainClass extends Activity { 
    /** Called when the activity is first created. */ 

    /*Global vars*/ 
    public static LinearLayout lila; 

    @Override 
    public void onCreate(Bundle savedInstanceState) {  
     super.onCreate(savedInstanceState); 
     lila = (LinearLayout) findViewById(R.id.lilay); 
     setContentView(lila); 
    } 

    public void Shortoast(){new Game(this);} 

    public static LinearLayout returnLayout(){return lila;} 


} 

程序甚至不啓動,我認爲它可能有一些做我如何處理的LinearLayout和的setContentView();

反正非常感謝提前

+0

你有佈局xml文件,它定義你的R.id.lilay?嘗試使用:setContentView(R.Layout.yourlayout) – 2011-05-17 23:17:00

+0

在Eclipse中使用'adb logcat',DDMS或DDMS透視圖來檢查LogCat並查看與您的錯誤相關的堆棧跟蹤。 – CommonsWare 2011-05-17 23:40:04

+0

是的,我在我的main.xml中,雖然我嘗試這種方法的主要原因是因爲我想從另一個類更新一些文本到屏幕。這就是我創建returnLayout方法的原因。所以我可以做一些像MainClass.returnLayout()。setView(texView) – Fred 2011-05-17 23:41:18

回答

0

建議:保持儘可能簡單,直到你解決這個問題 然後你就可以專注於業務邏輯

package applicationTest.ppr.com; 

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

public class MainClass extends Activity { 
    /** Called when the activity is first created. */ 

    @Override 
    public void onCreate(Bundle savedInstanceState) {  
     super.onCreate(savedInstanceState); 
     setContentView(R.id.lilay); 
    } 

} 

另外,您的主要活動是在Android清單中映射的嗎?

<application android:icon="@drawable/icon" android:label="@string/app_name"> 

    <activity android:name="MainClass" 
       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> 

</activity> 

- 編輯 - 你有lilay.xml文件在你的RES /佈局文件夾?

+0

lilay是我的linearlayout ID,如果它是一個xml文件不應該是R.layout.NAME.xml? – Fred 2011-05-18 20:30:25

+0

嗯..我只是想通了,我沒有正確使用linearlayout ... 我的目標是在屏幕上有一些文字。還有一個按鈕。當按下butotn時,該文本被更改,而不會創建新對象... – Fred 2011-05-18 20:39:23

+0

是的,羅傑。當然,莉莉是線性佈局ID – 2011-05-19 08:12:15