无法初始化Parse SDK Test

时间:2015-12-28 20:30:48

标签: java android android-studio parse-platform android-studio-2.0

当我尝试运行应用以测试我的SDK是否已安装时,我

错误:(35,22)错误:找不到合适的初始化方法(,String,String) 方法Parse.initialize(Context,String,String)不适用 (实际参数不能通过方法调用转换转换为Context) 方法Parse.initialize(Context)不适用 (实际和正式的参数列表长度不同)

我按照所有说明进行了检查,并检查了许多有关如何操作的教程,但仍然出现此错误。

源代码:

package com.dusanp.passer;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;

import com.parse.Parse;
import com.parse.ParseObject;


public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();

            Parse.initialize(this, "zHpYwtZUDEHFuDULv2Vwt9rR0fie7fANFx7s24hT", "trnAIEthNLKkT6ueBP0ATYZh6pYhbpXFTN2gsSbP");

            ParseObject testObject = new ParseObject("TestObject");
            testObject.put("foo", "bar");
            testObject.saveInBackground();

        }
    });
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, 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();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}

}

1 个答案:

答案 0 :(得分:0)

你的问题就在这一行

Parse.initialize(this, "zHpYwtZUDEHFuDULv2Vwt9rR0fie7fANFx7s24hT", "trnAIEthNLKkT6ueBP0ATYZh6pYhbpXFTN2gsSbP");

在onClickListener this内部是指单击侦听器,而不是Pase sdk期望该参数的Context。 如果您的活动名称是MainActivity,那么该行将如下所示。

Parse.initialize(MainActivity.this, "zHpYwtZUDEHFuDULv2Vwt9rR0fie7fANFx7s24hT", "trnAIEthNLKkT6ueBP0ATYZh6pYhbpXFTN2gsSbP");