2 u014594295 u014594295 于 2014.04.07 21:29 提问

为Button添加监听时报错

package com.example.jisuanji;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBarActivity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class Activity03 extends ActionBarActivity {
private EditText biaogeone = null;
private EditText biaogetwo = null;
private TextView wenzi = null;
private Button anjian = null;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_activity03);

    if (savedInstanceState == null) {
        getSupportFragmentManager().beginTransaction()
                .add(R.id.container, new PlaceholderFragment()).commit();
    }
    biaogeone = (EditText) findViewById(R.id.biaogeone);
    biaogetwo = (EditText) findViewById(R.id.biaogetwo);
    wenzi = (TextView) findViewById(R.id.wenzi);
    anjian = (Button) findViewById(R.id.anjian);

///////////////////////////////////////////////////////////////////
** anjian.setOnClickListener(new anjianlistener()); ** //////////////////////////////////////////////////////////////////

}

class anjianlistener implements OnClickListener {

    @Override
    public void onClick(View v) {
        String biaogeoneStr = biaogeone.getText().toString();
        String biaogetwoStr = biaogetwo.getText().toString();
        Intent intent = new Intent();
        intent.putExtra("one", biaogeoneStr);
        intent.putExtra("two", biaogetwoStr);
        intent.setClass(Activity03.this, resultactivity.class);
        Activity03.this.startActivity(intent);

    }

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {

    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.activity03, 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);
}

/**
 * A placeholder fragment containing a simple view.
 */
public static class PlaceholderFragment extends Fragment {

    public PlaceholderFragment() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_activity03,
                container, false);
        return rootView;
    }
}

}

1个回答

mimixi666
mimixi666   2014.04.08 16:26

错误日志log呢??
提示什么样的错?

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!