应用程序工作正常,但当我将项目导入另一个系统时,它给出了以下错误 -
Error:(159, 30) error: incomparable types: Object and int
Error:(166, 35) error: incomparable types: Object and int
Error:(173, 37) error: incomparable types: Object and int
Error:(179, 35) error: incomparable types: Object and int
Error:(185, 35) error: incomparable types: Object and int
Error:(191, 35) error: incomparable types: Object and int
Error:(201, 35) error: incomparable types: Object and int
Error:(207, 35) error: incomparable types: Object and int
Error:(213, 35) error: incomparable types: Object and int
Error:(219, 35) error: incomparable types: Object and int
Error:(369, 35) error: incomparable types: Object and int
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
以下是显示错误的代码,错误显示在getTag() -
fragmentDrawer.HideDrawer();
if(v.getTag()==0)
{
context.startActivity(intent);
}
else if(v.getTag()==1)
{
Intent intent=new Intent(context, class2.class);
context.startActivity(intent);
}
else if(v.getTag()==2)
{
Intent intent=new Intent(context, class3.class);
context.startActivity(intent);
}
else if(v.getTag()==3)
{
Intent intent=new Intent(context, NotificationActivity.class);
context.startActivity(intent);
}
else if(v.getTag()==4)
{
Intent intent=new Intent(context, class4.class);
context.startActivity(intent);
}
else if(v.getTag()==5)
{
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.setType("text/plain");
sendIntent.putExtra(Intent.EXTRA_TEXT,context.getResources().getString(R.string.user_name));
context.startActivity(Intent.createChooser(sendIntent, context.getResources().getString(R.string.about_us)));
}
else if(v.getTag()==6)
{
Intent intent=new Intent(context, class5.class);
context.startActivity(intent);
}
else if(v.getTag()==7)
{
Intent intent=new Intent(context, class6.class);
context.startActivity(intent);
}
else if(v.getTag()==8)
{
Intent intent=new Intent(context, class7.class);
context.startActivity(intent);
}
else if(v.getTag()==9)
{
dialog = new Dialog(context);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.rate_us);
TextView tv_rate_us=(TextView)dialog.findViewById(R.id.tv_rate_us);
TextView tv_tex=(TextView)dialog.findViewById(R.id.tv_tex);
TextView tv_meh = (TextView) dialog.findViewById(R.id.tv_meh);
LinearLayout ll_loved_it=(LinearLayout)dialog.findViewById(R.id.ll_loved_it);
LinearLayout ll_meh=(LinearLayout)dialog.findViewById(R.id.ll_meh);
Fontinnitialize.setFontTextView(tv_tex, context);
Fontinnitialize.setFontTextViewBold(tv_rate_us, context);
Fontinnitialize.setFontTextView(tv_meh, context);
TextView tv_loved_it = (TextView) dialog.findViewById(R.id.tv_loved_it);
Fontinnitialize.setFontTextView(tv_loved_it, context);
ll_meh.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
}
}
});
PS - 我已经阅读了与此相关的其他帖子但无法从中获得任何解决方案。
以下是app.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion '23.0.2'
lintOptions {
checkReleaseBuilds false
abortOnError false
}
dexOptions {
javaMaxHeapSize "2g"
}
defaultConfig {
applicationId "com.example"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile files('libs/volley.jar')
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.google.firebase:firebase-messaging:9.2.0'
compile 'com.google.code.gson:gson:1.6'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'de.hdodenhof:circleimageview:2.0.0'
compile 'com.android.support:recyclerview-v7:23.+'
compile 'com.android.support:design:23.2.0'
compile 'com.squareup.picasso:picasso:2.5.0'
// compile 'com.google.android.gms:play-services-location:8.1.0'
compile 'com.github.JakeWharton:ViewPagerIndicator:2.4.1'
compile 'com.intuit.sdp:sdp-android:1.0.3'
compile 'com.nispok:snackbar:2.11.+'
compile 'com.android.support:multidex:1.0.1'
compile 'com.facebook.android:facebook-android-sdk:[4,5)'
compile 'com.google.android.gms:play-services:9.2.1'
compile ('cn.trinea.android.view.autoscrollviewpager:android-auto-scroll-view-pager:1.1.2') {
exclude module: 'support-v4'
compile 'ch.acra:acra:4.9.0'
}
}
答案 0 :(得分:1)
将该代码更改为
fragmentDrawer.HideDrawer();
if((Integer)v.getTag()==0)
{
context.startActivity(intent);
}
else if((Integer)v.getTag()==1)
{
Intent intent=new Intent(context, class2.class);
context.startActivity(intent);
}
else if((Integer)v.getTag()==2)
{
Intent intent=new Intent(context, class3.class);
context.startActivity(intent);
}
else if((Integer)v.getTag()==3)
{
Intent intent=new Intent(context, NotificationActivity.class);
context.startActivity(intent);
}
else if((Integer)v.getTag()==4)
{
Intent intent=new Intent(context, class4.class);
context.startActivity(intent);
}
else if((Integer)v.getTag()==5)
{
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.setType("text/plain");
sendIntent.putExtra(Intent.EXTRA_TEXT,context.getResources().getString(R.string.user_name));
context.startActivity(Intent.createChooser(sendIntent, context.getResources().getString(R.string.about_us)));
}
else if((Integer)v.getTag()==6)
{
Intent intent=new Intent(context, class5.class);
context.startActivity(intent);
}
else if((Integer)v.getTag()==7)
{
Intent intent=new Intent(context, class6.class);
context.startActivity(intent);
}
else if((Integer)v.getTag()==8)
{
Intent intent=new Intent(context, class7.class);
context.startActivity(intent);
}
else if((Integer)v.getTag()==9)
{
dialog = new Dialog(context);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.rate_us);
TextView tv_rate_us=(TextView)dialog.findViewById(R.id.tv_rate_us);
TextView tv_tex=(TextView)dialog.findViewById(R.id.tv_tex);
TextView tv_meh = (TextView) dialog.findViewById(R.id.tv_meh);
LinearLayout ll_loved_it=(LinearLayout)dialog.findViewById(R.id.ll_loved_it);
LinearLayout ll_meh=(LinearLayout)dialog.findViewById(R.id.ll_meh);
Fontinnitialize.setFontTextView(tv_tex, context);
Fontinnitialize.setFontTextViewBold(tv_rate_us, context);
Fontinnitialize.setFontTextView(tv_meh, context);
TextView tv_loved_it = (TextView) dialog.findViewById(R.id.tv_loved_it);
Fontinnitialize.setFontTextView(tv_loved_it, context);
ll_meh.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
}
}
});
因为v.getTag()返回对象,我们必须输入将其强制转换为Integer。否则你会收到错误 希望这会有所帮助