我对所有这些编码工作都非常陌生,并且我已经走得很远了,但是我似乎无法弄清楚这个错误。感谢所有帮助。

“在作用域中无法访问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”。

最佳答案

采用

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


要么

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


代替

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


用于从DonationsActivity活动启动DonateActivity活动

关于java - 不能访问DonationsActivity类型的封闭实例,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14995597/

10-10 16:13