LocationClient cannot resolved symbol in android studio? - android

Below is my build.gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.domore.googlelocationdemo"
minSdkVersion 14
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.1.1'
//compile 'com.google.android.gms:play-services:8.3.0'
compile 'com.google.android.gms:play-services:6.5.87'
}
Here,Is my MainActivity.java
package com.domore.googlelocationdemo;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesClient;
public class MainActivity extends AppCompatActivity implements GooglePlayServicesClient.ConnectionCallbacks,
GooglePlayServicesClient.OnConnectionFailedListener{
LocationClien
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public void onConnected(Bundle bundle) {
}
#Override
public void onDisconnected() {
}
#Override
public void onConnectionFailed(ConnectionResult connectionResult) {
}
}
What will i need to do?
Please any one help me to solve out this error?
I was used a LocationRequest class but which parameter i need to set LocationRequeset class constructor?

Its because of the compiled sdk version as LocationClient is deprecated in API23 so you can use new libraries
com.google.android.gms.common.api.GoogleApiClient and
com.google.android.gms.location.LocationRequest.

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

why i can't extends AppCompatActivity in my activity class?

When i extends my activity class by AppCompatActivity it gave me Cannot resolve symbole AppCompatActivity.
I used the imports in my gradle but it does not works...
compile 'com.android.support:appcompat-v7:21.+'
compile 'com.android.support:appcompat-v7:21.0.+'
compile 'com.android.support:appcompat-v7:21.0.0'
Activity class
import android.support.v7.app.AppCompatActivity;//Cannot resolve symbole AppCompatActivity
public class myActivity extends AppCompatActivity{//Cannot resolve symbole AppCompatActivity
.
.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mymain);
intilaizs();
action();
}
.
.
My Gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.example.me.menu_2"
minSdkVersion 16
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:21.+'
// compile 'com.android.support:appcompat-v7:21.0.+'
// compile 'com.android.support:appcompat-v7:21.0.0'
compile project(':MenuLibrary')
compile files('libs/gson-2.2.4.jar', 'libs/gson-2.2.4-javadoc.jar', 'libs/gson-2.2.4-javadoc.jar')
}
Add following line in gradle file:
compile 'com.android.support:design:23.3.0'
I hope this will solve your problem.
You need to add compile 'com.android.support:support-v4:21.0.0'

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