I have done Android projects in the past with Eclipse. Now when I try to start using the Android Studio IDE when I create a new project the brand new untouched mainactivity.java file has import errors. I have looked on multiple forms and can not find out how to fix the problem. I have tried to go to file>Invalidate Cache> Invalidate and restart
I have tried every method I could find and think of and it is still not working.
This has been a 3 day project just to get the new project setup to work I don't understand why this is not working or how to fix it.
Here is the mainactivity.java file:
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity; //this is one of the errors
//it says that AppCompactActivity cannot be resolved
import android.view.Menu;
import android.view.MenuItem;
public class MyActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_my, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
this is my build.gradle:
android {
compileSdkVersion 22
buildToolsVersion "23.0.0 rc3"
defaultConfig {
applicationId "com.compeny.project"
minSdkVersion 16
targetSdkVersion 22
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'
}
Try adding :
dependencies {
compile 'com.android.support:appcompat-v7:19.1.+'
}
in build.gradle
You might be missing the library. Maven/IntelliJ projects can be imported like above, in Android Studio gradle
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.