I've been following a step by step tutorial trying to create a map using Mapbox and Android Studio using the 'Tracking Device Location on Android" tutorial but have run into a problem that doesn't seem to be outlined on Mapbox.
In the 'Listen to Updates' section of the tutorial, on line 176 of the code it reads:
Toast.makeText(activity, String.format(activity.getString(R.string.new_location)
new_location shows up in red and has not been defined beforehand. Does anyone know how to fix this?
https://docs.mapbox.com/help/tutorials/android-location-listening/#listen-to-location-updates
If you want to get it running, you would have to follow Ryan's advice (comment) and add the string he has highlighted from Mapbox' activity_strings.xml into your strings.xml.
<string name="new_location">New lat: %1$s New longitude: %2$s</string>
%1$s will be populated with the first parameter you pass and %2$s with second parameter you pass in
String.format(activity.getString(R.string.new_location),
String.valueOf(result.getLastLocation().getLatitude()),
String.valueOf(result.getLastLocation().getLongitude()))
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)
When I was printing java code in Eclipse, the way of printing was WYSIWYG. So if I folded some selected sections (for example import section, but also any other foldable section), it was printed as folded.
In Android Studio code is printed allways fully unfolded. Does anybody know some way (plugin or some preferences setting etc.), how to set it to print also in the folding WYSIWYG style?
My problem is that I have done the printing part in android device when the printer is already configured on the device.
If the printer is not configured on the device, the exception occurs can you tell that how u know that printer is configured on device
e1=(EditText) findViewById(R.id.editText);
String name=e1.getText().toString();
PrintManager printManager=(PrintManager) this.getSystemService(Context.PRINT_SERVICE);
//PrintDocumentAdapter printAdapter = view.createPrintDocumentAdapter();
//Toast.makeText(getApplicationContext(),"hi nikhil"+name+""+printManager.getPrintJobs(),Toast.LENGTH_LONG).show();
String text=this.getString(R.string.app_name)+"Document";
// printManager.getPrintJobs();
printManager.print(text, new MyPrintDocumentAdapter(this), null);
Log.d("print", "print" + printManager);
on Android-Studio 4.0, I noticed that you can select the parts of a file you wish to print, and in the print dialog box, it will allow you to just print the selection. This isn't exactly what you're looking for, but it is a way to bypass the long lines of import statements and comments at the head of a file.
Situation:
I have a TextView that have the property
android:textAlignment="center"
I am generating another TextView dinamically, based on my TextView from XML Layout, using a clone, cloning all the basic properties to work the way above.
Problem:
To do this i need to use this method:
this.myTextView.setMyTextViewProperty(MyTextView.getMyTextViewProperty());
for example:
this.MyTextView.setText(MyTextView.getText());
Note that this.MyTextViewis a local variable and MyTextView is a private var declared on the top of the file, under class name.
I do this on all the properties of the TextView but when i hit the following line of code from the TextAlignment property...:
this.myTextView.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
I tried to set it to a Custom Aligment instead of getting from my XML TextView It gives me an error:
11-20 15:27:04.460: E/AndroidRuntime(9185): FATAL EXCEPTION: main
11-20 15:27:04.460: E/AndroidRuntime(9185): java.lang.NoSuchMethodError: android.widget.TextView.setTextAlignment
But i see on Ctrl + Space that the method exists, so i cant understand what is happening.
A second try was, to set my TextView property to the property that comes from my TextView:
this.myTextView.setTextAlignment(MyTextView.getTextAlignment());
With no success, too.
Obs: i do not want a Android XML Layout solution, i want a solution on code, because i generate the TextView dinamically on the Activity
I'm using API Level 15
Any help?
The setTextAlignment method was added in API level 17. Maybe your compiler in the IDE is above 17 and the device/emulator which you are testing is less than that. Here the link to setTextAlignment.
Added from the comments:
For API level 15 and below, you want setGravity, per this question.
I'm trying to use a font I found on the internet, but the problem is that I get an FC with "native typeface cannot be made".
Here is the code in the getView of my ListVIew:
holder.tv_SuraName =(TextView)convertView.findViewById(R.id.Start_Name);
holder.tv_SuraName.setTypeface(Typeface.createFromAsset(mContext.getAssets(), "suralist_font.ttf"));
Can anyone tell me why can I use the custom rom? You can get it HERE .. the file is .ttf
My problem was incorrect placement of the assets folder.
When using Android Studio the assets folder should be inside of the source sets e.g.
src/main/assets/
Found in this answer
The font file is either corrupt or unsupported for some reason. You can drop it on the SD card and load it from file, to make sure it's not a problem with your assets.
There are basically 4 things that can cause this:
You use the wrong extension
You have to place the fonts in the assets folder and not inside assets/fonts/
You misspelled the fonts
The fonts need to be lowercase (in my case the solution was to rename MyFont.ttf to myfont.ttf, strange)
Double check the extension isn't in caps, ie. suralist_font.TTF
Fonts often come seem to come that way and it might be overlooked.
I had this same problem, I created mine in assets>fonts>whatever.ttf and was getting the same error. I added the fonts extension (fonts/whatever.ttf) and it fixed the problem in every case.
holder.tv_SuraName =(TextView)convertView.findViewById(R.id.Start_Name);
holder.tv_SuraName.setTypeface(Typeface.createFromAsset(mContext.getAssets(), "fonts/suralist_font.ttf"));
Rather old thread, but I want to add one more reason this can happen: You have to set the content view before calling typeface. See example below
Does not work:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView title = (TextView)findViewById(R.id.tvTitle);
Typeface font = Typeface.createFromAsset(this.getAssets(), "fonts/whatever.ttf");
title.setTypeface(font);
setContentView(R.layout.main);
}
Does work!
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main); // <-- call before typeface
TextView title = (TextView)findViewById(R.id.tvTitle);
Typeface font = Typeface.createFromAsset(this.getAssets(), "fonts/whatever.ttf");
title.setTypeface(font);
}
I am using android studio, in my case problem was with the path of assets folder, in Eclipse path for assets folder is res/assets/ but in Android Studio its src/main/assets/
So, i just move my font file to this path and finally problem solved.
Either your font file is corrupt else you making some mistake in spelling while calling your file name. I had same issue, it was because file name specified in asset folder was
roboto_black.ttf
and while declaring in java file, i have been spelling it as:
roboto_blak.ttf
If your .ttf files are in asset folder,then use:
Typeface type_bold = Typeface.createFromAsset(getAssets(), "roboto_black.ttf");
Else if it is in fonts folder, then use:
type_bold = Typeface.createFromAsset(getAssets(), "fonts/roboto_black.ttf");
Hope it helps!
Hope this will help
Typeface.createFromAsset leaks asset stream: http://code.google.com/p/android/issues/detail?id=9904
As CommonsWare states in this answer
I would guess that there is a problem with the font itself. That error
will be triggered when native code in the OS attempts to load the
typeface.
Anyway try this one:
holder.tv_SuraName = (TextView)convertView.findViewById(R.id.Start_Name);
Typeface Font = Typeface.createFromAsset(this.getAssets(),"suralist_font.ttf");
holder.tv_SuraName.setTypeface(Font);
I had the same problem with COMIC.TTF from comic sans ms of Windows.
Since the original file I placed in assets/fonts folder was in uppercase as spelt above, I had to type it exactly in uppercase.
Typeface.createFromAsset(getAssets(), "fonts/COMIC.TTF");
it turns out the problem was caused by the lower case:
Typeface.createFromAsset(getAssets(), "fonts/comic.ttf");
Please note that this is due to either a corrupt file or you have placed the file in the wrong folder.
According to Android documentation here
main/assets/
This is empty. You can use it to store raw asset files. Files that you save here are compiled into an .apk file as-is, and the original filename is preserved. You can navigate this directory in the same way as a typical file system using URIs and read files as a stream of bytes using the AssetManager. For example, this is a good location for textures and game data.
Therefore your folder structure should be yourmodule/main/assets (e.g. a***pp/main/assets*** )
What worked for me was first changing my font name to only lower case and underscore: from Amatic-Sc.ttf to amatic_sc.ttf.
Then in the set.TypeFace method change assets/fonts/amatic_sc.ttf to just fonts/amatic_sc.ttf.
I've been debugging forever on this error in Android Studio. Clean and rebuilding the project after adding the fonts to the assets directory fixed the issue for me.
Just did a build --> clean and it started rendering .
I had same issue which happened on Android 4.0.3-4.0.4 (100% reproducible on emulator IceCreamSandwich mips 4.0.3).
The problem was that TTF fonts, that I had, were not correct, despite almost all Android versions were able to load those TTF font. So I used https://cloudconvert.com/woff-to-ttf (since I had woff files as well) to make new TTF fonts, which solved my problem.