Trouble importing android.support.v7.widget.CardView into Eclipse - java

I use Eclipse and I'm trying to create an application using the new support-library-v7:21.+ from Lollipop.
Created my new project
imported in eclipse the support-library-v7
changed in project-properties of support library the line: target=android-21 with 21 target
changed the target of my application in 21
imported the library in my project
clean all
After all i still got the invalid R declaration. I restarted Eclipse and then, after re-importing the library, seem went! I created a Tolbar and a NavigationDrawer as well without problem - it works.
Now, i would like to put a CardView in my ListView items:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
>
<!-- A CardView that contains a TextView -->
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/card_view"
android:layout_gravity="center"
android:layout_width="200dp"
android:layout_height="200dp"
card_view:cardCornerRadius="4dp">
<TextView
android:id="#+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="#+id/codename"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="#+id/versione"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="#+id/link"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="#+id/timestamp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</android.support.v7.widget.CardView>
</LinearLayout>
well, first error: No resource identifier found for attribute 'cardCornerRadius'.
I tried to delete the attribute, restart the application but I get a the following crash:
java.lang.RuntimeException: Binary XML file line #2: You must supply a layout_width attribute.
I don't understand what the problem is.

Adding the library
Gradle
compile 'com.android.support:appcompat-v7:22.0.0'
compile 'com.android.support:cardview-v7:22.0.0'
Eclipse
Using android.support.v7.widget.CardView in my project (Eclipse)
Proper LinearLayout
As the error said, a LinearLayout needs a layout_width and a layout_heighth. Always.

I have outlined the steps that worked for me as an answer to this question. It should work.

I had the same issue.
Tried adding Eclipse->properies->Android->Libraries->Add = CardView is not there.
Tried Eclipse->properies->JavaBuildPath->Libraries->Add Jars->(select from CardView->libs) did not work.
what worked:
cardview->project.properites, add android.library=true if missing.

We need to do both the things add android.support.v7.widget.CardView as a library project and also add + check it's jar file in java build path
Go to File -> Import -> Existing Android code into workspace --> Browse (Go to sdk/extras/android/support/v7/cardview) --> Click ok --> Click Finish
Right click on cardview project --> Properties --> Android(Left Pane) --> Enable isLibrary (tick the checkbox) --> Apply --> ok
Right click on your project --> Properties --> Android(Left pane) --> Add (under library) --> cardview --> apply --> ok
right click on your project again --> build path --> configure build path -->under libraries-->add jar-->expand cardview-->expand libs-->select android.support.v7.widget.CardView.jar
under order and export-->check android.support.v7.widget.CardView.jar-->click
Hope it will work fine.

It is obvious that you didn't import the CardView support project as your main project's library. To import CardView library, you need to do this:
1, first, import CardView support library into you Eclipse. The process should be like this:
File-->Import-->Android-->Existing Android Code into Eclipse-->Browse-->.../sdk/extras/android/support/v7/cardview-->OK-->Finish. Then you will see project of android-support-v7-cardview in your Eclipse in which all resource and jar is.
2, add android-support-v7-cardview into your main project as a library. Just like this: right-click your project-->Properties-->Android-->Add, and select android-support-v7-cardview into your project.
And then, rebuild your project. Errors about CardView in your project will be finished.

Inside your build.gradle file (inside dependencies section) add the last versions for support library and cardView support library:
dependencies {
...
...
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:cardview-v7:23.0.1'
}

Related

execution failed for task ':app:mergeDebugResources' android studio 1.4.1

I made projects in Eclipse with ADK, but today i have installed Android Studio, created my first project HelloWorld and faced with problem: I added one ImageView, if I set beckgroung (or src) with any system resources - all right, but when I set my box.png file I get errors:
1. execution failed for task ':app:mergeDebugResources'
2. no resource found that matches the given name (at 'background' with value '#drawable)
I tried all the options of the website https://stackoverflow.com/ and others with same problems, but I didn't solve my problem yet.
Please, help me !
<?xml version="1.0" encoding="utf-8"?>
<TextView android:text="Hello World!" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/app_name"
android:id="#+id/imageView"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:background="#drawable/box" />

setContentView can't be resolved in Android

I know it is a known issue, but my ide(android studio) is saying that setContentView can't be resolved. In fact, it was working perfect well but I tried to import some android plugin but then I deleted all the plugin files I added. Then I noticed that setContentView wasn't recognized anymore.
I tried everything I found on SO (cleaning, rebuilding....). I read it is mainly related to the xml view files, but I have no error in these files. How can I do ?
Update :
when running gradle build, I get some success build. Then when I want to run the project, I get in my console
org.gradle.execution.TaskSelectionException: Task 'compileDebug' is ambiguous in root project 'NewsFeeder'. Candidates are: 'compileDebugAidl', 'compileDebugJava', 'compileDebugNdk', 'compileDebugRenderscript', 'compileDebugTestAidl', 'compileDebugTestJava', 'compileDebugTestNdk', 'compileDebugTestRenderscript
Edit 2 : here's my layout
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="400px"
android:layout_height="800px">
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ListView
android:id="#+id/left_drawer"
android:layout_width="280dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:background="#color/white"
android:headerDividersEnabled="false"
/>
<ListView
android:id="#+id/right_drawer"
android:layout_width="280dp"
android:layout_height="match_parent"
android:layout_gravity="end"
android:choiceMode="singleChoice"
android:background="#color/white"
android:headerDividersEnabled="false"
/>
</android.support.v4.widget.DrawerLayout>
Edit 3: I restart the ide, and now I get in the activity_main file
Failed to find style 'listViewStyle' in current theme (8 similar errors not shown) "?android:attr/listPreferredItemHeight" in attribute "minHeight" is not a valid format. (Edit) (3 similar errors not shown)
Try this,
Make sure that setContentView is in the onCreate Method, and that all the other required pieces of code are in the method. Here is a basic template to help you out
package com.example.app
import android.app.Activity;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
As mentioned you have deleted all plugins make sure some required plugins are still there in place.
You can check them from Settings > Plugins
It seems android plugins default tasks are missing so make sure you have
apply plugin: 'android'
in your module's build.gradle file.
EDIT(As per the discussion in comments) :
It seems you are using actionbarsherlock in your project make sure you have applied Sherlock theme in your AndroidManifest.xml file
Something Like this :
If you are using style.xml for you theming
In your style.xml
<style name="AppBaseTheme" parent="Theme.Sherlock.Light.DarkActionBar">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<style name="AppTheme" parent="AppBaseTheme">
//other style elements here or leave it blank
</style>
in your AndroidManifest.xml file
<application
android:allowBackup="true"
android:icon="#drawable/logo"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
</application>

Android OpenCV : No resource identifier found for attribute 'camera_id' in package

I have OpenCV and Android set up in my Eclipse. The following is one of my layout files:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:opencv="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<org.opencv.android.JavaCameraView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:visibility="gone"
android:id="#+id/hello"
opencv:show_fps="true"
opencv:camera_id="any" />
</LinearLayout>
The Eclipse compiler complains about:
No resource identifier found for attribute 'show_fps' in package
No resource identifier found for attribute 'camera_id' in package
Please add following resource file in your project's values directory :
attrs.xml
with following content :
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name = "CameraBridgeViewBase" >
<attr name="show_fps" format="boolean"/>
<attr name="camera_id" format="integer" >
<enum name="any" value="-1" />
<enum name="back" value="0" />
<enum name="front" value="1" />
</attr>
</declare-styleable>
</resources>
The two previously given answers to this question, in my opinion, are bandaids to the actual problem. When I encountered this error message, I needed to change some project properties.
Right click project and select Properties
Select 'Android' in the tree control
Make sure the OpenCV library is present and has a green check mark next to it in the 'Library' section (seen in the image below)
If the OpenCV library is not present or has a red X next to it, you need to fix the Library dependency. To do this:
Remove broken library (if necessary)
Click Add and select OpenCV Library
If OpenCV library is not present, you need to add the library to the project
you did not given value for this variables or not declare in opencv class..
opencv {
show_fps="true"
camera_id="any"
}
First assign the those two variables globally with necessary values....

UI doesnt render when i use Navigation Drawer in my android app

i want to use Navigation Drawer in my app. according google documentation here, i write my UI code like this:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- The main content view -->
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" >
MAIN LAYOUT IS HERE
</FrameLayout>
<!-- The navigation drawer -->
<ListView android:id="#+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="#android:color/transparent"
android:dividerHeight="0dp"
android:background="#111"/>
</android.support.v4.widget.DrawerLayout>
this is like google's own example but it gives me an error in layout preview:
Exception raised during rendering: DrawerLayout must be measured with MeasureSpec.EXACTLY.
i searched a lot about it, some people says that you have to put explicit values for android:layout_width and android:layout_height. when i do this everything is going to be OK but i dont want to put explicit values! because i dont know every device width and height... how i can fix that? whats the solution?
i already put android-support-v4.jar file in lib folder. i think its the latest version.
just right click on project >> select android tool >> select add support library .
this should work , just do same steps !

Generate R.Java and Layout - Intellij vs Eclipse

please look at this main.xml -
<TableLayout android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/TableLayout03">
In eclipse its coming out fine, no errors and project is working
In Intellij its stopping my project from generating a R.java class file and if I undo the main.xml to the default, R.java is present and its marking red a host of resource reference.e.g R.layout.main, R.id.myWebSite
What am I doing wrong?
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
İ think you should remove id part.

Categories