1

我对所有这些编码的东西都非常陌生,而且我自己已经走了很远,但我似乎无法弄清楚这个错误。感谢所有帮助。

“范围内无法访问 DonationsActivity 类型的封闭实例”

package com.ganttbros.shadowui;

import org.donations.DonationsActivity;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.content.Intent;

public class DonateActivity extends Activity {

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

final Button donate = (Button) findViewById(R.id.donatebutton);
    donate.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) 
                {
                    startActivity(new Intent(DonationsActivity.this, DonationsActivity.class));
                }
            });
        }

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

 }

我应该告诉你我正在尝试实现这个库:https ://github.com/dschuermann/android-donations-lib#readme 我已经设置了按钮,但我只需要让它启动“DonationsActivity”按下时。

4

2 回答 2

3

采用

startActivity(new Intent(DonateActivity.this, DonationsActivity.class));

或者

startActivity(new Intent(v.getContext(), DonationsActivity.class));

代替

startActivity(new Intent(DonationsActivity.this, DonationsActivity.class));

用于从DonationsActivityActivity启动DonateActivityActivity

于 2013-02-21T06:04:52.747 回答
1

改变这个:

startActivity(new Intent(DonationsActivity.this, DonationsActivity.class));

到:

startActivity(new Intent(DonateActivity.this, DonationsActivity.class));
于 2013-02-21T06:05:48.467 回答