I have a multitude of problems stemming from one central issue: Android Studio isn't recognizing imports.
For example, in my class "ActivityAbout" I have the following import statements:
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.view.View;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.animation.AnimationUtils;
import android.widget.ViewFlipper;
However, in the IDE (using the first import statement as an example), the import android.content. is appearing grayed out, and when I hover over it, it says "unused import statement" the Intent part is appearing red, and when hovering over that, it says "cannot resolve symbol Intent." This occurs for each of my import statements, with the first part being grayed out, and the last part being in red.
Now, this provides a multitude of issues in my code, as anything relating to those import statements appears red and when hovering over it, I get the message "cannot resolve symbol ____"
Here's the kicker- my app still compiles and runs upon opening it on my phone.
I suppose my main issue is that it is incredibly annoying, and auto imports doesn't work either. (I have checked off 'show import popup' in the settings, which is the answer I found for other people having issues with auto import not working). My other concern is that this would make my app ineligible for release on the play store. I'm still looking into the publishing process, so I don't know if that is actually an issue or not.
My question (if no one has an answer for how to fix this) is: is this a problem with the IDE itself or the code?
EDIT: added the other import statements
I just had this issue.
I resolved it by clicking File > Invalidate Caches / Restart... > Invalidate and Restart.
When Android Studio restarted and indexed all my code again, the issue was gone.
I have no idea what caused it...
I had a similar issue with my project. I resolved it by going to File > Sync with File System and then closing the project and importing it again
You may need to resync with the gradle again but hopefully it works for you
Related
Im using eclipse Photon. The code worcked fine on old computer. When I got a new computer and tried to run the program The following imports are give me a import cannot be resolved error
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClients;
I'm assuming im missing some jar files. Could some one tell me what jar files I need and whare i can find them? Also why does it work find on ole computer with same jars being added?
Those two classes are part of Apache HTTP Components which you can access from https://hc.apache.org/index.html.
I have downloaded the library
added the library
refreshed the project
imported the library to project
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.*;
import org.apache.commons.httpclient.params.HttpMethodParams;
However i still get the error
The import org.apache.commons.httpclient can not be resolved
can you please tell what is the problem with it?
I had to change my package name from com.example.chris.myapplication to com.tamaritz.chris.myapplication so that my app could be properly loaded and distributed via Google Play Store. To do this, I used the approach Android Studio Rename Package which was to basically create a new directory, copy contents, update Manifest. I got those steps down but I am having trouble with "change/rename the R file imports in whole project". When I made my package name change, my line of code(below) said "R cannot be resolved".
submit = (Button) v.findViewById(com.example.chris.myapplication.R.id.submitButton);
When I went to the imports part of the java source code(below)
package com.tamaritz.chris.myapplication;
import android.app.Activity;
import android.app.DialogFragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
Everything seemed to be line place, the right package name.
Do I have to put a manual R import? The person said to change/rename the import but I don't even see the original R import.
And this something else I did which I am not sure. A possible solution I found was just to do alt enter, and import the class. That line of code suddenly turned into
submit = (Button) v.findViewById(R.id.submitButton);
Is this a valid approach. Does the package name explictly need to be there? After I did this, i did not see any changes in the import section either.
So i made it finally to the final stage of my simple java app that runs under windows and is used to get the user name and log it in an remote excel file. up until now everything is ok.
When i Externelize (does that word exist?) the app to make it a runnable jar the size of the app was 22Mo! wich is huge since i want to use it in an email (outlook).
Here come the question (finally). Can i delete any of the default java jars in the classpath and the app will still run ?? if yes, which ones??
NB: i tried including the imports in the SS if it does help
NB2: the Jar of the app it self is just 20Ko , the ressources are around 22Mo .
By the way thank you all for helping me make this app it was thanks to this website eventhought i didn't ask any question up until now you'll still answered them all..You rock !
Those are my imports:
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Iterator;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.wb.swt.SWTResourceManager;
EDIT: So after the discussions i managed to reduce the size of the app to 8Mo by deleting some of the jar in the referenced library (org.ibm.icu.jar). The app still runs perfectly without it
A jar file is just a zip file, so what I would do is simply unzip the file and see what comes with it and what is large. The standard java libraries, should not even be part of your JAR as they are part of the JRE.
However, my suspicion is that you use Apache POI and that is huge. So if you are writing to an Excel file you might have to stick with that size or find another library.
You could for example write the output as CSV which is very lightweight.
I am following this tutorial http://steigert.blogspot.com/2012/02/3-libgdx-tutorial-scene2d.html and i get an error in eclipse for these imports:
import com.badlogic.gdx.scenes.scene2d.OnActionCompleted;
import com.badlogic.gdx.scenes.scene2d.actions.Delay;
import com.badlogic.gdx.scenes.scene2d.actions.FadeIn;
import com.badlogic.gdx.scenes.scene2d.actions.FadeOut;
import com.badlogic.gdx.scenes.scene2d.actions.Sequence;
import com.badlogic.gdx.scenes.scene2d.ui.Align;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Image.Scaling;
all other libgdx imports work fine but these give me the import cannot be resolved error
does anyone of you know how to fix this?
Now that I can see my code, yes - the libgdx version used in the steigert demos is not the latest, and lots of scene2d has changed since then.
http://steigert.blogspot.com/2012/07/13-libgdx-tutorial-libgdx-refactoring.html
You can get his refactored/updated code at:
https://code.google.com/p/steigert-libgdx/source/browse/tags/