2011-05-17 85 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