Java 基本Android Eclipse开发错误

Java 基本Android Eclipse开发错误,java,android,Java,Android,(已解决)感谢NetCat:这是一个UI XML问题:) 今天,我已经开始了Android开发,我正在使用一台带有Eclipse和Android SDK的Mac电脑,所有这些都在运行(我已经成功地运行了一些“Hello World”类型的应用程序),对于Android设备,我正在使用我的新HTC 因此,下面的代码应该可以工作,当我在手机上运行它时,它们的“无错误”是调试器,但每次在它加载之前,手机都会弹出一条消息,说“应用程序计数(process com.Count)意外停止。请再试一次。” 我

(已解决)感谢NetCat:这是一个UI XML问题:)

今天,我已经开始了Android开发,我正在使用一台带有Eclipse和Android SDK的Mac电脑,所有这些都在运行(我已经成功地运行了一些“Hello World”类型的应用程序),对于Android设备,我正在使用我的新HTC

因此,下面的代码应该可以工作,当我在手机上运行它时,它们的“无错误”是调试器,但每次在它加载之前,手机都会弹出一条消息,说“应用程序计数(process com.Count)意外停止。请再试一次。”

我已经用不同的SDK版本1.5和2.2多次重新创建了该项目,但仍然没有成功

代码来自我成功完成的另一个教程,但我已经更改了一些变量,使应用程序略有不同。你能告诉我以下代码有什么问题吗

package com.count;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class count extends Activity implements OnClickListener {


//Declare widgets
Button btnSave, btnUp, btnDown;
TextView lblCurrentCount, lblCountCard;

//Declare variables
int intCount=0;
int intCardCount=0;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    //Sets up the link between java and the XML widgets
    btnSave = (Button)findViewById(R.id.btnSave);
    btnUp = (Button)findViewById(R.id.btnUp);
    btnDown = (Button)findViewById(R.id.btnDown);
    lblCurrentCount = (TextView)findViewById(R.id.lblCurrentCount);
    lblCountCard = (TextView)findViewById(R.id.lblCountCard);

    //Initialize widgets
    lblCurrentCount.setText(String.valueOf(intCount));
    lblCountCard.setText("");

    //Define button listeners
    btnSave.setOnClickListener(this);
    btnUp.setOnClickListener(this);
    btnDown.setOnClickListener(this);

}

//When any button is clicked
@Override
public void onClick(View src) {

    //Actions when buttons are clicked
    switch(src.getId()) {
    case R.id.btnSave:
        lblCountCard.append("\n#" + intCardCount + " " + intCount);
        intCardCount++;
        intCount=0;
        lblCountCard.setText(String.valueOf(intCount));
        break;
    case R.id.btnUp:
        intCount++;
        lblCountCard.setText(String.valueOf(intCount));
        break;
    case R.id.btnDown:
        intCount--;
        lblCountCard.setText(String.valueOf(intCount));
        break;
    }

}
}
谢谢你,戴夫

您必须提供一个版面宽度 属性


可能就是这样。你有一个布局元素没有一个布局宽度(如果你犯了和我一样的错误,可能还有一个布局高度)属性。找到它,添加属性,然后看看接下来会发生什么。

请给出堆栈跟踪?您可以在eclipse的DDMS选项卡中找到这一点。单击它并转到Logcat,单击红色的e按钮并发布所有内容,这将有助于使用诊断您的错误。就是这样,在第一个家伙提到netcat后,我发现了它:)不知道那一个!