RecyclerView “cannot resolve symbol” errors, - Android Studio - android

I've created a dummy project to understand Card-Based Layout.
Unfortunately, I am getting cannot resolve symbol errors on RecyclerView.
I'm quite new to programming and can't understand what went wrong.
Dependencies are added to build file:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support:cardview-v7:28.0.0'
}
While I'm trying to create a field in Activity I'm getting cannot resolve symbol errors on RecyclerView.
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
RecyclerView recyclerView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}

when you want to use a class you should import its library.
in this case, you haven't import recyclerview library. to fix this just change your activity code to :
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView; //recyclerview library
public class MainActivity extends AppCompatActivity {
RecyclerView recyclerView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}

Try
File > Sync Project with Gradle Files
.
Now Remove and start typing the RecyclerView again, it should show up.

You did not import the RecyclerView class, so there's no way your compiler would know what you are talking about. Simply add this line to your import statements:
import android.support.v7.widget.RecyclerView;
Your code should run fine after that.
PS:
To make your programming experience easier, you can just auto-import all the classes you need. Click here to learn more.
I hope this helps.. Merry coding!

Related

Cannot import Android package "com.google.android.gms.ads.initialization.*"

This is for a simple Android app as my first step to test banner ads in an Android app.
I followed examples, guidelines, and arrived at the need for these import lines in MainActivity.java:
// these are needed for advertising:
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.MobileAds;
import com.google.android.gms.ads.initialization.InitializationStatus;
import com.google.android.gms.ads.initialization.OnInitializationCompleteListener;
But the builder cannot resolve the last two lines:
import com.google.android.gms.ads.initialization.InitializationStatus;
import com.google.android.gms.ads.initialization.OnInitializationCompleteListener;
Why???
I use AndroidX 1.0.0 library (after migrating from Support Library 28.0.0).
The dependencies in build.gradle of the app package are:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.0.0'
implementation 'com.google.android.gms:play-services-ads:7.8.0' // added by Henrik to access AdView
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
}
I have of course added the layout item AdView into activity_main.xml.
I have downloaded Google Play services SDK - it did not help (no change)
I have downloaded Google Repository - it did not help (no change)
What do I miss?
The version you are using is way too old. Use the latest and compatible version. Its already there in Documentation.
implementation 'com.google.android.gms:play-services-ads:19.6.0'

Not able to integrate zoom in my application

I am trying to integrate zoom in my application.
For that, I followed this link [https://marketplace.zoom.us/docs/sdk/native-sdks/android/getting-started/prerequisites]
I've created a new android project where I've imported the .aar files from zoom SDK as well as imported the dependencies but when I try to run this in my main application I get this error.
error: cannot find symbol
JoinMeetingOptions opts = ZoomMeetingUISettingHelper.getJoinMeetingOptions();
^
symbol: variable ZoomMeetingUISettingHelper
location: class MainActivity
Dependencies
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation project(path: ':commonlib')
implementation project(path: ':mobilertc')
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'androidx.multidex:multidex:2.0.0'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.0.0-rc01'
}
MainActivity
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import us.zoom.sdk.JoinMeetingOptions;
import us.zoom.sdk.JoinMeetingParams;
import us.zoom.sdk.ZoomSDK;
import us.zoom.sdk.ZoomSDKInitializeListener;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ZoomSDK sdk = ZoomSDK.getInstance();
MeetingService meetingService = sdk.getMeetingService();
sdk.initialize(this, App_Key, App_Secret, ZoomSDKInitializeListener);
JoinMeetingOptions opts = ZoomMeetingUISettingHelper.getJoinMeetingOptions();
JoinMeetingParams params = new JoinMeetingParams();
params.displayName = displayName;
params.meetingNo = meetingNo;
params.password = meetingPassword;
meetingService.joinMeetingWithParams(context, params, opts);
}
}
Suggestion 1:
Check the order of imports.
Clean gradle cache at C:\Users\<USER>\.gradle\cache
In Android Studio Invalidate & Restart
Oh yeah found the problem: (You should have just done suggestion 2)
import com.***.inmeetingfunction.customizedmeetingui.MyMeetingActivity;
import com.***.inmeetingfunction.customizedmeetingui.SimpleZoomUIDelegate;
import com.***.inmeetingfunction.customizedmeetingui.view.MeetingWindowHelper;
import com.***.inmeetingfunction.zoommeetingui.ZoomMeetingUISettingHelper;
This class ZoomMeetingUISettingHelper is not part of the SDK. Its a custom class. That's why you cannot import it. Just copy it over from the sample.
Suggestion 2:
Same as I mentioned here: Just start with their sample application. Why you trying to re-invent the wheel importing libraries and stuff. Just use their existing sample as a starting point, and then go from there, create your new Activities, Views etc. Just don't use their Activities and Views you don't need. Once you are done with all the functionality, you can remove and do some cleaning up.
You have to import both commonlib.aar and mobilertc.aar . And inside your gradle paste this two
implementation project(":commonlib")
implementation project(":mobilertc")

Espresso test class not found

I have created a basic Espresso test class that looks like the following:
#LargeTest
#RunWith(AndroidJUnit4.class)
class ConfigurationsActivityTest {
#Rule
public ActivityTestRule<ConfigurationsActivity> mConfigsTestRule =
new ActivityTestRule<>(ConfigurationsActivity.class);
#Test
public void isInView() {
onView(withId(R.id.config_recyclerview)).check(matches(isDisplayed()));
}
}
The problem is, when I try to run this test I get the following error message:
Class not found: "com.name.app.activities.ConfigurationsTest"
I have followed this answer: Android Espresso test: Class not found: ...Empty test suite and taken a look at my run configurations. It seems that my test is being run as an unit test even though it's an instrumented one.
Another problem arises when I delete the unit test configurations, that were created when I tried to run my instrumented test, and try to create an instrumented test run configuration for my test class: the wizard does not allow me to select my instrumented test class containing the test above to be the test class. The problem is visualised here.
I have also taken a look at this answer: TestCase class not found by Android Studio and confirmed that my directory structure in main/java and androidTest/java are the same.
In addition, when I follow what was done in this question: Android Espresso: "No test were found" , "Process crashed" and create a run configuration for the whole package that contains my test class and run that, I get:
java.lang.RuntimeException: Delegate runner 'androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner' for AndroidJUnit4 could not be loaded.
I am suspecting that it's something to do with my imports or dependencies. Here are both:
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.LargeTest;
import androidx.test.rule.ActivityTestRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
dependencies {
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.github.bumptech.glide:glide:3.7.0'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation 'androidx.preference:preference:1.1.1'
testImplementation 'junit:junit:4.13'
testImplementation "org.mockito:mockito-core:3.3.1"
androidTestImplementation 'androidx.test:rules:1.2.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.2.0'
}
Any help appreciated. Thanks!
The rule should be like this
#Rule
public ActivityTestRule<ConfigurationsActivity> mConfigsTestRule =
new ActivityTestRule<>(ConfigurationsActivity.class);
The test class has to be public. That's why it wasn't working.

Could not Resolve Symbol R After Migrating to Androidx

After migrating to Androidx,my project start displaying a red underline error which says could not resolve R.
i have Tried googling for some similar issue but yet the error
remain,
i have checked my manifest, my Res folder for error
i have novalidate/restart project
i have clean and rebuild project
i have sync gradle with android project
yet after i have done these, the error still remains
dependencies {
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
// implementation 'com.google.android.material:material:1.0.0-rc01'
implementation 'com.google.android.material:material:1.1.0-alpha05'
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'androidx.appcompat:appcompat:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
implementation 'com.github.maxyou:CalendarPicker:v1.1.2'
// Ramotion
implementation 'com.ramotion.paperonboarding:paper-onboarding:1.1.3'
implementation 'com.ramotion.foldingcell:folding-cell:1.2.3'
implementation 'com.ramotion.garlandview:garland-view:0.3.3'
}
MyApplication.java
package xyz.esusku.nearbyworker;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}```
See https://twitter.com/tasomaniac/status/1103020923874131968 for the details.
Gradle Android Plugin 3.3+ no longer generates R source file. You either need to update to the IDE that supports the new binary format for the resources or downgrade the plug-in to an older version in your build.gradle.
Hope you have added these line in gradle.properties file: as you are trying to migrate existing project.
android.useAndroidX=true
android.enableJetifier=true
one more thing try removing the duplicate import-
import android.support.v7.app.AppCompatActivity; //remove this line
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;

trying to share code created in a android library module

Im trying to share a class (between 2 apps) created in a Android Library Module. called cTest . When I try to declare it in my, code says it is undfined.
This is what I did:
created a new project called testdouble.
created a new app by going to new module, phone & tablet module and called it app1. The package name was "com.example.app1"
created another app called app2 but change the package name to "com.example.app1", so both apps have the same package name.
created a new libary module by going to new moduleandroid library. I change the package name to "com.example.app1.common and set the
name of library to common.
added the 2 gradle strips labeled build gradle(Module app1) build gradle(Module app1) I added the line build gradle(Module app1) inside
the dependencies block.
I then created a new class in common java folder called cTest
in file MainActvy for app1 i added the line
cTest t;
got a error saying ctest was undefinned.
My files are as follows
App1 mainacticty
package com.example.app1;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
CTest t; // says cTest does not exist
App2 mainacticty
package com.example.app1;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
CTest t; // says cTest does not exist
.....
Gradle file
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
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'
compile project(":common")
}

Categories

Resources