package com.china.hello;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public
class HelloChina extends Activity {/**
Called
when
the
activity
is
first
created.
*/@Overridepublic
void 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 ;
高手指点下...
解决方案 »
- 为什么设置了layout_gravity="right",按钮不会到右边?
- 求Eclipse插件能对SqliteDatabase进行操作的?
- 关于安装Android遇到的问题?
- 关于surfaceview的一些问题
- Service not registered
- 崩溃中!!!intent-filter接不到我发的intent!!!!
- android 自定义发送彩信的问题
- linphone_android编译出的库怎么在自己的程序中调用
- android jni初学者纠结问题,急急急!!!!!
- Android socket 编程 客户端接收的数据数据无法更新到UI上,只有当客户端与服务器断开连接时才能更新到UI上
- help.... 有谁知道怎样取消控件绑定的Listener?
- 决定走Android...纠结了好久
我估计你的清单文件有错(AndroidManifest.xml);
activity的中的android:name=""参数 是不是不是HelloChina 。
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.china.hello"
android:versionCode="1"
android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" /> <application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".HelloWorldActivity"
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></manifest>没错吧
有错。。你看这一句:
android:name=".HelloWorldActivity"
它说明你要运行的Activity的名字应该是HelloWorldActivity。。你看你的程序里面那个Activity的名字是HelloChina。。程序运行的时候,它根据HelloWorldActivity这个名字来找,当然会找不到,就要报错,应该要报什么classNotFound的异常。
你把名字改一下,随便你改程序里的还是清单文件的,一样就行。
Ps:以后你写程序,每自己写了一个Activity,都需要在清单文件里面注册。
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);
TextView不是继承View?又是java不学好跑来弄android的。。lz还真被你误导了