- Java code
package com.china.hello;import android.app.Activity;import android.os.Bundle;import android.widget.TextView;publicclass HelloChina extends Activity {/**Calledwhentheactivityisfirstcreated.*/@Overridepublicvoid onCreate(Bundle saveInstanceState) {super.onCreate(saveInstanceState);//setContentView(R.layout.main);TextView tv = new TextView(this);tv.setText("helloWorld");setContentView(tv);}}
下载的是android2.2;
运行后出现一个手机界面不过说:The application has stopped unexpectedly, please try again ;
高手指点下...
------解决方案--------------------
从这看来,程序没什么错。如果报错的话,看下错误日志报的什么错。
我估计你的清单文件有错(AndroidManifest.xml);
activity的中的android:name=""参数 是不是不是HelloChina 。
------解决方案--------------------
明显错了,你的activity叫HelloChina,manifest里面写成HelloWorldActivity了
------解决方案--------------------
------解决方案--------------------
2楼说的没错,修改过来运行一下,试试。
------解决方案--------------------
是这段代码出错了:
TextView tv = new TextView(this);
tv.setText("helloWorld");
setContentView(tv);
setContentView的参数只能是View类型,而tv是View下的控件,不能直接用,需要修改一下:
TextView tv = new TextView(this);
tv.setText("helloWorld");
tv.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
LinearLayout linearlayout = new LinearLayout(this)
linearlayout.addView(tv);
setContentView(linearlayout);
------解决方案--------------------
6楼应该没有问题的吧!在清单文件错了android:name=".HelloWorldActivity",要和你的java 类名一致
------解决方案--------------------
能放父类的地方就能放子类。