愚柴 2016-10-28 12:07 采纳率: 37.5%
浏览 4819

安卓模拟器运行出现unfortunately,xxx has stoped是什么原因啊,小白刚学

activity_main.xml代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"

<TextView
    android:id="@+id/text_view"
    android:layout_width="match_parent"  
    android:layout_height="wrap_content"
    android:text="This is TextView" />
<Button
    android:id="@+id/button"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Button"/>
<EditText
    android:id="@+id/edit_text"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/button"
    android:layout_marginTop="14dp"
    android:ems="10"
    android:hint="Type something here" >
    <requestFocus />
</EditText>

MainActivity.java代码:

package com.example.class3;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends Activity {

private Button button;

private EditText editText;

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}

@Override

protected void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Button button = (Button) findViewById(R.id.button);
    editText=(EditText) findViewById(R.id.edit_text);
    button.setOnClickListener((OnClickListener) this);
}

public void onClick(View v){
    switch(v.getId()){
    case R.id.button:
        String inputText=editText.getText().toString();
        Toast.makeText(MainActivity.this,inputText,
                Toast.LENGTH_SHORT).show();
        break;
        default:
            break;
    }
}

}

  • 写回答

4条回答 默认 最新

  • 愚柴 2016-10-28 12:11
    关注

    感觉自己排版都好乱- -

    评论

报告相同问题?

悬赏问题

  • ¥15 用三极管设计—个共射极放大电路
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示