好吧,所以我不能像我的Android Studio决定的那样开发任何东西。我的所有项目都充满了错误,由Android Studio导致的未知错误。
注意:我的文件是正确的,这是另一个问题,因为即使我将从谷歌代码导入一些东西,它也会有错误。
当我导入一个项目时,一切都很好,但是在索引和诸如此类的事情之后,突然一切都是红色的,而不应该是红色的。
例如,我的错误是:
button1.setOnLongClickListener(new View.OnLongClickListener()
{
....
....
}
不应该是错误的,但是:cannot resolve symbol setOnLongClickListener
另一个例子:
button1=(Button) findViewById(R.id.button1);
我对其他按钮使用了这段代码,似乎是对的,我总是使用这一行,这是很好的,直到我的Android Studio决定给我一些困难,这一行充满了错误,他们是:
Unknown class: 'button1' , invalid method declaration; return type required, missing method body, or declare abstract
有20个错误是不应该的,我试过了:
我的模块:app build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion '22.0.1'
defaultConfig {
applicationId "firstappdevelopments.david.reactiontime"
minSdkVersion 9
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.1'
}
我现在还注意到,我的清单文件作为android:name=".MainActivity"
中的一个错误,说明它没有默认结构。就像这样。下面是完整的正常代码:
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
</manifest>
如果有人知道问题出在哪里,或者我还能做什么,请说,我对我的英语感到抱歉,谢谢大家。
发布于 2017-07-13 00:41:22
我看到的是我的代码充满了错误,但它仍然构建得很好,部署到设备上也很好。
解决这个问题的:
发布于 2021-05-20 13:49:08
对我来说,我把我的Kotlin版本从1.4升级到了1.5.0,现在它可以工作了。
dependencies {
classpath 'com.android.tools.build:gradle:4.2.1'
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$navigationVersion"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.0"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
之后,我做了一次清理和重建,之后一切都很好。
https://stackoverflow.com/questions/31792393
复制相似问题