【发布时间】:2010-11-11 18:46:59
【问题描述】:
我正在尝试创建一个应用程序,当我单击第一个布局中的按钮时,它将从 EditText 中提取文本并将该值从第二个布局中放入 TextView 中。但是,似乎应用程序会因为 TextView 的 setText 而崩溃。
我没有放 logCat,因为它并不能说明太多。我相信错误来自 setText 部分。但是我不知道如何修复该部分,或者我的编码方式可能是错误的。希望有人能帮助我。提前致谢。
<TextView android:id="@+id/showtitle"
android:layout_marginTop="1dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp"
android:textStyle="bold" />
<TextView android:id="@+id/showtemplate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/showtitle"
android:layout_alignLeft="@+id/showtitle"
android:paddingBottom="4dip"
android:includeFontPadding="false"
android:textSize="15sp"
android:textStyle="normal" />
下面是我的java代码:
导入android.os.Bundle; 导入android.view.View; 导入 android.widget.TextView; 导入 android.widget.EditText; 导入android.widget.Button; 导入android.widget.Toast;
import android.app.Activity;
public class AndroidGroupSMS extends Activity{
private EditText title;
private EditText template;
private Button btnsave;
private Button btnload;
private TextView text,text2;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
title = (EditText) findViewById(R.id.title);
template = (EditText) findViewById(R.id.template);
btnsave = (Button) findViewById(R.id.save);
btnload = (Button) findViewById(R.id.load);
text = (TextView) findViewById(R.id.showtitle);
text2 = (TextView) findViewById(R.id.showtemplate);
btnsave.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
String sTitle = title.getText().toString();
String sTemplate = template.getText().toString();
if(sTitle.length() > 0 && sTemplate.length() > 0)
{
//this is where i'm setting the text extracted from the edittext boxes
text.setText(sTitle.toString());
text2.setText(sTemplate.toString());
}
else
Toast.makeText(getBaseContext(),"Please enter the title and template" + "", Toast.LENGTH_SHORT).show();
}
});
}
我不知道怎么读。 以下是我要求的 logCat: 11-12 04:32:51.652: 调试/AndroidRuntime(283): >>>>>>>>>>>>>> AndroidRuntime START >>>>>>>>>>>>> AndroidRuntime START
【问题讨论】:
-
@Joel Seah:您可以发布您的 logcat 消息,或者只是突出显示哪一行出现错误以及您在 logcat 中遇到了什么错误?
-
这样的话,恐怕如果 logCat 没有告诉你太多,那是你没看清楚。
-
我的疯狂猜测是,当你尝试使用它时,某处的某些东西是空的,logcat 会告诉你和我们更多:)
-
至少,我们真的需要来自 logcat 的堆栈跟踪,如果可能的话,还需要相应的布局 XML 文件。
-
@Tilsan The Fighter:我发布了 logCat,但我不知道它为什么如此混乱。 @Blumer & psicho:我不知道如何阅读 logCat。 @Alexander Lucas:我尝试发布我的主要布局,但它只显示几行。我只能以如此清晰的方式发布我的第二个布局。
标签: android