unfortunately has stopped

《煮酒论Android》第五章,由Button启动TextView完整程序:

text.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
   
    <TextView
        android:id="@+id/text_view"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textSize="16sp"
        android:textColor="#ffffff"
        android:padding="10dp"
        android:background="#cc0000"
        android:text="这是一个TextView, 这段文字来源于txet.xml布局文件。"/>

</LinearLayout>

ViewTextActivity.java:

package com.example.chapter05;

import android.app.Activity;

import android.os.Bundle;
import android.widget.TextView;

public class ViewTextActivity extends Activity {

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
       
        setTitle("ViewTextActivity");
        setContentView(R.layout.text);
        findAndModifyTextView();
    }
   
    private void findAndModifyTextView(){
     
     TextView textView = (TextView)findViewById(R.id.text_view);
     CharSequence textViewOld = textView.getText();
     textView.setText("Text.xml文件里配置的文字是:"
        + textViewOld
        +"\n 在此我们动态修改为:textView的值也是可以动态修改的。");
    }
}

main.xml:

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

MainActivity.java

package com.example.chapter05;

import android.app.Activity;

import android.os.Bundle;
import android.widget.Button;
import android.view.View;
import android.content.Intent;

public class MainActivity extends Activity {

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
       
        setTitle("ViewTextActivity");
        setContentView(R.layout.main);
        Button textViewButton = (Button)findViewById(R.id.text_view_button);
        textViewButton.setOnClickListener(mTextViewButtonListener);
    }
   
    private Button.OnClickListener mTextViewButtonListener = new Button.OnClickListener(){
     public void onClick(View v){
      Intent intent = new Intent (MainActivity.this, ViewTextActivity.class);
      startActivity(intent);
     }
     
    };
}

AndroidMainifest.xml:

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

<uses-sdk
        android:minSdkVersion="19"
        android:targetSdkVersion="19" />

<application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name">
           
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
       
        <activity
            android:name=".ViewTextActivity"
            android:label="@string/app_name">
        </activity>
       
    </application>

</manifest>

注意:

(1)android:id="@+id/text_view_button"中"@+id/text_view_button"里不能有空格;

(2)两个Activity都需要在Mainifest.xml中声明;

时间: 2024-10-12 16:06:07

unfortunately has stopped的相关文章

java.lang.IllegalStateException: Illegal access: this web application instance has been stopped already.

java.lang.IllegalStateException: Illegal access: this web application instance has been stopped already. Could not load [META-INF/services/javax.xml.bind.JAXBContext]. 解决方法:先将项目remove,然后停止服务器,到应用程序目录下将部署的应用删除,然后启动服务器,重新部署就ok了 原因:暂不明确,可能是修改后有原来的残留物.

the process android.process.acore has stopped或the process com.phone。。。。

模拟器一启动 The process android.process.acore has stopped unexpectedly 今天不知道怎么回事,模拟器一启动就狂报错, 模拟器已经重新安装过了,刚开始是脸界面都进不了, 后来进去了 launcher,报了The process android.process.acore has stopped unexpectedly这个错. 后来我试着重建模拟器的时候起了一个我以前从来不用的名字,OK了. 估计是我以前的模拟器有程序把系统搞crash了,

项目跑起来之后,一会儿后台就会报错Illegal access: this web application instance has been stopped already. Could not load [com.mchange.v2.resourcepool.BasicResourcePool$1DestroyResourceTask]. The following stack trace

一月 24, 2016 6:42:54 下午 org.apache.catalina.loader.WebappClassLoaderBase checkStateForResourceLoading 信息: Illegal access: this web application instance has been stopped already. Could not load [com.mchange.v2.resourcepool.BasicResourcePool$1DestroyRes

Android eclipse - aapt.exe has stopped working.

今天在修改Android的布局文件的时候,发现每保存一次,就提示: aapt.exe has stopped working(appt.exe已停止工作).很是郁闷,当时Android控制台已经提示错误了,我以为是当前写的代码没写完,就继续写,不理...报错在java代码过程很常见,可是也不至于崩溃哈.R.java文件都无法产生. 网上有很多人说的是错的,其实这多是xml这种资源文件错误引起的,有的人说属性值设置错误也会影响,而我遇到的错误是因为我将string.xml中的 action_set

registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped.

最近在用maven整合SSH做个人主页时候,在eclipse里面使用tomcat7插件发布项目是没有问题的,但当打包成war之后,使用tomcat7单独发布项目,就出现了以下的错误. 严重: Context [/wangxin] startup failed due to previous errors 八月 16, 2017 7:29:12 下午 org.apache.catalina.loader.WebappClassLoaderBase clearReferencesJdbc 严重: T

【Linux】Linux中 “there are stopped jobs”问题的解决方案

在用管理员执行一个命令后,我用Ctrl+Z把命令转移到了后台天.导致我无法退出root的. 输入命令:logout终端显示:There are stopped jobs. 解决方法:输入命令:jobs终端显示:[1]+ Stopped vim /etc/network/interfaces > /home/leo/Desktop/ip.txt (wd: /) 看了半天没有看到进程的PID,没有办法下手杀掉. 继续输入命令:jobs -l终端显示:[1]+ 4664 停止 vim /etc/net

Tomcat服务无法开启,点击stat不一会就变成stopped

前天在学习J2EE方面技术时,运行一个调试示例,需要用到Tomcat服务,结果使用Myeclipse怎么也打不开服务.之后去尝试手动打开Tmcat服务也无法成功,一直弄了好几个小时.后来,问了一下隔壁宿舍的同学,不一会问题就解决了~ 具体问题和相关解决方法如下(当然这个方法不一定适应所有Tomcat无法开启的问题哟): 首先,当时我按照网上手动开启Tomcat服务方法步骤: 一.在cmd中install service.bat,注册tomcat服务 图一:找到Tomcat中service.bat

registered the JBDC driver [oracle.jdbc.OracleDriver] but failed to unregister it when the web application was stopped. (转)

最近项目中遇见一问题,在开发环境没有问题的代码,到了生产环境就会报如下错误: 严重: A web application registered the JBDC driver [oracle.jdbc.OracleDriver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregiste

this web application instance has been stopped already

一台机器启动两个tomcat server.xml connector里面port换一个新端口,然后启动进程 启动不了,日志里面catalina.out里面总显示 Illegal access: this web application instance has been stopped already.  Could not load net.rubyeye.xmemcached.exception.UnknownCommandException.  The eventual followin

Android - Layout时发生&#39;Unfortunately xxx has stopped&#39;

概述 我在进行LinearLayout和TableLayout的嵌套布局的时候,发生题的错误.如下布局xml代码: 1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 android:layout_width="fill_parent" 3 android:layout_height="fill_parent" 4 android:orie