本文介绍了Androidruntime致命异常主要的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好:当我尝试运行我的应用程序时,我得到一个致命的异常主,请任何人都可以给我一些额外的帮助。我真的想学习如何编写应用程序。我是自己教的。谢谢你好吗


Hello everyone: When I try to run my app I get an fatal exception main , please can anyone give me some extra help. I really want to learn how to write apps. I'm teaching it by myself. Thhank u

package com.c.alc;

import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class AcActivity extends Activity {
	
	int counter;
	Button add, sub;
	TextView display;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ac);
		
		counter= 0;
		add= (Button) findViewById(R.id.suma);
		sub= (Button) findViewById(R.id.resta);
		display=(TextView) findViewById(R.id.textView1);
		
		
		add.setOnClickListener(new View.OnClickListener() {
	
			@Override
			public void onClick(View v) {
				counter++;
				display.setText("Your Total is: " + counter);

			}
		});
		
		
		sub.setOnClickListener(new View.OnClickListener() {
			
			
			@Override
			public void onClick(View v) {
				counter--;
				display.setText("Your Tatal is: " + counter);

			}
		});
		
	}
}





XML代码



XML code

<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:gravity="top"

    android:paddingBottom="@dimen/activity_vertical_margin"

    android:paddingLeft="@dimen/activity_horizontal_margin"

    android:paddingRight="@dimen/activity_horizontal_margin"

    android:paddingTop="@dimen/activity_vertical_margin"

    tools:context=".AcActivity" >

    <textview

        android:id="@+id/textView1"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_alignParentLeft="true"

        android:layout_alignParentTop="true"

        android:layout_marginLeft="17dp"

        android:layout_marginTop="16dp"

        android:text="@string/hello_world" />

    <Button

        android:id="@+id/suma"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_below="@+id/textView1"

        android:layout_marginLeft="61dp"

        android:layout_marginTop="65dp"

        android:layout_toRightOf="@+id/resta"

        android:text="Suma" />

    <Button

        android:id="@+id/resta"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_alignBaseline="@+id/suma"

        android:layout_alignBottom="@+id/suma"

        android:layout_alignLeft="@+id/textView1"

        android:layout_marginLeft="25dp"

        android:text="Resta" />

</relativelayout>

推荐答案


这篇关于Androidruntime致命异常主要的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 01:35