开发者

Error on running Android Emulator

开发者 https://www.devze.com 2023-04-12 06:53 出处:网络
This is my first Android application which I am learning using this series and I get an error when I run the emulator.

This is my first Android application which I am learning using this series and I get an error when I run the emulator.

Here's the program:

package com.thenewboston.android.sarabjeet;

import android.app.Activity;
import android开发者_高级运维.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

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

    int counter;
    Button add, sub;
    TextView display;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        counter = 0;
        add = (Button) findViewById(R.id.bAdd);
        sub = (Button) findViewById(R.id.bSubtract);
        display = (TextView) findViewById(R.id.tvDisplay);
        add.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub
                counter++;
                display.setText("Your total is " + counter);
            }
        });
        sub.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub
                counter--;
                display.setText("Your total is " + counter);
            }
        });
    }
}

And here's the run-time information and the error:

[2011-10-12 18:16:57 - sarabjeet] Android Launch!
[2011-10-12 18:16:57 - sarabjeet] adb is running normally.
[2011-10-12 18:16:57 - sarabjeet] Performing com.thenewboston.android.sarabjeet.MainActivity activity launch
[2011-10-12 18:16:57 - sarabjeet] Automatic Target Mode: Preferred AVD 'Sarabjeets_Phone' is available on emulator 'emulator-5554'
[2011-10-12 18:17:00 - sarabjeet] Application already deployed. No need to reinstall.
[2011-10-12 18:17:00 - sarabjeet] Starting activity com.thenewboston.android.sarabjeet.MainActivity on device emulator-5554
[2011-10-12 18:17:02 - sarabjeet] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.thenewboston.android.sarabjeet/.MainActivity }
[2011-10-12 18:17:02 - sarabjeet] **ActivityManager: Warning: Activity not started, its current task has been brought to the front**

I am totally new to Android programming and running the Emulator. What might be wrong here that I don't see the emulator as I should?

Thanks a lot.


That's not an error. The tools just saw that nothing changed in your program, so they didn't recompile your application into a new APK. They launched the already installed one on the emulator instead.

Sometimes the tools miss that you changed a resource (e.g. an image file inside the /res folder), in this case you can clean your project to force a regeneration. Use Project -> Clean .. inside eclipse for that.


Warning: Activity not started, its current task has been brought to the front

this is because already your application run in simulator press back button and again run and try OR go to setting first delete application and reinstall.


Check the com.thenewboston.android.sarabjeet Ensure that its in your manifest file may be something like this...

<activity android:name="sarabjeet.MainActivity"></activity>

Or whatever your package is called :)

If all else fails, then delete the app from your simulator, then close down the emulator

press project > clean > clean all projects

Then load up the simulator again, all will be good

Looks like it may be that!

Post me your android manifest bit too :)

0

精彩评论

暂无评论...
验证码 换一张
取 消