[enter image description here]
At the top right, next to the zoom buttons a blue warning appears which basically says :
Failed to initiate one or more classes
The following classes could not be instantiated:
android.support.constraint.ConstraintLayout
with exception details:
Exception Details java.lang.NoClassDefFoundError: android/support/constraint/R$styleable android.support.constraint.ConstraintLayout.init(ConstraintLayout.java:599) android.support.constraint.ConstraintLayout.(ConstraintLayout.java:576) java.lang.reflect.Constructor.newInstance(Constructor.java:423) android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730) android.view.LayoutInflater.inflate(LayoutInflater.java:492)
android.view.LayoutInflater.inflate(LayoutInflater.java:394)
And also in the text format of activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
On the tools:context=".MainActivity" line .MainActivity appears in red color saying "Unresolved class MainActivity"
This is my AndroidManifest.xml file :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.kaan.asd">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
I'm new to Android Studio and I've been trying to solve the problem for quite some time now, I have tried clearing caches, clean/rebuild project but neither solved my issue.
I am using the Android Studio 3.3.1 version with gradle version of 4.10.1 on Windows.
I'd appriciate it if anyone could help me fix it.
You have to add the repository of constraint layout in the android directory: app/build.gradle like below:
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
Then sync your project and enjoy this perfect layout.
Related
I want to add a map control to my android app.
To do this I have got the latest xamarin.forms and xamarin.forms.maps packages from Nuget.
My code behind logic does nothing at all, and my axml page looks like as below:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:maps="clr-namespace:Xamarin.Forms.Maps;assembly=Xamarin.Forms.Maps"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<LinearLayout
android:orientation="vertical"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/optionsContainerLinearLayout">
//Other UI elements
<maps:Map>
</maps:Map>
</LinearLayout>
...
</LinearLayout>
Note I've but no tags within maps:Map so as to provide minimal chance for errors. Note that when I populate this map with more properties as directly below, the code still breaks in the same way:
<map:Map
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/mockMapView">
</map:Map>
When I run this application, it breaks on SetContentView() with the error:
Didn't find class "android.view.Map" on path: DexPathList
[[zip file "/system/framework/org.apache.http.legacy.boot.jar", zip file "/data/app/com.geosolve.pavestate2-fJtHBLcT2gY6AlUrxcOOVg==/base.apk"],
nativeLibraryDirectories=[/data/app/com.geosolve.pavestate2-fJtHBLcT2gY6AlUrxcOOVg==/lib/x86, /data/app/com.geosolve.pavestate2-fJtHBLcT2gY6AlUrxcOOVg==/base.apk!/lib/x86, /system/lib]]
I've got another sample xamarin application I downloaded which runs fine on my emulator, so I don't think the emulator is the problem.
I have my API key being used by this other application as well, so I don't think the API key is the problem either.
My androidManifest.xml looks like so:
...
<application android:allowBackup="true" android:icon="#mipmap/icon" android:label="#string/app_name" android:roundIcon="#mipmap/icon" android:supportsRtl="true" android:theme="#style/GeosolveApp">
<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="(My API Key)" />
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
</application>
...
Any help as to why this isn;'t just showing up like you would expect?
For Xamarin.Android,we usually install the Xamarin.GooglePlayServices.Maps package from NuGet.
And add the map in your xaml like:
Declaratively :
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/map"
class="com.google.android.gms.maps.SupportMapFragment" />
Programmatically :
var mapFrag = MapFragment.NewInstance();
activity.FragmentManager.BeginTransaction()
.Add(Resource.Id.map_container, mapFrag, "map_fragment")
.Commit();
the more you could read Google Maps.
I have just started learning development on Android, and I am not able to view "Hellow World!" TextView in the Design Tab.
MainActivity.java:
package com.dummy.demoapp;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.dummy.demoapp">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
The TextView appears in the Component Tree, but the preview of the activity is totally blank:
I tried zooming in, but the TextView is just not there.
[EDIT]: The red exclamation (!) gives me the following message:
And refreshing doesn't solve the problem. Any help?
Go to style.xml and change this:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
to
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
Android Studio sometimes does not appear upto you've success build,
Build->Build&Run, then select your virtual device if there is a helloworld it's okay, it's not your code problem it's related with IDE.
I think it's you default AppTheme with color white , try to add color to TextView
android:textColor="#android:color/black"
Click on the blue icon at the top left corner and then click on force layout. and You will see the Hello World!
I have an android program with 2 layouts. The first layout is Login. When the login is started first, I have no problem. When I try to change in AndroidManifest from login to splash layout, I got an error. The error is like the title of this posts.
In this android manifest, I change my code from :
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
>
<activity
android:name=".Login"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
to :
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
>
<activity
android:name=".Splash"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Here is the layout for login:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:orientation="vertical"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".Login">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Your total is 0"
android:textSize="45dp"
android:gravity="center"
android:id="#+id/tvDisplay"
/>
<Button
android:layout_width="250dp"
android:layout_height="100dp"
android:text="Add One"
android:gravity="center"
android:layout_gravity="center"
android:id="#+id/bAdd"
android:textSize="20dp"/>
<Button
android:layout_width="250dp"
android:layout_height="100dp"
android:text="Substract One"
android:gravity="center"
android:layout_gravity="center"
android:id="#+id/bSub"
android:textSize="20dp"/>
And here the layout of splash:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:background="#drawable/sertifikat"
tools:context=".Splash"></LinearLayout>
And structure of my code :
Log in logcat:
Here splash.java
How can I fix my code?
Hey You missed some small things
Here is a small example from your code
on Github that i wrote
This is running example of your code
Other than the ending tags
The <intent-filter>
should only be one
most probably the problem lies in your #drawable
as well as look at these tutorials they are great
http://www.androidhive.info/2013/07/how-to-implement-android-splash-screen-2/
Obviously,you have lost a character '/' in the splash layout at the end.
You are missing the closing tag of your LinearLayout in splash.xml. Add </LinearLayout> to the end of the file. You also might want to consider using an ImageView with android:scaleType="centerCrop" instead of using a LinearLayout with a background. Using android:background will stretch to fit the size of the screen, which can give a different aspect ratio on different devices, whereas an ImageView will scale it to maintain the aspect ratio (depending on the scaleType).
Also, a LinearLayout is not appropriate for a single image, since it is meant to be a container for other views.
For better performance I recommend you to follow this :
http://www.cutehacks.com/blog/2014/01/13/splash-screens
If you use an high end device you won't see a big difference, but for common devices you will see an huge improvement
I just downloaded and started learning android L material design api. Whenever I use CardView in my activity it gives me this error Failed to find style with id 0x7f070001 in current theme.
This is my xml layout :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res/com.flip.tesla"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.flip.tesla.MainActivity$PlaceholderFragment" >
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="200dp"
app:cardElevation="10dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World"
android:textSize="15sp" />
</android.support.v7.widget.CardView>
</RelativeLayout>
And this is my manifest file :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.test"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
and this is the exact message it displays :
Missing styles.
Is the correct theme chosen for this layout?
Use the Theme combo box above the layout to choose a different layout, or fix the theme style references.
Failed to find style with id 0x7f070001 in current theme
EDIT : So I restarted eclipse this is the new message it displays.
Exception raised during rendering: com.android.layoutlib.bridge.MockView cannot be cast to android.view.ViewGroup
Exception details are logged in Window > Show View > Error Log
The following classes could not be instantiated:
- android.support.v7.widget.CardView
any ideas on what it means?
It's an issue related with Gradle sync. Try clicking the refresh button in the toolbar
Try running the application and see if it shows the output
put android.support.v7.widget.CardView as your parent layout instead of RelativeLayout,
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
card_view:cardCornerRadius="4dp" >
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:orientation="vertical"
android:weightSum="100" >
try to use this code in your activity style
<style name="StyledIndicators" parent="#android:style/Theme.Light">
<item name="vpiCirclePageIndicatorStyle">#style/CustomCirclePageIndicator</item>
</style>
<style name="CustomCirclePageIndicator">
<item name="fillColor">#000000</item>
<item name="strokeColor">#000000</item>
<item name="strokeWidth">1dp</item>
<item name="radius">6dp</item>
<item name="centered">true</item>
</style>
see this link failed-to-find-style-vpicirclepageindicatorstyle
This solution worked for me:
Go to File -> Invalidate Caches / Restart and click on Invalidate and Restart.
Go to Build> Rebuild Project
I have been reading Google's android tutorial and I got a problem... In the tutorial they explain the XML elements (EditText and Button) and in the end they say how to tun the program to see the button + the text field.
The problem is, that the emulator doesn't show them.. just a black screen.
I even tried adding this line to the onCreate function -
System.out.println("Hello World!");
but still the emulator is showing only black screen..
Here's the .java main file - http://pastebin.com/G5J9YjNe
And the XML files (I mentioned what code is what file) - http://pastebin.com/VnRwAfMW
What should I do?
Thanks a lot for everyone who will help!
System.out.println("Hello World!");
does not print any thing on screen. it can seen on Consol. i tried below code and working fine for me.
// Main Activity
public class MainActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.kuchbhi);
System.out.println("Hello World!");
}
Layout /.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<EditText android:id="#+id/text_message"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="enter text" />
<Button android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Send" />
</LinearLayout>
Manifest file ..
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name="MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
try this code and let me know what u see.
I tried your source code and it is working fine for me. see screen