-1

我是 android 开发的新手,我尝试用 eclipse 运行我的第一个应用程序,但模拟器给了我一个错误:

应用程序 XXXXX(进程 com.ough.XXXXX)已意外停止。请再试一次。

我试图在网上寻找答案,但它似乎对我没有多大帮助。也许我把模拟器设置错了?还是我的代码不好?

我的模拟器设置为:4.0" WVGA,android 2.2 api level 8(我尝试了不同的东西,但它也不起作用..)

我的代码是:

int counter;
Button add;
Button sub;
TextView display;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    counter = 0;
    add = (Button) findViewById(R.id.bAdd);
    sub = (Button) findViewById(R.id.bSub);
    display = (TextView) findViewById(R.id.tvDisplay);

    add.setOnClickListener(new View.OnClickListener() {

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

    sub.setOnClickListener(new View.OnClickListener() {

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

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

我的 androidManifest.xml :

<?xml version="1.0" encoding="utf-8"?>

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.ough.thenewboston.MainActivity"
        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>

日志猫:

    03-19 13:31:19.014: E/Zygote(32): setreuid() failed. errno: 2
03-19 13:31:24.084: E/Zygote(32): setreuid() failed. errno: 17
03-19 13:31:24.844: E/BatteryService(58): usbOnlinePath not found
03-19 13:31:24.844: E/BatteryService(58): batteryVoltagePath not found
03-19 13:31:24.844: E/BatteryService(58): batteryTemperaturePath not found
03-19 13:31:24.854: E/SurfaceFlinger(58): Couldn't open /sys/power/wait_for_fb_sleep or /sys/power/wait_for_fb_wake
03-19 13:31:28.244: E/EventHub(58): could not get driver version for /dev/input/mouse0, Not a typewriter
03-19 13:31:28.244: E/EventHub(58): could not get driver version for /dev/input/mice, Not a typewriter
03-19 13:31:28.914: E/System(58): Failure starting core service
03-19 13:31:28.914: E/System(58): java.lang.SecurityException
03-19 13:31:28.914: E/System(58):   at android.os.BinderProxy.transact(Native Method)
03-19 13:31:28.914: E/System(58):   at android.os.ServiceManagerProxy.addService(ServiceManagerNative.java:146)
03-19 13:31:28.914: E/System(58):   at android.os.ServiceManager.addService(ServiceManager.java:72)
03-19 13:31:28.914: E/System(58):   at com.android.server.ServerThread.run(SystemServer.java:184)
03-19 13:31:29.334: E/SoundPool(58): error loading /system/media/audio/ui/Effect_Tick.ogg
03-19 13:31:29.334: E/SoundPool(58): error loading /system/media/audio/ui/KeypressStandard.ogg
03-19 13:31:29.334: E/SoundPool(58): error loading /system/media/audio/ui/KeypressSpacebar.ogg
03-19 13:31:29.334: E/SoundPool(58): error loading /system/media/audio/ui/KeypressDelete.ogg
03-19 13:31:29.334: E/SoundPool(58): error loading /system/media/audio/ui/KeypressReturn.ogg
03-19 13:31:30.024: E/ThrottleService(58): Could not open GPS configuration file /etc/gps.conf
03-19 13:31:30.464: E/logwrapper(131): executing /system/bin/tc failed: No such file or directory
03-19 13:31:30.504: E/logwrapper(133): executing /system/bin/tc failed: No such file or directory
03-19 13:31:30.574: E/logwrapper(136): executing /system/bin/tc failed: No such file or directory
03-19 13:31:35.136: E/HierarchicalStateMachine(58): TetherMaster - unhandledMessage: msg.what=3

另一件奇怪的事情是:每次我启动应用程序时它都会“锁定”。当我从锁定模式打开它时,它给了我“对不起..”错误行..

有什么想法吗 ?

4

1 回答 1

1

这不是一个直接的答案,因为您没有显示您的 logcat,而且我没有看到您的代码有任何明显错误,但希望它会有所帮助,而且评论太多了。如果不是,那我就删了。

如果它没有启动,那么使用您拥有的代码,您很可能null pointer exceptionmanifest.

逐步检查并检查这些行是否不是null

add = (Button) findViewById(R.id.bAdd);
sub = (Button) findViewById(R.id.bSub);
display = (TextView) findViewById(R.id.tvDisplay);

还要确保您声明了正确的menu layout.

如果您没有看到任何null值,那么问题可能出在您的manifest

日志猫

我很确定当它显示“设备已断开连接”时,您就在控制台选项卡中。您需要在 logcat 选项卡中。您可以选择第一行,按住 shift,然后选择最后一行,然后单击“保存”图标并保存日志,然后将其复制并粘贴到您的 OP 中。

于 2013-03-19T13:20:44.303 回答