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 ;
高手指点下...
解决方案 »
- 有没有什么软件可以让手机模仿Android模拟器效果?
- android 怎么连接服务器,求各位大神搭救
- 找了个兼职,别人想看我的代码规范,要求发一段代码,求解
- frameLayout后边的按钮及文本框都不显示?为什么呢?
- android 错误2
- youtube中采用json解析如何得到视频的所有评语?
- 如果我有个anroid手机,我能不能在上面安装一些软件,在手机上写程序
- android直接获取到webservices服务器上传过来的图片字节流文件,改怎么去转成图片呢
- android 画图(循环,重绘)
- service总是不能初始化,注释掉一部分程序后可以初始化,怎么回事?求解释。
- 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还真被你误导了