2013-03-27 73 views
-4

我是新的android应用程序开发...我所做的是创建一个应用程序,添加一个计数器文本添加按钮被点击和子文本subb按钮是点击。请指出我的错误线程退出与未捕获的异常(组= 0x4001d800)

startingpoint.java`

package vignesh.pandian.app; 

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

import android.view.View; 
import android.widget.Button; 
import android.widget.TextView; 

public class Startingpoint extends Activity { 

    int counter; 
    Button add, subb; 
    TextView displ; 


    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_startingpoint); 
     counter=0; 
     add = (Button) findViewById(R.id.add); 
     subb =(Button) findViewById(R.id.bSub); 
     displ =(Button) findViewById(R.id.tex); 

add.setOnClickListener(new View.OnClickListener() { 

      public void onClick(View v) { 
       // TODO Auto-generated method stub 
       counter++; 
       displ.setText("value is "+counter); 

      } 
     }); 
     subb.setOnClickListener(new View.OnClickListener() { 

      public void onClick(View v) { 
       // TODO Auto-generated method stub 
       counter--; 
       displ.setText("value is"+counter); 

      } 
     });   


    } 

} 

activity_startingpoint.xml

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

    <Button 
     android:id="@+id/add" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_centerVertical="true" 
     android:text="Add one " /> 

    <TextView 
     android:id="@+id/My" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentRight="true" 
     android:layout_marginBottom="15dp" 
     android:text="Vignesh&apos;s app !!!!" 
     tools:context=".Startingpoint" /> 

    <TextView 
     android:id="@+id/tex" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_marginTop="35dp" 
     android:text="Value is" 
     android:textSize="35dp" 
     tools:context=".Startingpoint" /> 

    <Button 
     android:id="@+id/bSub" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_below="@+id/add" 
     android:layout_marginTop="37dp" 
     android:text="Subract one " /> 


</RelativeLayout> 
+2

请给我们例外的完整堆栈跟踪 – 2013-03-27 06:04:38

+0

发布您的logcat – 2013-03-27 06:06:05

+0

您的问题解决了吗? – rajeshwaran 2013-03-27 06:44:49

回答

2

TextView的显示终端;

displ =(Button)findViewById(R.id.tex);

这是不对的,使用此

displ =(TextView) findViewById(R.id.tex); 

DISP1是TextView的对象,而不是按钮对象。

相关问题