I am new to programming and trying to learn android development with android studio. I updated Java and tried to update android SDK when it crashed. I finally got the Android SDK update fixed but now I have this error in an app I was working on. It's in the activity_main.xml file
The error says "cannot resolve this symbol: MainActivity.java"
Here's the line where the error shows up.
tools:context="com.example.android.justjava.MainActivity.java"
MainActivity.java is red. I feel like it's directory tree issue, but I can't tell what the program wants so I can fix it.
Remove .java at the end, and make sure that MainActivity.java exists inside the package com.example.android.justjava.
What is the purpose of writing that line?
tools:context
This attribute is typically set on the root element in a layout XML
file, and records which activity the layout is associated with (at
designtime, since obviously a layout can be used by more than one
layout). This will for example be used by the layout editor to guess a
default theme, since themes are defined in the Manifest and are
associated with activities, not layouts.
Source: http://tools.android.com/tech-docs/tools-attributes
Related
I extend ConstraintLayout class for special purpose.
and I use this class in layout xml file.
not problem show layout.xml with text mode.
but try show layout.xml with Design mode,
android studio show me this message.
I already try 'Refresh', 'rebuild', 'clean build'.
but still show 'Missing classes'.
how can I fix this problem?
The problem is that you are referencing to a class that doesn't exist or is not where you are referencing to.
You can either fix the path by
Copying the class to the correct folder.
Fixing the path by clicking on Fix build path
Or, click on Create Class and copy everything you had in previous class into the new one.
I think the 3rd option will be the easiest for you.
I'm very new to Android studio and I'm currently following a tutorial that implements a sliding tab layout for an application. The tutorial says to put
SlidingTabLayout.java and SlidingTabStrip.java in our project, but doesn't say exactly where. For now, I just put declared them as two classes and put them under the java folder. (...app\src\androidTest\java). However, when I try to include a SlidingTabLayout object in my xml file, it says "The following classes could not be: found:com.android4devs.slidingtab.SlidingTabLayout", which means I must have put those two files in the wrong place. Anybody used these files before and know where to put them?
Thank you
The error says could not found the SlidingTabLayout class. Which means you have to tell correctly where the SlidingTabLayout file placed.
in xml change com.android4devs.slidingtab to your package name. You can find your package name in SlidingTabLayout.java or in manifest file.
I'm programming an Android app that uses Gradle. However, in the .xml files and Android Manifest, the URL for Android Schemas are "Not registered".
This problem has been a nuisance and have spent hours trying to get it fixed. I have looked through:
1: Intellij Android project schema URI not registered?
2: If I change an external library: AndroidManifest, cannot parse file
I cannot just create a new project because this application is not only developed only by me but a small team. The code is also on GitHub as well. Secondly, even if I try to create a new project, the Schemas are still not registered.
Eclipse is not an option because they do not officially support Gradle integration. (unless you have found a Gradle plugin that is SPECIFIC to android applications). I also have installed Android Studio, but I still get the same errors, if not more errors.
Edit: I am currently using Intelli-J community edition
I had almost the same problem, 2 different flavors and that URI error in the xml files inside one of the flavors. I've solved by placing a copy of the Android Manifest inside the folder of the flavor that was giving me trouble, build project and error gone
For me the only thing worked was add mock Activity with right click on the Flavour package, choose "new->activity>empty activity", choose the fit source set and package name in the dialog, and after the Activity created the problem solved. I deleted the mock activity later and it not brought any problem.
Combining both Hernan Romero's answer and yshahak's answer, create an Android Manifest file inside each flavor's root folder.
For example, if you have a flavor called "pro", right-click on the pro folder then choose new * other * Android Manifest File.
(I did it the "long way": for each flavor, I set that flavor to be the active variant and then created a dummy empty activity with no layout file. I then removed the activity and unneeded xmlns: from the manifest and then deleted the activity and now-empty java folder in the flavor's folder. Rinse-repeat for the other flavor(s). That left me with an almost empty manifest, for each flavor, as follows:)
My "dummy" AndroidManifest.xml file in each flavor contains only:
<manifest>
<application/>
</manifest>
I am developing an Android app using Phonegap and jQueryMobile, working in Eclipse. I want the app, with the user's permission, to auto-install a launcher icon on the user's "desktop". I've found the example LauncherShortcuts.java on Android Developers, and I am almost to the point of getting it to work. That's a big achievement, since I know extremely little of Java programming.
Almost.
This is the example code online:
http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/LauncherShortcuts.html
One string or thingy in the code refuses to cooperate. Line 83...
TextView intentInfo = (TextView) findViewById(R.id.txt_shortcut_intent);
...has this constant or variable in it called "R.id.txt_shortcut_intent", and Eclipse says it doesn't recognize the id part. If I follow its suggestion of adding a class 'id' in R., it tells me there is no field txt_shortcut_intent in 'R.id'. That doesn't surprise me.
I've been able to fix a few similar errors involving R.something_or_other. But not this one. My R.java only contains the classes attr,drawable,layout, and string.
What is going on here and most importantly, what should I do to get this thing up and running? The launcher icon is all that stands between here and actually launching the app (how ironic).
If you find any errors in the project. Sometimes id of R.java entries will be shifted to string folder or R.java.
For this choose
project → clean
file → close all
click on your project
See the entries in id of R.java your ids will be in this folder
An android app uses an xml to define the layout of all the elements you want to display. In this case, you're missing an element that displays text called TextView. You don't have the Textview 'txt_shortcut_intent' defined in the xml, probably.
Here's the xml you're looking for (just copy and paste it into your main.xml):
http://developer.android.com/resources/samples/ApiDemos/res/layout/launcher_shortcuts.html
The ADT Plugin in Eclipse can only rebuild the R class if there are no (Java) errors.
Therefore, fix all errors and check if your layout ressource has the correct id (txt_shortcut_intent).
It's worth a try to clean the project and restart Eclipse.
I have just started writing my first ever Java/Android application, so forgive the total n00b question.
How do you access the the standard operating system icons such as search icon/menu icon etc? They are not in the res/drawable folder where I would expect to find them. Are they available as part of the SDK or must you download them seperately?
EDIT
Maybe you can help me further - I am getting the following error (repeated on):
[2011-09-08 19:59:47 - TweetTab] C:\Users\Dan\workspace\TweetTab\res\menu\options_menu.xml:4: error: Error: No resource found that matches the given name (at 'icon' with value '#drawable/ic_menu_search').
However, the icon is not empty, the xml looks like this:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/search"
android:icon="#drawable/ic_menu_search"
android:title="#string/search"/>
</menu>
Am I missing something?
SOLVED
I changed android:icon="#drawable/ic_menu_search" to android:icon="#android:drawable/ic_menu_search" and it could then find the icon.
You can acces them via android.R.drawable.* or in xml by #android:drawable/something.
I installed the Android SDK for Eclipse on Windows.
Now I can find all ressources under "C:\Program Files\Android\android-sdk-windows\platforms\android-9\data\res..."
try this instead:
android:src="#android:drawable/ic_menu_camera"
it is now possible to use vector assets to generate standard (or customised) icons for android.
Add 'com.android.tools.build:gradle:1.4.0-beta3' to your build.gradle file. (The stable version will be out in the coming weeks).
Add a vector asset by right-clicking res/drawable/ > New > Vector Asset. Android Studio provides a built-in viewer for you to pick your drawable.
Reference your icon like you usually do. Eg: android:icon="#drawable/ic_help_24dp"
A lot of them can be found in android.R.drawable but not all are publicly accessible
You can find the android.R.drawable images in your local SDK folder. (Tested using Android Studio 3.0)
First have a look at the docs for the names of the drawables here: https://developer.android.com/reference/android/R.drawable.html
Second either search your drive for one of those image names.png or type in the name of any of them into your Android Studio activity and right click (goto declaration) on it to view the image. Then you can also right click that image to copy the path. Then open that folder and look at all the PNG's there.
Example on windows 10: android.R.drawable.star_big_on is located in user/AppData/Local/Android/Sdk/platforms/android-25/data/res/drawable-hdpi/star_big_on.png
(Note also on windows AppData is a hidden folder so you may need to set your windows explorer to show hidden if you are clicking to open each folder)
Also if you need to see material design icons / descriptions this is a good place to look: https://material.io/icons
Someone may see this page useful for getting those icons... http://developer.android.com/design/style/iconography.html
For those of you in the Visual Studio/Xamarin Android camp, you can view and add the standard Material icons pretty easily using the following plugin:
https://marketplace.visualstudio.com/items?itemName=nikainteristi.Materialiconsgenerator
I've used it a few times in my projects.