简体   繁体   中英

Android execution error in AVD

an anyone look at this simple code (?) and tell me what's wrong please? I'm a complete beginner to android development and I don't understand why my application doesn't even start. I get an unexpected error.. : ( Here it is:

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;}


}

The program doesn't even launch, and I think it might have something to do with how I handle the LinearLayout and setContentView();

anyway thanks very much in advance!

Suggestion: keep it as simple as possible until you fix the issue! Then you can concentrate on your business logic.

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);
    }

}

Also, is your main activity mapped in the Android manifest?

<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>

--EDIT-- Do you have the lilay.xml file in your res/layout folder?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM