how to do junit testing in android - android

i am new to android and i want to do a junit testing in android then i followed this code from android site
i am getting many errors
as HelloAndroid cannot be resolved to a type
Multiple markers at this line
- HelloAndroid cannot be resolved to a type
- The constructor ActivityInstrumentationTestCase2(Class) refers to the missing type
HelloAndroid
Multiple markers at this line
- The method getActivity() from the type ActivityInstrumentationTestCase2 refers to the missing type
HelloAndroid
- HelloAndroid cannot be resolved to a type
Multiple markers at this line
- HelloAndroid cannot be resolved to a type
- com.example.helloandroid.R cannot be resolved to a
variable
package com.example.helloandroid.test;
import android.test.ActivityInstrumentationTestCase2;
import android.widget.TextView;
public class HelloAndroidTest extends ActivityInstrumentationTestCase2<HelloAndroid> {
private HelloAndroid mActivity; // the activity under test
private TextView mView; // the activity's TextView (the only view)
private String resourceString;
public HelloAndroidTest() {
super("com.example.helloandroid", HelloAndroid.class);
}
#Override
protected void setUp() throws Exception {
super.setUp();
mActivity = this.getActivity();
mView = (TextView) mActivity.findViewById(com.example.helloandroid.R.id.textview);
resourceString = mActivity.getString(com.example.helloandroid.R.string.hello);
}
public void testPreconditions() {
assertNotNull(mView);
}
public void testText() {
assertEquals(resourceString,(String)mView.getText());
}
}
can anyone help me

Too little space in the comments to show you my point...
One of the things you're missing (seeing your code) is the import section:
Your import section:
import android.test.ActivityInstrumentationTestCase2;
import android.widget.TextView;
Tutorials import section:
import com.example.helloandroid.HelloAndroid;
import android.test.ActivityInstrumentationTestCase2;
import android.widget.TextView;
Also the tutorial says:
This tutorial and its code depend on the Hello World tutorial. If you
haven't completed that tutorial already, do so now. You will learn the
fundamentals of Android application development, and you will have an
Android application that is ready to be tested. The tutorial guides
you through the setup of an Android test project using the ADT Plugin
for Eclipse and other SDK tools. You will need an SDK development
platform that is version 1.5 (API level 3) or higher.
Make sure you have completed this tutorial first. Compare your HelloAndroid class with the final version in the HelloWorld tutorial. Happy coding!

I tried the same example it worked for me
I guess in the code
public HelloAndroidTest() {
super("com.example.helloandroid", HelloAndroid.class);
}
instead of HelloAndroid.class you should put the class name in my case it was MainActivity
I changed it to MainActivity.class and it worked
Check for the class you are testing and change the <HelloAndroid> to the class name i.i MainActivity

Related

Android studio project could not find android.view.View

My Android project show that it is not able to find the android.view.View class but still it is being compiled and run on simulator and devices.
apart from android.view.View All other class of the package is accessible like
This is not available ==> import android.view.View;
this is available => import android.view.ViewGroup;
I have tried many things like Clean, Rebuild, restart and Invalidate cache and restart but not fixed this issue.
Please check the code and help me to fix this issue.
import android.view.View;
public class AppSettingsActivity extends BaseActivity implements View.OnClickListener, AdListener {
//Other objects
private static final String TAG = AppSettingsActivity.class.getSimpleName();
//Data objects
// //Design
private LinearLayout banner_container;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
initViews();
}
private void initViews() {
//Actionbar init
//Action bar
TextView idTvTitle = findViewById(R.id.idTvTitle);
findViewById(R.id.idTvSelectDefaultActivity).setOnClickListener(this);
findViewById(R.id.idTvSelectAppLang).setOnClickListener(this);
findViewById(R.id.idIvBack).setOnClickListener(this);
findViewById(R.id.idTvCalcSetting).setOnClickListener(this);
//Set data
//Set Actionbar Title
idTvTitle.setText(R.string.app_settings_text);
//Load Facebook ads
banner_container = findViewById(R.id.banner_container);
if (fbAdView != null) {
banner_container.addView(fbAdView);
fbAdView.loadAd();
fbAdView.setAdListener(this);
logs.e(TAG, "Face book load add called....");
}
int selectedLanguage=SessionManagement.getIntValue(AppSettingsActivity.this, AppConstant.SELECTED_LANG, AppConstant.INT_ONE);
int selectedScreen=SessionManagement.getIntValue(AppSettingsActivity.this, AppConstant.DEFAULT_SCREEN_INDEX, AppConstant.INT_ONE);
String[] languages = getResources().getStringArray(R.array.language);
String[] screens = getResources().getStringArray(R.array.screens);
((TextView)findViewById(R.id.idTvSelectDefaultActivity)).setText(screens[selectedScreen]);
((TextView)findViewById(R.id.idTvSelectAppLang)).setText(languages[selectedLanguage]);
}
I am giving this answer to my question.
I simply uninstall the Android studio and reinstall it. My previous Android studio was running with 3.5 version (Latest) and the fresh install Android studio version was also 3.5 so there was no versioning difference in it. But I don't know some How issue fixed when I reinstall AS.
After half an hour of searching, I could not found a solution that can fix my issue. Then I pass the same code to other PC and it was working well on that PC.
So This is final that no issue in the source code.
Then 2nd suspect is the android studio
I uninstall Android Studio and install it again, it took me 1 hour to set-up and make the code workable but it saves 30GB of my hard disk space so it was worth it.
But still, Android studio manage SDK and build tools very badly

AS3 Class Error gotoAndPlay(33)

i´m trying to add admob ane to my game but i´m getting an error.
My error is this, when i import the class i got and erro in my project with the gotoAndPlay(33);
how can i define into class this gotoAndPlay(33); to stops error.
i´m using this package
package
{
import flash.display.Sprite;
import so.cuo.platform.admob.Admob;
import so.cuo.platform.admob.AdmobPosition;
public class SimpleDemo extends Sprite
{
public function SimpleDemo()
{
super();
var admob:Admob= Admob.getInstance();
if(admob.supportDevice){
admob.setKeys("your banner id ");
admob.showBanner(Admob.BANNER,AdmobPosition.BOTTOM_CENTER);
}
}
}
}
So, i don´t know how to declare this gotoAndPlay(33) event in the class.
Since now thanks to all!
Sounds like somewhere your code is trying to use SimpleDemo like it's a movie clip.
To give SimpleDemo all the powers of a MovieClip, make it extends that class
public class SimpleDemo extends MovieClip
instead of extending Sprite which doesn't have timeline functionality.
Now SimpleDemo will have all the MovieClip Methods, like gotoAndPlay.
If SimpleDemo is set as the class file for your document class (or a library object that has more than one frame or code on a frame), then you MUST extend MovieClip (though for the document class it CAN extend Sprite or DisplayObjectContainer if no timeline code or additional frames are used).

Android cordova chromeview : Not implemented reached in virtual quota::SpecialStoragePolicy

I'm working on a phonegap project which contains a canvas overlayed with kinetic.js, which allows a user to pinch zoom and pan around an image, then draw annotations on it. it works spliendidly in a browser and on windows and apple tablets, but of course android is a good bit slower.
as a solution, i've released the app using https://github.com/thedracle/cordova-android-chromeview. after switching my main java class to use ChromeView as the webview, i'm getting this error on startup:
12-03 13:21:09.083: E/chromium(13917): [ERROR:aw_browser_context.cc(191)] Not implemented reached in virtual quota::SpecialStoragePolicy* android_webview::AwBrowserContext::GetSpecialStoragePolicy()
after debugging through the codebase, it looks like the error is triggering here:
private void setNativeContentsClientBridge(int nativeContentsClientBridge) {
mNativeContentsClientBridge = nativeContentsClientBridge;
}
(AwContentsClientBridge.java line 36).
i'm trying to find out what the nativeContentsClientBridge int is. My value is 1611312352 but i haven't a notion of what that represents.
my gut feel is that the chromium browser is missing an implementation for accessing localstorage. i found this bug:
https://github.com/pwnall/chromeview/issues/27
where someone is experiencing the same thing, but there is no solution.
for assistance, this is my main activity class:
package com.companion;
import org.apache.cordova.Config;
import org.apache.cordova.CordovaActivity;
import us.costan.chrome.ChromeSettings;
import us.costan.chrome.ChromeView;
import android.os.Bundle;
public class CompanionApp extends CordovaActivity
{
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState)
{
ChromeView chromeView = new ChromeView(CompanionApp.this);
ChromeSettings settings = chromeView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setDatabaseEnabled(true);
settings.setDomStorageEnabled(true);
setContentView(chromeView);
super.loadUrl(Config.getStartUrl());
}
}
Thanks for your help,
Margaret
Don't know if it's normal, but it seems that a method's not implemented in Chromium base code : https://github.com/01org/pa-chromium/blob/master/android_webview/browser/aw_browser_context.cc
Here's that particular method:
quota::SpecialStoragePolicy* AwBrowserContext::GetSpecialStoragePolicy() {
// TODO(boliu): Implement this so we are not relying on default behavior.
NOTIMPLEMENTED();
return NULL;
}
I hope it helps :)

Error from import android.R or from layout.main?

I keep either removing import.R or adding mypackage.R or deleting all imports and shift-control O
or deleting R.java.
I still get the error: main.xml cannot be resolved or alternately, R cannot be resolved to a variable. I have cleaned each time. How do you get this to work?
package com.hga;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
public class Hga extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView( R.layout.activity_hga );
Yeah i used to run into those type of problems when i was starting programing for android. The R folder updates itself everytime code is written or saved and when a error occurs in your code for whatver reason it may be the R folder gives you that error report. At first clean but if that doesnt work as it usually wont you want to completely coment out your code /* .... */
then clean and the error should go way now you can pin point which bit of code is causing the error to occur in the R folder.
PS. this was my main source of frustration in coding android apps

Issue observed with Android app developed using phonegap

I have developed Android applicationusing Phonegap framework with Eclipse pulgin. am not gettting any error in Eclipse but when i'm running the app am able to see the blank app screen.So can someone help me out this issue..
Sample app developed using this link
Please comment asap..
Code:
Java File ----------
package com.phonegap;
import com.phonegap.*;
import android.os.Bundle;
public class HelloworldActivity extends DroidGap
{
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
super.loadUrl("file:///android_assets/www/helloworld.html");
}
}
The problem is in your loadUrl, you should use:
super.loadUrl("file:///android_asset/index.html"); // Singular android_asset, not assets

Categories

Resources