Can not resolve the symbol FragmentActivity - android

The Activity shows error while importing the FragmentActivity.
import android.support.v4.app.FragmentActivity;
import android.text.TextUtils;
import android.widget.TextView;
import java.util.ArrayList;
public class DetailActivity extends FragmentActivity
My build.gradle file
apply plugin: 'android'
android {
compileSdkVersion 23
buildToolsVersion '23.0.3'
defaultConfig {
minSdkVersion 8
targetSdkVersion 23
versionCode 3
versionName "1.0.2"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:support-v4:23.1.0'
compile 'com.android.support:appcompat-v7:23.1.0'
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.google.android:support-v4:r7'
}

At First
Remove Unnecessary
compile 'com.google.android:support-v4:r7' // No Need
Then Clean-Rebuild and Do Gradle Your Project

Related

error: package android.v7.app does not exist

Hi there stackoverflow community, hope you can help!
Im using udacity to learn android development and I have ran into a problem. there are a few errors that have come up:
error: package android.v7.app does not exist
error: cannot find symbol class AppCompatActivity
error: method does not override or implement a method from a supertype
error: cannot find symbol variable super
error: cannot find symbol method setContentView(int)
error: cannot find symbol class openNumbersList
error: cannot find symbol method startActivity(Intent)
Everything was working fine but I was following a tutorial and noticed that my imports in my Main Activity didn't match with what was on the tutorial so I changed:
"import..."
to
import android.v7.app.AppCompatActivity;
import android.os.Bundle;
also even before this, "AppCompatActivity" was in red:
public class MainActivity extends AppCompatActivity {
Main Activity:
package com.example.android.miwok;
import android.content.Intent;
import android.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Set the content of the activity to use the activity_main.xml layout file
setContentView(R.layout.activity_main);
}
public void openNumbersList(View view){
Intent i = new Intent(this, openNumbersList.class);
startActivity(i);
}
}
Gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion '27.0.3'
defaultConfig {
applicationId "com.example.android.miwok"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
implementation 'com.android.support:appcompat-v7:23.3.0'
implementation 'com.android.support:support-v4:23.3.0'
implementation 'com.android.support:design:23.3.0'
}
hope this helps.
Try your gradle as follow
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.example.android.miwok"
minSdkVersion 19
targetSdkVersion 27
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.android.support:design:27.1.1'
}
I think that above code solve your issue
Anyone who faces this problem has to revise the coding of padding and alignment attributes.
The fault is simple.
All you have to do is to be careful with the attributes specifying.

Cannot resolve symbol MathUtils

I started a new project on Android Studio, targeting API 26, and did nothing but to add the following line:
import android.util.MathUtils;
and got the error: Cannot resolve symbol MathUtils
Here's my MainActivity.java:
package com.example.HeyJude.test2;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.MathUtils;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
And my build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.example.HeyJude.test2"
minSdkVersion 26
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
I tried using File > Invalidate Caches (with restart), but it didn't help. Any other ideas?
If you search for it, did you mean this?
android.support.v4.math.MathUtils

import com.firebase.client.Firebase in Android 2.3.3

I am creating an application class to use Firebase in my complete application. However in the import line error occurs highlighting 'firebase' in red.
I have looked everywhere but cannot make out the problem.
Code:
package com.mobility.mobilityindia;
import android.app.Application;
import com.firebase.client.Firebase; <--- firebase is red here
public class MobilityIndia2 extends Application{
#Override
public void onCreate() {
super.onCreate();
Firebase.setAndroidContext(this); <---- Firebase is red here
}
app level gradle.build
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "26.0.0"
defaultConfig
{
applicationId "com.mobility.mobilityindia"
minSdkVersion 21
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
String googleSupportVersion = '26.+'
String googlePlayServicesVersion = '11.0.2'
compile "com.google.firebase:firebase-core:$googlePlayServicesVersion"
compile "com.google.firebase:firebase-auth:$googlePlayServicesVersion"
compile "com.android.support:appcompat-v7:$googleSupportVersion"
compile "com.android.support:support-v4:$googleSupportVersion"
compile "com.google.android.gms:play-services:$googlePlayServicesVersion"
compile "com.android.support:design:$googleSupportVersion"
compile 'com.android.support.constraint:constraint-layout:1.0.2'
}
apply plugin: 'com.google.gms.google-services'
top level gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.google.gms:google-services:3.1.0'
}
}
The code you have is for an old version of the Firebase SDK (1.x or 2.x), while you're importing the latest version.
If you follow the latest documentation or the latest Android codelab, you won't need the Firebase.setAndroidContext() anymore and will get imports that start with com.google.firebase.

Why it doesn't crash when invoking a nonexistent api

I am running such a code piece on an Android emulator with api level 16:
package darklord.compilesdkversiontest;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
LinearLayout linearLayout = (LinearLayout) findViewById(R.id.test);
int result = linearLayout.getPaddingEnd();
Log.e("Test", result+"");
}
}
The getPaddingEnd is added in api level 17 so I am expecting this to crash on the emulator. There is indeed a warning in the Android Studio however it did compile and runs on the emulator. Furthermore, it even prints out the correct padding value. So why it doesn't throw some runtime expection? Here is the build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "darklord.compilesdkversiontest"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
}

Error at creating new Fragment on compileSdkVersion 22 on Android App : onAttach() method fails

I just use the menu to create new fragment and by default it's throwing an error with the fragment generated file, I did not add any code. The problem is in the onAttach() method
#Override
public void onAttach(Context context) {
super.onAttach(context);
if (context instanceof OnFragmentInteractionListener) {
mListener = (OnFragmentInteractionListener) context;
} else {
throw new RuntimeException(context.toString()
+ " must implement OnFragmentInteractionListener");
}
}
It says: "onAttach(android.app.Activity) in fragment cannot be applied to (android.content.Context)"
My imports on the fragment file:
import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
My gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "license.j4ftech.com.mapevents"
minSdkVersion 19
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'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.android.support:design:22.2.0'
compile 'de.hdodenhof:circleimageview:2.0.0'
compile 'com.android.support:support-v4:22.2.0'
}
My gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "license.j4ftech.com.mapevents"
minSdkVersion 19
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'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.android.support:design:22.2.0'
compile 'de.hdodenhof:circleimageview:2.0.0'
compile 'com.android.support:support-v4:22.2.0'
}
How can I solve this issue?
The method onAttach(Context context) was introduced in API level 23. Your compile/target SDK version is 22 which is why the project cannot find the method definition. You can either switch back to using the old deprecated method onAttach(Activity a) or change the appcompat version to the latest (23.1.1) to be able to use the new method.
Use the latest support library:
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
in your gradle file and set compileSdkVersion/targetSdkVersion to 23.

Categories

Resources