Why is android-studio TextView invisible? - android-studio

Why is android-studio TextView invisible after following the Android Studio Tutorial step by step? The Android Studio version is 3.1.4, Include Kotlin Support is checked, and the selected SDK platform API levels are 26, 27, and 28. This is the code for the MainActivity:
package com.example.myfirstapp
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
}
The Hello World! TextView is nowhere to be seen on the Blueprint or Design as can be seen in this screenshot:
The Hello World! is also invisible when running the tutorial app on the emulator.

Just set your appTheme to different one, for example Light. It is a button above your preview

Try this in xml
android:visibility="visible"

Related

class does not implement ActivityResultLauncher AS ArcticFox

I just installed the last version of Android Studio Arctic Fox | 2020.3.1 Canary 3.
When I open my projects, studio shows error for all of the fragments :
Class 'MapsFragment' is not abstract and does not implement abstract base class member public abstract fun <I : Any!, O : Any!> prepareCall(contract: ActivityResultContract<I!, O!>, callback: ActivityResultCallback<O!>): ActivityResultLauncher<I!> defined in androidx.fragment.app.Fragment
is it AS bug?
For some reason this problem happens after core-ktx version 1.3.0-rc01.
You can manage to solve it either by:
downgrading your core-ktx.
implementation 'androidx.core:core-ktx:1.3.0-rc01'
or just add the suitable dependency for the fragment and leave your core-ktx as is
implementation 'androidx.fragment:fragment-ktx:1.3.0-rc02'

viewBinding is not working with error (Android studio 4)

I make android application with kotlin by Android studio 4 (4.11).
findViewById is deprecated in Androd Studio 4 ,then I use viewBinding.
https://developer.android.com/topic/libraries/view-binding
But viewBinding is not working with error.
(path)/MainActivity.kt: (6, 31): Unresolved reference: ActivityMainBinding
Can someone tell me the reason for the error or my mistake?
code is below.
build.grade:
android {
...
// <-- added
buildFeatures {
viewBinding = true
}
// -->
}
res/layout/activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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:id="#+id/viewText" // added.
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" />
</androidx.constraintlayout.widget.ConstraintLayout>
package com.example.myapplication
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
private lateinit var binding: ActivityMainBinding // added. <== error (6:31)
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// <-- added.
binding = ActivityMainBinding.inflate(layoutInflater)
val view = binding.root
binding.textView.text = "Test view binding."
// -->
setContentView(R.layout.activity_main)
}
}
I was also receiving a data binding error when building my project with view bindings enabled. This question and some of the answers may be useful for anyone having this issue with Arctic Fox + Java 11.
After upgrading, I changed the compile options in the app build.gradle entry to:
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
//Required if using new Java 11 language features in your project
I was receiving an error: package not found (*.databinding) and thought that view bindings were not being generated. After trying numerous remedies and finding the generated bindings, I came across the above question. Since I am not using any of the new language features in my project, I changed the compile options in the build.gradle back to:
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
Rebuilt the project and the bindings were all back with no compile errors.
As per teralser's answer, "this issue has been fixed and landed in BB canary 8. It is specific to Java 11".
For devices running Android 4.0 (API level 14) or higher with Android Gradle Plugin 3.0.0+, adding the Java 8 compile options as per link may solve your issue.
One of these might help
Rebuild project (Build->Rebuild Project)
File -> Invalidate Chaches -> Invalidate and Restart
Do this:-
binding = ActivityMainBinding.inflate(layoutInflater)
val view = binding.root
setContentView(view) or setcontentview(binding.root)
binding.textView.text = "Test view binding."
it should work.
Just replace:
setContentView(R.layout.activity_main)
with:
setContentView(binding.root)
Passing your layout separately will inflate the second layout without any view bindings.
More easy solve. Broke the xml. Set space in id or not close tag. ViewBinding recreate broken xml and return xml to correct state.
Very easy to solve. Create a copy of the layout you are applying on the window and use this copied layout from now on, solved.
change the setContentView(R.layout.activity_main) with setContentView(view) or setContentView(binding.root)

Inflating TextView throwing noSuchMethodException on method addFontWeightStyle() during inflate process

Update: I've changed the title to remove the indication that ExoPlayer has anything to do with what is going on as I've managed to duplicate this without it being used at all.
I decided to try and isolate this error on API levels:
I obtained an older Samsung tablet (Tab S2) running Android 7.0 (Api 24), and the error does not occur there.
I am not able to duplicate this problem on a Nexus 6 emulator using API 25
I also tried on a newer Samsung tablet (Tab S3) running Android 8.0.0 (Api 26), the same version as on the Samsung S7 Edge phone. I got the same error.
I then created a new emulator (Pixel 2 XL) running Api 26 (Oreo 8.0.0) and ran the software and got the same error.
I then created a new emulator (Pixel XL) running Api 27 (Oreo 8.1) and ran the software and got the same error.
Lost of frustration trying to verify this on Android 9 - got errors on download of the bundle, Googled to find out many people had to run as Administrator in order to solve this, did that, copied the downloads over to the SDK location I'm using with my normal login, re-started Android under my normal login, patched the SDK per prompt from Studio, and defined an emulator using 9. Got the same error.
Interestingly, in the stack trace using Pie, I got a different line number for where the fail happens in TypefaceCompat - line 47 this time which is at least on the instancing of the relevant class (TypefaceCompatApi28Impl). However then stacktrace is still showing Api21Impl throwing the error. Examining Api28Impl shows me it extends Api26Impl which extends Api21Impl. So it looks like this is simply a matter of the tag not getting reported correctly. Api21Impl is the base class and so that's what is getting reported out.
It still doesn't explain why the error is happening nor what to do about it.
So it would appear at least from this limited testing that there is some issue introduced with Oreo 8.0 that also exists in all SDK's thereafter.
What to do about it?
Update: Some other odd things - my Samsung is API 26 (8.0.0), yet the stack trace below shows Android is attempting to utilize TypefaceCompatApi21Impl:
at androidx.core.graphics.TypefaceCompatApi21Impl.<clinit>(TypefaceCompatApi21Impl.java:74)
That line of code in TypefaceCompatApi21Impl looks like this:
try {
fontFamilyClass = Class.forName(FONT_FAMILY_CLASS);
fontFamilyCtor = fontFamilyClass.getConstructor();
error here---> addFontMethod = fontFamilyClass.getMethod(ADD_FONT_WEIGHT_STYLE_METHOD,
String.class, Integer.TYPE, Boolean.TYPE);
What's odd about this is that further down the stacktrace we see how the *Impl class gets initialized:
The AppCompatTextView.setTypeface() method is called (line 576)
This in turn causes a typeface to get created:
finalTypeface = TypefaceCompat.create(getContext(), tf, style);
When the static method create() is called, this in turn causes a static initializer to be run:
public class TypefaceCompat {
private static final TypefaceCompatBaseImpl sTypefaceCompatImpl;
static {
if (Build.VERSION.SDK_INT >= 28) {
sTypefaceCompatImpl = new TypefaceCompatApi28Impl();
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
sTypefaceCompatImpl = new TypefaceCompatApi26Impl();
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N
&& TypefaceCompatApi24Impl.isUsable()) {
sTypefaceCompatImpl = new TypefaceCompatApi24Impl();
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
sTypefaceCompatImpl = new TypefaceCompatApi21Impl();
} else {
sTypefaceCompatImpl = new TypefaceCompatBaseImpl();
}
}
This line in the stacktrace:
at androidx.core.graphics.TypefaceCompat.<clinit>(TypefaceCompat.java:49)
is actually the line initializing TypefaceCompatApi26Impl(), which would suggest that TypefaceCompatApi26Impl should be used (which makes sense given the API level of my Samsung hardware) and yet the stacktrace shows TypefaceCompatApi21Impl() throwing the error!
How is that possible?
The other clue in here is that a static initializer only runs once. Since I am getting this only after I launch the detail layout (but there are other layouts that also have TextView components on them that appear prior to this), there has to be something associated with this layout that is somehow different. Here are the first few components (up to the first definition of a TextView component) in the layout:
<?xml version="1.0" encoding="utf-8"?>
<!-- This layout is used by PlaylistDetailFragment -->
<androidx.constraintlayout.widget.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:id="#+id/item_listitem_constraint_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Layout related to Playlist 'Header' -->
<androidx.constraintlayout.widget.Guideline
android:id="#+id/guideline1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintGuide_percent="0.25"
android:orientation="vertical" />
<androidx.constraintlayout.widget.Guideline
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintGuide_percent="0.80"
android:orientation="vertical" />
<androidx.constraintlayout.widget.Guideline
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintGuide_percent="0.90"
android:orientation="vertical" />
<androidx.appcompat.widget.AppCompatImageView
android:id="#+id/item_list_content_image"
android:layout_width="0dp"
android:layout_height="0dp"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:layout_marginStart="16dp"
android:layout_marginTop="4dp"
android:background="?android:attr/selectableItemBackground"
android:src="#drawable/playlist"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="#+id/guideline1"
app:layout_constraintBottom_toBottomOf="#+id/playlist_detail_description"/>
<TextView
android:id="#+id/playlist_detail_list_content_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="end"
android:text="#string/playlist_title_label"
android:textAppearance="#android:style/TextAppearance.Material.Small"
app:layout_constraintTop_toTopOf="#+id/playlist_detail_title"
app:layout_constraintBottom_toBottomOf="#+id/playlist_detail_title"
app:layout_constraintRight_toRightOf="#+id/playlist_detail_list_content_description"/>
I thought perhaps the android:textAppearance="#android:style/TextAppearance.Material.Small" line in the TextView definition was causing an issue for some reason, but removing it had no effect - same error is happening.
Update 2/15/19: This just happened again, this time on the same Samsung device where it didn't happen previously, with a completely different layout which doesn't use ExoPlayer at all and in fact just uses stock widgets. In the stack trace below, this line:
at com.reddragon.cloudframe.PlaylistDetailFragment.onCreateView(PlaylistDetailFragment.java:309)
is where I'm inflating a layout:
final View rootView = inflater.inflate(R.layout.playlist_detail, container, false);
The layout includes very standard items (TextView, RecyclerView, Guidelines) etc. Here is the full stack trace:
2019-02-15 06:31:12.287 10895-10895/com.reddragon.cloudframe E/TypefaceCompatApi21Impl: java.lang.NoSuchMethodException
java.lang.NoSuchMethodException: addFontWeightStyle [class java.lang.String, int, boolean]
at java.lang.Class.getMethod(Class.java:2068)
at java.lang.Class.getMethod(Class.java:1690)
at androidx.core.graphics.TypefaceCompatApi21Impl.<clinit>(TypefaceCompatApi21Impl.java:74)
at androidx.core.graphics.TypefaceCompat.<clinit>(TypefaceCompat.java:49)
at androidx.core.graphics.TypefaceCompat.create(TypefaceCompat.java:190)
at androidx.appcompat.widget.AppCompatTextView.setTypeface(AppCompatTextView.java:576)
at androidx.appcompat.widget.AppCompatTextHelper.loadFromAttributes(AppCompatTextHelper.java:217)
at androidx.appcompat.widget.AppCompatTextView.<init>(AppCompatTextView.java:103)
at androidx.appcompat.widget.AppCompatTextView.<init>(AppCompatTextView.java:93)
at androidx.appcompat.app.AppCompatViewInflater.createTextView(AppCompatViewInflater.java:182)
at androidx.appcompat.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:103)
at androidx.appcompat.app.AppCompatDelegateImpl.createView(AppCompatDelegateImpl.java:1267)
at androidx.appcompat.app.AppCompatDelegateImpl.onCreateView(AppCompatDelegateImpl.java:1317)
at android.view.LayoutInflater$FactoryMerger.onCreateView(LayoutInflater.java:189)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:772)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:866)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at com.reddragon.cloudframe.PlaylistDetailFragment.onCreateView(PlaylistDetailFragment.java:309)
at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2530)
at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:887)
at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManagerImpl.java:1233)
at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:1299)
at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:688)
at androidx.fragment.app.FragmentManagerImpl.executeOps(FragmentManagerImpl.java:2069)
at androidx.fragment.app.FragmentManagerImpl.executeOpsTogether(FragmentManagerImpl.java:1859)
at androidx.fragment.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManagerImpl.java:1814)
at androidx.fragment.app.FragmentManagerImpl.execSingleAction(FragmentManagerImpl.java:1691)
at androidx.fragment.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:537)
at androidx.fragment.app.FragmentStatePagerAdapter.finishUpdate(FragmentStatePagerAdapter.java:170)
at androidx.viewpager.widget.ViewPager.populate(ViewPager.java:1244)
at androidx.viewpager.widget.ViewPager.populate(ViewPager.java:1092)
at androidx.viewpager.widget.ViewPager.onMeasure(ViewPager.java:1622)
at android.view.View.measure(View.java:23297)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6928)
at androidx.coordinatorlayout.widget.CoordinatorLayout.onMeasureChild(CoordinatorLayout.java:733)
at com.google.android.material.appbar.HeaderScrollingViewBehavior.onMeasureChild(HeaderScrollingViewBehavior.java:95)
at com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior.onMeasureChild(AppBarLayout.java:1556)
at androidx.coordinatorlayout.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:803)
at android.view.View.measure(View.java:23297)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6928)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at androidx.appcompat.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:143)
Any ideas at all? This is very strange, and extremely frustrating!
It seems that it fails on the first TextView that it tries to inflate, but I can't figure out why this error is occurring. I'm using the same TextView widgets in other layouts of this app, they inflate just fine!
Update 2/13/19: when Googling around for similar issues I found this post. Because it mentioned different behavior on emulator vs. physical, I tested my issue on a physical device (Samsung 7 Edge, Android 8.0.0) and voila - no problem.
EDIT 2/16/19 - but now see comments at the top of this post. I don't know why it didn't happen on my initial test that I describe here I did on 2/13, but the issue is "back" on the Samsung 7 Edge running API 26.
I deleted the previous emulator (Nexus 5, API 27), and created a new one (Nexus 6, API 25) and....no error! Strange, but somehow the emulator got confused I suppose... Still would be good to understand how to troubleshoot these kinds of things faster.
=================================
I have been working on an app (MediaPlayerActivity) using the latest Exoplayer (2.9.5), and have just recently started getting errors when trying to inflate the stock views:
2019-02-12 21:36:43.339 25761-25761/E/TypefaceCompatApi21Impl: java.lang.NoSuchMethodException
java.lang.NoSuchMethodException: addFontWeightStyle [class java.lang.String, int, boolean]
at java.lang.Class.getMethod(Class.java:2068)
at java.lang.Class.getMethod(Class.java:1690)
at androidx.core.graphics.TypefaceCompatApi21Impl.<clinit>(TypefaceCompatApi21Impl.java:74)
at androidx.core.graphics.TypefaceCompat.<clinit>(TypefaceCompat.java:49)
at androidx.core.graphics.TypefaceCompat.create(TypefaceCompat.java:190)
at androidx.appcompat.widget.AppCompatTextView.setTypeface(AppCompatTextView.java:576)
at androidx.appcompat.widget.AppCompatTextHelper.loadFromAttributes(AppCompatTextHelper.java:217)
at androidx.appcompat.widget.AppCompatTextView.<init>(AppCompatTextView.java:103)
at androidx.appcompat.widget.AppCompatTextView.<init>(AppCompatTextView.java:93)
at androidx.appcompat.app.AppCompatViewInflater.createTextView(AppCompatViewInflater.java:182)
at androidx.appcompat.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:103)
at androidx.appcompat.app.AppCompatDelegateImpl.createView(AppCompatDelegateImpl.java:1267)
at androidx.appcompat.app.AppCompatDelegateImpl.onCreateView(AppCompatDelegateImpl.java:1317)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:772)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:866)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:995)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:859)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at com.google.android.exoplayer2.ui.PlayerControlView.<init>(PlayerControlView.java:296)
at com.google.android.exoplayer2.ui.PlayerView.<init>(PlayerView.java:452)
at com.google.android.exoplayer2.ui.PlayerView.<init>(PlayerView.java:304)
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
at android.view.LayoutInflater.createView(LayoutInflater.java:647)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at MediaPlayerActivity$MediaPagerAdapter.instantiateItem(MediaPlayerActivity.java:676)
I'm using the standard stock ExoPlayer views - nothing custom:
Layout from pager_video_item.xml:
<!-- Video Player -->
<com.google.android.exoplayer2.ui.PlayerView
android:id="#+id/video_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"/>
Code from which the error begins, which is in a PagerAdapter instance:
case Media.MEDIA_TYPE_VIDEO:
itemView = mLayoutInflater.inflate(R.layout.pager_video_item, container, false);
mLayoutInflater is initialized in the PagerAdapter constructor:
class MediaPagerAdapter extends PagerAdapter {
final Context mContext;
final LayoutInflater mLayoutInflater;
MediaPagerAdapter(Context context) {
mContext = context;
mLayoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
The context passed is from my MediaPlayerActivity class, which extends androidx.appcompat.app.AppCompatActivity (CFViewPager extends ViewPager, and just adds some logic to handle dispatching touch events appropriately.):
mViewPagerView = findViewById(R.id.activity_media_player_viewpager);
((CFViewPager) mViewPagerView).setAdapter(new MediaPagerAdapter(this));
I can build and run the ExoPlayer demo on my same machine and it works. So clearly I've changed some setting in my app that is confusing the runtime. Again, this used to work perfectly a couple days back.
I've poured over the version control diffs and can't see anything I've introduced that might cause this behavior.
From the stack trace, it looks like it is failing when trying to inflate a TextView in the PlayerControlView. But I don't know how to troubleshoot.
What would cause runtime to think "all of a sudden" that it can't use reflection to find the addFontWeightStyle() method in TypefaceCompatApi21Impl.java?
Android Studio is the latest stable release (3.3.1)
I believe my gradle files are up to date:
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
compileSdkVersion 28
defaultConfig {
applicationId "mycoolapp.com"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
Build tools is set to 28.0.3
I have invalidated caches and restarted, rebuilt, etc.
Thanks for any thoughts about where to look to troubleshoot.
This is a bug already reported to the Android team, and seems to be a fix in place ready for a future release:
https://issuetracker.google.com/issues/124274577
I'm guessing they are referring to a future release of the AndroidX library.

Is JUnit really unable to find my test class in android studio?

I read the solution to How to run a simple JUnit4 test in Android Studio 1.1? and verified my gradle plugin version is greater than 1.1
Right Clicking my junit 4 test class and selecting run gives this error in android studio:
Cannot find class com.me.android.javamodule.MyTestClass
My android proj dir looks like:
In module "app":
src-->main
src-->test-->java-->com.me.android.working contains WorkingTest.java
src-->test-->java-->com.me.android.javamodule contains MyTestClass.java
"javamodule" is a regular java module that the app module depends on, it is a sibling to the "app" module.
I don't think the error is accurate because I copied "MyTestClass.java" into com.me.android.working, which contains WorkingTest.java, a Junit4 test that CAN run. Android Studio still complains with the same error.
Here is MyTestClass.java
package com.me.android.javamodule;
import org.junit.Before;
import org.junit.Test;
public class MyTestClass {
private Solver solver;
#Before
public void init() {
solver = new Solver();
}
#Test
public void testReverse() {
assertTrue(solver.parseStr("woof").equals("foow"));
}
}
This worked for me:
right click src and select New Directory, call it test
do the same for test and call it java
right click java and select New Package to create a new package like com.application. unit test can go here.

Making activity fullscreen in Android 4.0

I've looked for it in many web sites. I wanna make my activity full screen in Android 4.0 (Whole screen with even virtual buttons and bar). There are many solutions even in Stack Overflow. Many of them are ticked as it works. However when I try these solutions, they don't work! I couldn't find where I am making the mistake. I'm giving an example code that was given as answer for my problem (it's worked as they said):
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
public class ActivityName extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// remove title
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
}
}
This isn't enough:
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
In order to accomplish what you want to accomplish, add this:
this.getWindow().getDecorView()
.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
I know this is a rather old question (with a bunch of duplicates), but this is found via Google so I figured I'd still post this solution.

Resources