无法解析符号 InstagramApp
Cannot resolve symbol InstagramApp
我正在开发一个允许通过 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
解决此问题的任何建议和指导都会非常有帮助。谢谢。
这一行:
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
文件夹下才能导入。
编辑:您可以阅读this related question about java import
to understand what's wrong with your code. You could also read this tutorial关于包的内容。
第二次编辑: 您需要将 this file 放在您的项目下才能导入。您不能在没有获得所需文件的情况下简单地复制和粘贴示例。你漏了一个,这就是你收到错误的原因。
我正在开发一个允许通过 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
解决此问题的任何建议和指导都会非常有帮助。谢谢。
这一行:
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
文件夹下才能导入。
编辑:您可以阅读this related question about java import
to understand what's wrong with your code. You could also read this tutorial关于包的内容。
第二次编辑: 您需要将 this file 放在您的项目下才能导入。您不能在没有获得所需文件的情况下简单地复制和粘贴示例。你漏了一个,这就是你收到错误的原因。