Eclipse Android - 调试器不会在OnClick方法的断点处停止

时间:2023-01-12 21:13:14

I want to debug my onClick method in my SaveActivity:

我想在SaveActivity中调试我的onClick方法:

public class SaveActivity extends Activity {

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

    getActionBar().setDisplayHomeAsUpEnabled(true);
}

// For the Back Button
// (http://developer.android.com/training/implementing-navigation/ancestral.html)
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        // This is called when the Home (Up) button is pressed
        // in the Action Bar.
        Intent parentActivityIntent = new Intent(this, MainActivity.class);
        parentActivityIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
                | Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(parentActivityIntent);
        finish();
        return true;
    }
    return super.onOptionsItemSelected(item);
}

public void onClick(View view) {

    switch (view.getId()) {   // <-- On this line is my Breakpoint
    case R.id.location_save:

        EditText formName = (EditText) findViewById(R.id.location_name);
        String locationName = formName.getText().toString();
        EditText formDesc = (EditText) findViewById(R.id.location_desc);
        String locationDesc = formDesc.getText().toString();
        // Example for New York
        String locationLatitude = "40.714353";
        String locationLongitude = "-74.005973";

        DatabaseHandler db = new DatabaseHandler(this);
        Location newLocation = new Location(locationName, locationDesc,
                locationLatitude, locationLongitude);
        db.addLocation(newLocation);
        Intent myIntent = new Intent(SaveActivity.this, DetailActivity.class);
        myIntent.putExtra("id", newLocation.getId()); 
        SaveActivity.this.startActivity(myIntent);

    }
}

}

}

Now i added a Breakpoint on the switch-Statemant in the onClick method. Then i click on this Button in my activity_save.xml:

现在我在onClick方法的switch-Statemant上添加了一个Breakpoint。然后我点击我的activity_save.xml中的这个按钮:

<Button
   android:id="@+id/location_save"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:text="@string/location_save" >
</Button>

So it should stop at my breakpoint, but nothing happend.
What did i wrong?

所以它应该停在我的断点处,但没有任何事情发生。我错了什么?

1 个解决方案

#1


2  

Add this in your button layout to bind the method to its onClick:

在按钮布局中添加此项以将方法绑定到其onClick:

android:onClick="onClick"

#1


2  

Add this in your button layout to bind the method to its onClick:

在按钮布局中添加此项以将方法绑定到其onClick:

android:onClick="onClick"