so I just recently started to develop Android applications via Xamarin and I am struggling a LOT.
I created my application like this(in Visual Studio 2017 Community edition):
New Project -> Visual C# -> Android -> Android App(Xamarin) -> Tabbed App(Android version 5.0).
Then I drag ImageView anywhere on the screen.I try to run it and it crashes with the exception:
Unhandled Exception:
Android.Views.InflateException: Binary XML file line #1: Binary XML file line #1: Error inflating class android.support.design.widget.BottomNavigationView
What I tried:
1) doing this in new Visual studio version - 2019.
2) Putting this in a blank app - it does work, but I need the tabbed page functionality for my app, so that's not an option.
Any tips & tricks are appreciated.Here are the images to visualize it.
Code line where it crashes
This is how it looks from the designer perspective.
Error from designer window
MainActivity.cs:
using Android.App;
using Android.OS;
using Android.Runtime;
using Android.Support.Design.Widget;
using Android.Support.V7.App;
using Android.Views;
using Android.Widget;
namespace App10
{
[Activity(Label = "#string/app_name", Theme = "#style/AppTheme", MainLauncher = true)]
public class MainActivity : AppCompatActivity, BottomNavigationView.IOnNavigationItemSelectedListener
{
TextView textMessage;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Error on this line.
SetContentView(Resource.Layout.activity_main);
textMessage = FindViewById<TextView>(Resource.Id.message);
BottomNavigationView navigation = FindViewById<BottomNavigationView>(Resource.Id.navigation);
navigation.SetOnNavigationItemSelectedListener(this);
}
public bool OnNavigationItemSelected(IMenuItem item)
{
switch (item.ItemId)
{
case Resource.Id.navigation_home:
textMessage.SetText(Resource.String.title_home);
return true;
case Resource.Id.navigation_dashboard:
textMessage.SetText(Resource.String.title_dashboard);
return true;
case Resource.Id.navigation_notifications:
textMessage.SetText(Resource.String.title_notifications);
return true;
}
return false;
}
}
}
Then I drag ImageView anywhere on the screen.I try to run it and it crashes with the exception:
After testing , I found that this is not your problem, this should be a bug for VS.
Solution:
After modify axml file, you need to clean project, then rebuild it. This error will not happen.
Clean Solution -> Build Solution can solve it.
Related
This code is for a button that would be on the android emulator. However, when I place this code in the main activity.kt it gives me multiple errors. The first error I experience is a redeclaration error on line 9 on the main activity
package com.example.android.justjava
import android.R
import android.os.Bundle
import android.support.v7.app.ActionBarActivity
import android.view.View
import android.widget.TextView
// This activity displays an order form to order coffee.
class MainActivity : ActionBarActivity() {
protected fun onCreate(savedInstanceState: Bundle) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
// this method is called when the order button is clicked.
fun submitOrder(view: View) {
display(1)
}
// This method displays the given quantity value on the screen.
private fun display(number: Int) {
val quantityTextView = findViewById(R.id.quantity_text_view as TextView
quantityTextView.text = "" + number
}
}
This activity displays an order form to order coffee.
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
// This method is called when the order button is clicked.
public void submitOrder(View view) {
display(1);
}
// This method displays the given quantity value on the screen.
private void display(int number) {
TextView quantityTextView =(TextView) findViewById (R.id.quantity_text_view);
quantityTextView.setText("" + number);
}
}
File tab -> Invalidate Caches/Restart (then choose invalidate and restart from the dialog that will appear)
Build tab -> Clean Project
Build tab -> Rebuild Project
This solution is just the same as #Ehsan_Haghdoust solution but letting Android Studio do that for me instead of doing that my self.
The question is for 6 months ago, but I write my answer for others face this problem in the future. I have had challenge with this error, I checked every possible way suggested by others and I FINALLY had to delete build folders in
projectFolder/
and
projectFolder/app/
manually and rebuild the project again.
The problem you face is that you have 2 activities with the same name MainActivity - one in Java, and second in Koltin. Both classes (activities in this case) are compiled into the same application - you have 2 symbols with the same name.
yes, Koltin and Java look the same after the compiler finish with them :)
In my case, I was running the app in debug mode and a direction class was generated for debug. Then I tried generating a signed APK in release mode. Then a similar class was generated in same package for release mode which caused the issue. I manually deleted just the debug folder in the Java folder(root) and the build was successful.
Build -> Select Build Variant. It was in debug, I just changed it to release mode and done.
I am trying to change photos in android studio by clicking on my button.
When I put code for changing the photo in my MainActivity.java I keep getting this type of error messages and it says :
Cannot resolve symbol "image"
image.setImageResource(R.drawable.xxx);
I am watching Udemy course for android development and I have done everything same like the professor on that video.
I have tried to restart android studio.
I have tried to make new project.
I have tried to clear invalidate caches and restart.
public void changeImage(View view)
{
ImageView bitcoin = findViewById(R.id.bitcoin);
image.setImageResource(R.drawable.xxx);
}
I hope there is actual error with android studio,because code is clone of the video that I am watching.
You are binding your layout's ImageView in Java file with bitcoin variable and you are trying to set an image on an unknown variable 'image'(maybe it's not defined in the class). So you have to set as below.
ImageView bitcoin = findViewById(R.id.bitcoin);
bitcoin.setImageResource(R.drawable.xxx);
Set Your Code Like this
ImageView image = findViewById(R.id.bitcoin);
image.setImageResource(R.drawable.xxx);
change your this line
image.setImageResource(R.drawable.xxx)
to this one:
bitcoin.setImageResource(R.drawable.xxx)
This is a strange one! On my old desktop, I was able to build and run my libGDX project for HTML5 using the gradlew html:dist gradle command.
I uploaded the files to my site and everything worked well.
But on my laptop I synced the project via GitHub to Android Studio, ran the same command and it appears that the default ApplicationListener runs instead of my own custom one.
The only thing that appears is a red rectangle: http://johnathongoss.com/jaggybattles/
The desktop and android versions run and build fine on my laptop.
I'm using Android Studio and the latest version of libGDX.
Here is some code:
public class HtmlLauncher extends GwtApplication {
#Override
public ApplicationListener createApplicationListener() {
return new MyGame();
}
#Override
public GwtApplicationConfiguration getConfig () {
GwtApplicationConfiguration cfg = new GwtApplicationConfiguration(1280, 720);
return cfg;
}
}
//MyGame Class (Doesn't seem to get this far?)
#Override
public void create() {
camera = new OrthographicCamera(VIRTUAL_WIDTH, VIRTUAL_HEIGHT);
setScreen(new LoadingScreen(this)); //Loads the assets and sets Main Menu Screen
}
I've had this problem before but it was because I didn't change the createApplicationListener() method to return my own custom ApplicationListener. Now it seems to return the right one, I really don't know what could be causing this.
I should point out I can't access my desktop computer anymore due to relocating.
Any advice would be gratefully received!
Edit: Loading Class
https://gist.github.com/jaggygames/79b1bd821f4203aadecfe5e8ba925150
Assets Class:
https://gist.github.com/jaggygames/5b863f1692b0974b769d5694b5a3334f
MyDistance Font Class
https://gist.github.com/ea7b5965488cd5672e9e7c20917df9a1
Well For Showcase View
I using this:
https://github.com/amlcurran/ShowcaseView
After importing files it gives error. this is my errors and improted .jar files
Errors says
in java
R cannot be resolved to a variable
in style
error: Error retrieving parent for item: No resource found that matches the given name 'Theme.Sherlock.Light'.
again, in style
error: Error: No resource found that matches the given name: attr 'android:fontFamily'.
Also Are there any tutorial to use Showcase view in my project. I can not find and I didnt understant from github project. it is not clear.
This library works Awesome for all. How it works?? i want to highlight a toolbar option. Now just add the library and write code like this.
you can use multiple showCaseView using this code
1 add Library in our Gradle.build
implementation 'com.github.mreram:ShowCaseView:1.0.5'
simple call this method with pass title, Description Text, view or view Id and Type
ShowIntro("SetTheme", "Select Theme and Apply on your video", R.id.button_tool_theme, 1);
method create like this
private void ShowIntro(String title, String text, int viewId, final int type) {
new GuideView.Builder(this)
.setTitle(title)
.setContentText(text)
.setTargetView((LinearLayout)findViewById(viewId))
.setContentTextSize(12)//optional
.setTitleTextSize(14)//optional
.setDismissType(GuideView.DismissType.targetView) //optional - default dismissible by TargetView
.setGuideListener(new GuideView.GuideListener() {
#Override
public void onDismiss(View view) {
if (type == 1) {
ShowIntro("Editor", "Edit any photo from selected photos than Apply on your video", R.id.button_tool_editor, 6);
} else if (type == 6) {
ShowIntro("Duration", "Set duration between photos", R.id.button_tool_duration, 2);
} else if (type == 2) {
ShowIntro("Filter", "Add filter to video ", R.id.button_tool_effect, 4);
} else if (type == 4) {
ShowIntro("Add Song", "Add your selected song on your video ", R.id.button_tool_music, 3);
} else if (type == 3) {
ShowIntro("Overlay", "Add your selected overlay effect on your video ", R.id.button_tool_overlay, 5);
} else if (type == 5) {
SharePrefUtils.putBoolean("showcase", false);
}
}
})
.build()
.show();
}
Here for this I am using this library
https://github.com/amlcurran/ShowcaseView
This library works really great. How it works??
Suppose i want to highlight a menu option. Now just add the library and white this code.
Toolbar toolbar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.inflateMenu(R.menu.menu_main);
setSupportActionBar(toolbar);
ViewTarget target = new ViewTarget(toolbar.findViewById(R.id.menu_id_launcher));
new ShowcaseView.Builder(this)
.setContentTitle("Its My Navigation Drawer")
.setContentText("Click here and you will get options to navigate to other sections.")
.useDecorViewAsParent() //this is the difference
.setTarget(target)
.build();
}
and finally you have to make your menu show always like this
<item
android:id="#+id/menu_id_launcher"
android:orderInCategory="100"
android:icon="#mipmap/ic_launcher"
android:title="#string/action_settings"
app:showAsAction="always" />
Now just run the app i think this will works perfectly.
I usually use another library for showcase views. It creates bubbles instead of concentric circles but it works really well. Maybe it is also useful for your requirements and with this one you don't have importing problems.
You just have to add 'implementation 'com.elconfidencial.bubbleshowcase:bubbleshowcase:1.3.0' in your build.gradle file of your app and synchronize your project.
It works similar to ShowCaseView library:
BubbleShowCaseBuilder(this) //Activity instance
.title("foo") //Any title for the bubble view
.targetView(view) //View to point out
.show() //Display the ShowCase
Source https://github.com/ECLaboratorio/BubbleShowCase-Android
The sample you use needs the ActionBarSherlock Library, you can read it in the instructions from the github page: "To use the sample download ActionBarSherlock and add it as a dependency to the library project. Use point 1 on the "Including in your project" instructions at the link."
download ActionBarSherlock and import it (only the library, you don't need the samples)
right click to your SampleActivity project and choose Properties
choose Android, click Add and include the ActionBarSherlock project
Then the style errors will go away and R can be built.
import, add actionbarsherlock library
android:fontFamily minSDK is 16, or delete this
project -> clean all
I am new to android development and just started working on a web app using cordova, ionic framework and angular. I have completed the basic features of the app and found that the transitions between views in the app are a bit slow
I found this article to improve them here:
https://github.com/ajoslin/angular-mobile-nav/wiki/PhoneGap,-improving-performance
I have never coded in java and so I am stuck.
I tried doing the following
went to the cordovawebview.java in the path myapp\platforms\android\CordovaLib\src\org\apache\cordova and added the import statements missing in the file (except for the "import org.apache.cordova.CordovaWebView")
which were using in the article and copy-pasted the myWebview class.
Then I went to the StarterApp.java, below path
\myapp\platforms\android\src\com\ionicframework\starter
and modified it to
public class StarterApp extends CordovaActivity
{
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
CordovaWebView webView = new MyWebView(MyActivity.this);
super.init(webView, new CordovaWebViewClient(this, webView), new CordovaChromeClient(this, webView));
// Set by <content src="index.html" /> in config.xml
super.loadUrl(Config.getStartUrl());
//super.loadUrl("file:///android_asset/www/index.html")
}
}
But when I run the cordova build command I am getting a error. Could someone tell me, what I am missing?
This looks incorrect to me:
CordovaWebView webView = new MyWebView(MyActivity.this);
Have you written code for MyWebView?
MyActivity doesn't seem to exist. You can just use this.