我的项目运行良好(备份项目仍然没有产生此错误)但是当我为 Conact_Us 页面添加布局时,它产生了此错误。 (联系我们活动不会抛出任何错误) 以下是我的Gradle构建消息
信息:Gradle任务[:app:assembleDebug] 观察到的套餐ID'附加组件; addon-google_apis-google-23'在不一致的位置' C:\ Users \ DELL \ AppData \ Local \ Android \ Sdk \ add-ons \ addon-google_apis-google-23-1' (预期' C:\ Users \ DELL \ AppData \ Local \ Android \ Sdk \ add-ons \ addon-google_apis-google-23') 已经观察到包ID'附加组件; addon-google_apis-google-23'在&C; \ Users \ DELL \ AppData \ Local \ Android \ Sdk \ add-ons \ addon-google_apis-google-23'中。在' C:\ Users \ DELL \ AppData \ Local \ Android \ Sdk \ add-ons \ addon-google_apis-google-23-1'中删除重复内容 :app:preBuild UP-TO-DATE :app:preDebugBuild UP-TO-DATE :应用:checkDebugManifest :app:preReleaseBuild UP-TO-DATE :app:prepareComAndroidSupportAnimatedVectorDrawable2400Beta1Library UP-TO-DATE :app:prepareComAndroidSupportAppcompatV72400Beta1Library UP-TO-DATE :app:prepareComAndroidSupportDesign2400Beta1Library UP-TO-DATE :app:prepareComAndroidSupportMediarouterV72300Library UP-TO-DATE :app:prepareComAndroidSupportMultidex101Library UP-TO-DATE :app:prepareComAndroidSupportRecyclerviewV72400Beta1Library UP-TO-DATE :app:prepareComAndroidSupportSupportV42400Library UP-TO-DATE :app:prepareComAndroidSupportSupportVectorDrawable2400Beta1Library UP-TO-DATE :app:prepareComDaimajiaSliderLibrary115Library UP-TO-DATE :app:prepareComGoogleAndroidGmsPlayServices902Library UP-TO-DATE :app:prepareComGoogleAndroidGmsPlayServicesAds902Library UP-TO-DATE :app:prepareComGoogleAndroidGmsPlayServicesAdsLite902Library UP-TO-DATE :app:prepareComGoogleAndroidGmsPlayServicesAnalytics902Library UP-TO-DATE :app:prepareComGoogleAndroidGmsPlayServicesAnalyticsImpl902Library UP-TO-DATE :app:prepareComGoogleAndroidGmsPlayServicesAppindexing902Library UP-TO-DATE :app:prepareComGoogleAndroidGmsPlayServicesAppinvite902Library UP-TO-DATE :app:prepareComGoogleAndroidGmsPlayServicesAuth902Library UP-TO-DATE :app:prepareComGoogleAndroidGmsPlayServicesAuthBase902Library UP-TO-DATE :app:prepareComGoogleAndroidGmsPlayServicesBase902Library UP-TO-DATE :app:prepareComGoogleAndroidGmsPlayServicesBasement902Library UP-TO-DATE :app:prepareComGoogleAndroidGmsPlayServicesCast902Library UP-TO-DATE :app:prepareComGoogleAndroidGmsPlayServicesDrive902Library UP-TO-DATE :app:prepareComGoogleAndroidGmsPlayServicesFitness902Library UP-TO-DATE :app:prepareComGoogleAndroidGmsPlayServicesGames902Library UP-TO-DATE :app:prepareComGoogleAndroidGmsPlayServicesGcm902Library UP-TO-DATE :app:prepareComGoogleAndroidGmsPlayServicesIdentity902Library UP-TO-DATE :app:prepareComGoogleAndroidGmsPlayServicesIid902Library UP-TO-DATE :app:prepareComGoogleAndroidGmsPlayServicesLocation902Library UP-TO-DATE :app:prepareComGoogleAndroidGmsPlayServicesMaps902Library UP-TO-DATE :app:prepareComGoogleAndroidGmsPlayServicesNearby902Library UP-TO-DATE :app:prepareComGoogleAndroidGmsPlayServicesPanorama902Library UP-TO-DATE :app:prepareComGoogleAndroidGmsPlayServicesPlus902Library UP-TO-DATE :app:prepareComGoogleAndroidGmsPlayServicesSafetynet902Library UP-TO-DATE :app:prepareComGoogleAndroidGmsPlayServicesTagmanager902Library UP-TO-DATE :app:prepareComGoogleAndroidGmsPlayServicesTagmanagerApi902Library UP-TO-DATE :app:prepareComGoogleAndroidGmsPlayServicesTasks902Library UP-TO-DATE :app:prepareComGoogleAndroidGmsPlayServicesVision902Library UP-TO-DATE :app:prepareComGoogleAndroidGmsPlayServicesWallet902Library UP-TO-DATE :app:prepareComGoogleAndroidGmsPlayServicesWearable902Library UP-TO-DATE :app:prepareComGoogleFirebaseFirebaseAnalytics902Library UP-TO-DATE :app:prepareComGoogleFirebaseFirebaseAnalyticsImpl902Library UP-TO-DATE :app:prepareComGoogleFirebaseFirebaseAuth902Library UP-TO-DATE :app:prepareComGoogleFirebaseFirebaseAuthCommon902Library UP-TO-DATE :app:prepareComGoogleFirebaseFirebaseAuthModule902Library UP-TO-DATE :app:prepareComGoogleFirebaseFirebaseCommon902Library UP-TO-DATE :app:prepareComGoogleFirebaseFirebaseConfig902Library UP-TO-DATE :app:prepareComGoogleFirebaseFirebaseCrash902Library UP-TO-DATE :app:prepareComGoogleFirebaseFirebaseDatabase902Library UP-TO-DATE :app:prepareComGoogleFirebaseFirebaseDatabaseConnection902Library UP-TO-DATE :app:prepareComGoogleFirebaseFirebaseIid902Library UP-TO-DATE :app:prepareComGoogleFirebaseFirebaseMessaging902Library UP-TO-DATE :app:prepareComGoogleFirebaseFirebaseStorage902Library UP-TO-DATE :app:prepareComGoogleFirebaseFirebaseStorageCommon902Library UP-TO-DATE :应用:prepareDebugDependencies :app:compileDebugAidl UP-TO-DATE :app:compileDebugRenderscript UP-TO-DATE :app:generateDebugBuildConfig UP-TO-DATE :app:mergeDebugShaders UP-TO-DATE :app:compileDebugShaders 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:incrementalDebugJavaCompilationSafeguard UP-TO-DATE :应用:compileDebugJavaWithJavac :app:compileDebugJavaWithJavac - 不是增量的(例如输出已更改,之前没有执行等)。 E:\ Optasia \ Optasia2 \程序\ SRC \主\ java中的\ com \例子\ DELL \ optasia \ WelcomeActivity.java 错误:(81,18)错误:找不到符号方法addOnPageChangeListener(OnPageChangeListener) 注意:某些输入文件使用或覆盖已弃用的API。 注意:使用-Xlint重新编译:弃用以获取详细信息。 :app:compileDebugJavaWithJavac FAILED 错误:任务':app:compileDebugJavaWithJavac'执行失败。 编译失败;请参阅编译器错误输出以获取详细信 信息:建筑失败 信息:总时间:9.781秒 信息:2个错误 信息:0警告 信息:请参阅控制台中的完整输出
这是我的代码,其中发生了错误
package com.example.dell.optasia;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.example.dell.optasia.MainActivity;
import com.example.dell.optasia.R;
public class WelcomeActivity extends AppCompatActivity {
private ViewPager viewPager;
private MyViewPagerAdapter myViewPagerAdapter;
private LinearLayout dotsLayout;
private TextView[] dots;
private int[] layouts;
private Button btnSkip, btnNext;
private PrefManager prefManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Checking for first time launch - before calling setContentView()
prefManager = new PrefManager(this);
if (!prefManager.isFirstTimeLaunch()) {
launchHomeScreen();
finish();
}
// Making notification bar transparent
if (Build.VERSION.SDK_INT >= 21) {
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}
setContentView(R.layout.activity_welcome);
viewPager = (ViewPager) findViewById(R.id.view_pager);
dotsLayout = (LinearLayout) findViewById(R.id.layoutDots);
btnSkip = (Button) findViewById(R.id.btn_skip);
btnNext = (Button) findViewById(R.id.btn_next);
// layouts of all welcome sliders
// add few more layouts if you want
layouts = new int[]{
R.layout.welcome_slide1,
R.layout.welcome_slide2,
R.layout.welcome_slide3,
R.layout.welcome_slide4};
// adding bottom dots
addBottomDots(0);
// making notification bar transparent
changeStatusBarColor();
myViewPagerAdapter = new MyViewPagerAdapter();
viewPager.setAdapter(myViewPagerAdapter);
viewPager.addOnPageChangeListener(viewPagerPageChangeListener);
btnSkip.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
launchHomeScreen();
}
});
btnNext.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// checking for last page
// if last page home screen will be launched
int current = getItem(+1);
if (current < layouts.length) {
// move to next screen
viewPager.setCurrentItem(current);
} else {
launchHomeScreen();
}
}
});
}
private void addBottomDots(int currentPage) {
dots = new TextView[layouts.length];
int[] colorsActive = getResources().getIntArray(R.array.array_dot_active);
int[] colorsInactive = getResources().getIntArray(R.array.array_dot_inactive);
dotsLayout.removeAllViews();
for (int i = 0; i < dots.length; i++) {
dots[i] = new TextView(this);
dots[i].setText(Html.fromHtml("•"));
dots[i].setTextSize(35);
dots[i].setTextColor(colorsInactive[currentPage]);
dotsLayout.addView(dots[i]);
}
if (dots.length > 0)
dots[currentPage].setTextColor(colorsActive[currentPage]);
}
private int getItem(int i) {
return viewPager.getCurrentItem() + i;
}
private void launchHomeScreen() {
prefManager.setFirstTimeLaunch(false);
startActivity(new Intent(WelcomeActivity.this, HomeScreen.class));
finish();
}
// viewpager change listener
ViewPager.OnPageChangeListener viewPagerPageChangeListener = new ViewPager.OnPageChangeListener() {
@Override
public void onPageSelected(int position) {
addBottomDots(position);
// changing the next button text 'NEXT' / 'GOT IT'
if (position == layouts.length - 1) {
// last page. make button text to GOT IT
btnNext.setText(getString(R.string.start));
btnSkip.setVisibility(View.GONE);
} else {
// still pages are left
btnNext.setText(getString(R.string.next));
btnSkip.setVisibility(View.VISIBLE);
}
}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
}
@Override
public void onPageScrollStateChanged(int arg0) {
}
};
/**
* Making notification bar transparent
*/
private void changeStatusBarColor() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(Color.TRANSPARENT);
}
}
/**
* View pager adapter
*/
public class MyViewPagerAdapter extends PagerAdapter {
private LayoutInflater layoutInflater;
public MyViewPagerAdapter() {
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = layoutInflater.inflate(layouts[position], container, false);
container.addView(view);
return view;
}
@Override
public int getCount() {
return layouts.length;
}
@Override
public boolean isViewFromObject(View view, Object obj) {
return view == obj;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
View view = (View) object;
container.removeView(view);
}
}
}
error at viewPager.addOnPageChangeListener(viewPagerPageChangeListener);
以下是我的Gradle Built
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.example.dell.optasia"
minSdkVersion 15
targetSdkVersion 24
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.daimajia.slider:library:1.1.5@aar'
androidTestCompile 'junit:junit:4.12'
compile 'com.android.support:support-v4:24.0.0'
compile 'com.android.support:appcompat-v7:24.0.0-beta1'
compile 'com.google.android.gms:play-services:9.0.2'
compile 'com.android.support:design:24.0.0-beta1'
compile 'com.android.support:multidex:1.0.0'
compile 'com.google.android.gms:play-services-ads:9.0.2'
compile 'com.google.android.gms:play-services-auth:9.0.2'
compile 'com.google.android.gms:play-services-gcm:9.0.2'
compile files('E:/Optasia/Optasia2/libs/mail.jar')
compile files('E:/Optasia/Optasia2/libs/android-support-v4.jar')
compile files('E:/Optasia/Optasia2/libs/additionnal.jar')
compile files('E:/Optasia/Optasia2/libs/activation.jar')
}
答案 0 :(得分:0)
您添加了两个版本的支持库。删除jar版本,因为我怀疑它应该是没有addOnPageChangeListener
删除强>
compile files('E:/Optasia/Optasia2/libs/android-support-v4.jar')
答案 1 :(得分:0)
我怀疑您在代码中没有定义onPageChangeListener方法的ViewPager类。
您需要使用此导入
android.support.v4.view.ViewPager
我还建议像这样清理你的依赖
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.daimajia.slider:library:1.1.5@aar'
androidTestCompile 'junit:junit:4.12'
compile 'com.android.support:design:24.0.0-beta1'
compile 'com.android.support:multidex:1.0.0'
compile 'com.google.android.gms:play-services-ads:9.0.2'
compile 'com.google.android.gms:play-services-auth:9.0.2'
compile 'com.google.android.gms:play-services-gcm:9.0.2'
}
然后,如果这些文件引用您的本地项目,请在此处删除v4 JAR
compile files('E:/Optasia/Optasia2/libs/mail.jar')
compile files('E:/Optasia/Optasia2/libs/android-support-v4.jar')
compile files('E:/Optasia/Optasia2/libs/additionnal.jar')
compile files('E:/Optasia/Optasia2/libs/activation.jar')
如果你的jar文件在libs目录中,那么这些行是不必要的,因为这行编译了libs中的所有jar文件。
compile fileTree(include: ['*.jar'], dir: 'libs')