专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > Android

startActivity时出错解决办法

发布时间:2010-05-30 10:53:57 文章来源:www.iduyao.cn 采编人员:星星草
startActivity时出错
今天做android开发一个小项目怎么都调不通,然后就随便建了个测试用例,发现startActivity函数竟然总是出错,我已经在AndroidManifest.xml 对新建的页面进行的注册了,但是依然不行不知道是什么原因,现在贴出来代码请大家指教!
Activity01代码

package An.Android;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class TestA extends Activity {
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
   
  Button to_anoter = (Button) findViewById(R.id.button1); //测试打开新的activity
  to_anoter.setOnClickListener(new OnClickListener()
  {
  public void onClick(View v) 
  {
  // TODO Auto-generated method stub

  Intent intent0 = new Intent(TestA.this,anotherActivity.class);  
  setTitle("test");  
  startActivity(intent0);  
  TestA.this.finish();
  //CityWeather.this.finish();
  }
 
  });
  }
   
   
}

对应的mian.xml文件如下

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  >
   
<TextView  
  android:layout_width="fill_parent" 
  android:layout_height="wrap_content" 
  android:text="@string/hello"
  />
<Button android:text="试试" android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
</LinearLayout>

Activity02的代码如下:

package An.Android;

import android.app.Activity;
import android.os.Bundle;

public class anotherActivity extends Activity{
/** Called when the activity is first created. */
  @Override
   
  public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.another);
  };

}
对应的xml文件如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  >
   
<TextView  
  android:layout_width="fill_parent" 
  android:layout_height="wrap_content" 
  android:text="你好啊!"
  />

</LinearLayout>

AndroidManifest.xml 对应如下:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="An.Android"
  android:versionCode="1"
  android:versionName="1.0">


  <application android:icon="@drawable/icon" android:label="@string/app_name">
  <activity android:name=".TestA"
  android:label="@string/app_name">
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: