无法解析符号InstagramApp

时间:2015-09-29 05:10:04

标签: java android instagram android-sharing

我正在开发一个允许通过Instagram共享内容的应用程序。我的编码有错误。我不能将instagramApp导入我的编码。它说不能解析符号instagramApp.Can有人指导我解决这个问题。编码和错误日志如下。

MainActivity.java

package com.example.dothis.instagram;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.example.dothis.instagram.InstagramApp;
import    com.example.dothis.instagram.InstagramApp.OAuthAuthenticationListener;

public class MainActivity extends Activity {

private InstagramApp mApp;
private Button btnConnect;
private TextView tvSummary;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    mApp = new InstagramApp(this, ApplicationData.CLIENT_ID,
            ApplicationData.CLIENT_SECRET, ApplicationData.CALLBACK_URL);
    mApp.setListener(listener);

    tvSummary = (TextView) findViewById(R.id.tvSummary);

    btnConnect = (Button) findViewById(R.id.btnConnect);
    btnConnect.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View view) {
            if (mApp.hasAccessToken()) {
                final AlertDialog.Builder builder = new AlertDialog.Builder(
                        MainActivity.this);
                builder.setMessage("Disconnect from Instagram?")
                        .setCancelable(false)
                        .setPositiveButton("Yes",
                                new DialogInterface.OnClickListener() {
                                    public void onClick(
                                            DialogInterface dialog, int id) {
                                        mApp.resetAccessToken();
                                        btnConnect.setText("Connect");
                                        tvSummary.setText("Not connected");
                                    }
                                })
                        .setNegativeButton("No",
                                new DialogInterface.OnClickListener() {
                                    public void onClick(
                                            DialogInterface dialog, int id) {
                                        dialog.cancel();
                                    }
                                });
                final AlertDialog alert = builder.create();
                alert.show();
            } else {
                mApp.authorize();
            }
        }
    });

    if (mApp.hasAccessToken()) {
        tvSummary.setText("Connected as " + mApp.getUserName());
        btnConnect.setText("Disconnect");
    }

}

OAuthAuthenticationListener listener = new OAuthAuthenticationListener() {

    @Override
    public void onSuccess() {
        tvSummary.setText("Connected as " + mApp.getUserName());
        btnConnect.setText("Disconnect");
    }

    @Override
    public void onFail(String error) {
        Toast.makeText(MainActivity.this, error,   Toast.LENGTH_SHORT).show();
    }
};
}

错误日志:

Information:Gradle tasks [:app:assembleDebug]
:app:preBuild
:app:compileDebugNdk
:app:preDebugBuild
:app:checkDebugManifest
:app:preReleaseBuild
:app:prepareComAndroidSupportAppcompatV72103Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42103Library UP-TO-DATE
:app:prepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE
:app:mergeDebugResources UP-TO-DATE
:app:processDebugManifest UP-TO-DATE
:app:processDebugResources UP-TO-DATE
:app:generateDebugSources UP-TO-DATE
:app:compileDebugJava
/Users/marian/AndroidStudioProjects/Instagram/app/src/main/java/com/example/dothis/instagram/MainActivity.java
Error:(13, 36) error: cannot find symbol class InstagramApp
Error:(14, 49) error: package com.example.dothis.instagram.InstagramApp does not exist
Error:(18, 13) error: cannot find symbol class InstagramApp
Error:(74, 5) error: cannot find symbol class OAuthAuthenticationListener
Error:(25, 32) error: cannot find symbol variable main
Error:(27, 20) error: cannot find symbol class InstagramApp
Error:(74, 48) error: cannot find symbol class OAuthAuthenticationListener
Error:Execution failed for task ':app:compileDebugJava'.
> Compilation failed; see the compiler error output for details.
Information:BUILD FAILED
Information:Total time: 3.909 secs
Information:8 errors
Information:0 warnings
Information:See complete output in console

任何解决此问题的建议和指导都会非常有帮助。谢谢。

1 个答案:

答案 0 :(得分:1)

这一行:

error: package com.example.dothis.instagram.InstagramApp does not exist Error:(18, 13)

告诉您使用的套餐不存在。因此,该路径上没有文件。您应该将InstagramApp java文件放在该路径上,或将包名称更改为正确的路径。

TL; DR:您正在尝试导入这两个文件:

import com.example.dothis.instagram.InstagramApp;
import com.example.dothis.instagram.InstagramApp.OAuthAuthenticationListener;

但他们并没有走上你提供的道路。您必须将InstagramApp.java文件放在instagram文件夹下才能导入。

编辑:您可以阅读有关java import的{​​{3}},了解您的代码有什么问题。您还可以阅读有关包裹的this related question

第二次修改:您需要在项目下放置this tutorial才能使导入生效。您无法在不获取所需文件的情况下复制并粘贴示例。您错过了一个,这就是您收到错误的原因。