My simple android to print hello world is not running properly. Android virtual Device is getting start but not showing any output. Here is my code plz fix it.
its my java class.
package com.example.jack;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
here is mainActivity.xml for layout.
<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">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world" />
</LinearLayout>
And here is String.xmm.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">jack</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello World</string>
</resources>
here is AndroidMenifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.jack"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.jack.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>
Avd is showing only the android image. Nothing more.. Plz help me out.
AVD showing only the android image and nothing else loading after a reasonable period of time likely means that your system is unable to render the resolution that you have chosen (Note that I said most likely - in some cases, I have found that AVD takes like 15 minutes just to start but then runs properly after that). A solution to this would be to check the 'Use Host GPU' option under Emulation options.
If that does not solve it, try to reduce the Memory and VM heap options. That should most certainly solve it.
If you are unable to start the app on a physical device as well, then it likely means there is an error in your app.
The AVD can take a while to start up the first time depending on the machine resources and does stay on the Android Logo for some time. It should always boot up completely through. If there is an error with your app it will show you an alert saying your app has stopped working. Just give it some time to boot completely.
Related
I'm developing an Android tablet application containing lots of activities that use the Theme.Holo.DialogWhenLarge theme. On real devices (Nexus 7 KitKat and Samsung Galaxy Tab 3 8") these activities are displayed as expected, but on every Genymotion VM I try to create (Nexus 7 KitKat and Nexus 10 Jelly Bean for example) they are displayed as normal full-screen activities. I tested also on a Nexus 7 KitKat emulator created with the standard Android SDK Virtual Device Manager, and activities are displayed as expected.
I can ignore it and suppose that it's only a problem with the Genymotion emulator, but I want to know if there's a way to fix that in order to have a better test environment. I would like to point out that the *-large resource qualifier works on the Genymotion VMs, the issue looks related only to that theme.
To reduce all possible causes of the problem I created a new test project with a normal main activity having a button that launches a DialogWhenLarge-themed activity. I also removed all Android support libraries and all XML styles files automatically created by Eclipse: the only resources left are the two layouts for the activities and the launcher icon. These are all the files of the test project:
src/com/example/testdialogwhenlarge/MainActivity.java
package com.example.testdialogwhenlarge;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
public class MainActivity extends Activity {
#Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
#Override public void onClick(View v) {
// Start the DialogWhenLarge-themed activity
startActivity(new Intent(MainActivity.this, TestActivity.class));
}
});
}
}
src/com/example/testdialogwhenlarge/TestActivity.java
package com.example.testdialogwhenlarge;
import android.app.Activity;
import android.os.Bundle;
public class TestActivity extends Activity {
#Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
}
}
res/layout/activity_main.xml
<FrameLayout
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"
tools:context="com.example.testdialogwhenlarge.MainActivity">
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</FrameLayout>
res/layout/activity_test.xml
<FrameLayout
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"
tools:context="com.example.testdialogwhenlarge.TestActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</FrameLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.testdialogwhenlarge"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="TestDialogWhenLarge"
android:theme="#android:style/Theme.Holo">
<activity android:name="com.example.testdialogwhenlarge.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.testdialogwhenlarge.TestActivity"
android:theme="#android:style/Theme.Holo.DialogWhenLarge">
</activity>
</application>
</manifest>
This issue has been fixed by the Genymotion team in release 2.3.0.
I'm recently been trying to get R.JAVA to generate with no avail. I've tried the following
1. Adding spaces to the manifest file
2. Project--> Clean
So my last guess is that there is some error in my xml files that I/eclipse haven't been able to see. So I was hoping to have a second pair of eyes that might be able to check my xml files for review. There's only three and they should be pretty basic(I'm following a intro to android book).
Manifest File
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.activites"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Activity2"
android:label="Activity 2" >
<intent-filter>
<action android:name="com.example.ACTIVITY2" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
activity_main.xml
<RelativeLayout 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" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="#string/hello_world"
tools:context=".MainActivity" />
</RelativeLayout>
Activity2.xml
<RelativeLayout 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" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is Activity 2!" />
</RelativeLayout>
Again thanks to all of you that have taken time out of your busy day/night to help out a beginner like myself. Also if there's any suggestion other than errors in the xml feel free to bring them up.
As requested here are the problems appear in windows-> show view -> problems
R cannot be resolved to a variable
R cannot be resolved to a variable
R cannot be resolved to a variable
Tag is not that obvious it is used to show debug information in catlog with the following lines of code.
public class MainActivity extends Activity {
String tag = "Events";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
Log.d(tag, "In the onCreate() event");
}
In eclipse you can check the Problems view(windows-->show view-->Problems) or/and the Console view to help locate errors in Xml efficiently. If you remain need help you may want to post these errors to us
I get following error when I compile your code:
res\layout\Activity2.xml: Invalid file name: must contain only
[a-z0-9_.]
So remove capital A and rename "Activity2.xml" to "activity2.xml"
Also, if this doesn't help, try this:-
Rename your package name to some other. Clean. Restart Eclipse. Rename package back to the previous one. Again clean. Restart Eclipse.
check your imports. is import android.R anywhere there? if so, remove it. if you're indeed following some android tutorial in a book and it instructed you to organize or manage imports with Ctrl+shift+O or otherwise, that will cause that to pop up.
tag should be a String variable. What is it defined as? You should probably hard-code it there, unless you are using it as a global variable for your application.
http://developer.android.com/reference/android/util/Log.html#d%28java.lang.String,%20java.lang.String%29
EDIT: R cannot be resolved - Android error has a lot of different answers, try reading through those. If the first one doesn't solve your problem, another one might.
I am not totally new to working with the eclipse android plugin but I am new at writing a project from the ground up. So I went to the Android developers website to follow the 'Hello World' tutorial.
When I run my program the emulator puts up a screen that says
unfortunately Hello, Android Has stopped working.
my code is:
HelloAndroid.Java
package daniel.android.projects;
import android.app.Activity;
import android.os.Bundle;
public class HelloAndroid extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Object o = null;
o.toString();
setContentView(R.layout.main);
}
}
Main.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/textview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="#string/hello"/>
Strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello, Android! I am a string resource!</string>
<string name="app_name">Hello, Android</string>
</resources>
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="daniel.android.projects"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="15" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".AndroidTesterActivity"
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>
You have a null pointer exception, you assign null to o and then call toString() on it:
Object o = null;
o.toString();
It seems like it serves nothing in your application anyway, it shouldn't be there.
Also, looking at your code, you create HelloAndroid class, but in themanifest you declare
android:name=".AndroidTesterActivity"
it should be
android:name=".HelloAndroid"
I've made a very simple app that just displays a Google map. However, it only seems to be displaying gray squares.
I've troubleshooted and have done virtually everything I could. I checked my code 5+ times over, I've compared it even to other tutorials. I've re-made my API key 3 times - none of them work.
The phone I'm using is connected to wireless. Even the emulator won't work. I have the library and permission established in the manifest. I think I've done just about everything, but it still doesn't work... any suggestions?
Here's my code:
MapsActivity.java:
package net.learn2develop.GoogleMaps;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import android.os.Bundle;
public class MapsActivity extends MapActivity
{
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
#Override
protected boolean isRouteDisplayed() {
return false;
}
}
main.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.google.android.maps.MapView
android:id="#+id/mapView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:enabled="true"
android:clickable="true"
android:apiKey="0duU2_tgS67qkUZIpmLVIo0IDvJDh4Ew1Mzh9Pg"
/>
</RelativeLayout>
GoogleMapsManifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.learn2develop.GoogleMaps"
android:versionCode="1"
android:versionName="1.0.0">
<uses-sdk android:minSdkVersion="7" />
<application android:icon="#drawable/icon" android:label="#string/app_name">
<uses-library android:name="com.google.android.maps" />
<activity android:name=".MapsActivity"
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>
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
You need to add
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
into you manifest
Note: If you are using both NETWORK_PROVIDER and GPS_PROVIDER, then you need to request only the ACCESS_FINE_LOCATION permission, because it includes permission for both providers. (Permission for ACCESS_COARSE_LOCATION includes permission only for NETWORK_PROVIDER.)
The problem was that Mike was using an API key generated with the release keystore instead of the debug keystore that eclipse uses when compiling the apk.
I had the same error ! I tried everything, so a try this tutorial below and it worked!!!!
TUTORIAL
Thanks in advance for your efforts.
I have an Application that revolves around a ListActivity extended class. Before the app starts, I want to check whether the user is registered, and if not tell him to and get some info from him. So, I tried to call StartActivity in the OnCreate() method. When that loaded, I got a big black screen.
I thought that it may be related to being run in the OnCreate so I let the Activity start as usual, and I tried to run it in an OnClick event, and I got the same result.
In both cases, if I press escape, that Window goes away and the main app window comes back.
Here are the lines from where I call the new Activity
Intent emailIntent = new Intent(this, EmailAddressGetter.class);
this.startActivity(emailIntent);
Here is the code of the class
/**
*
*/
package com.kosherapp;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Toast;
/**
* #author Josh
*
*/
public class EmailAddressGetter extends Activity {
public void OnCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.emailinput);
}
}
Here is the emailinput xml contents
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#ffffff"
android:textColor="#000000"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:text="hello"
>
</TextView>
And, here is the manifest contents
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.kosherapp"
android:versionCode="1"
android:versionName="1.0"
>
<uses-permission
android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission
android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission
android:name="android.permission.INTERNET" />
<uses-permission
android:name="android.permission.CALL_PHONE" />
<application
android:icon="#drawable/icon"
android:label="#string/app_name"
>
<activity
android:name=".KosherApp"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar"
>
<intent-filter>
<action
android:name="android.intent.action.MAIN" />
<category
android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".EmailAddressGetter"
android:label="email Address Getter"
>
</activity>
<activity
android:name=".GoogleMaps"
android:label="Google Maps"
>
</activity>
<uses-library
android:name="com.google.android.maps" />
</application>
</manifest>
Let me know if there's any other info you may need. Oh, I'm running this with the Google API 2.1-update
Thanks
Change OnCreate to onCreate in EmailAddressGetter.
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.emailinput);
}
You need to use EditText instead. TextView is for static text which is why nothing is displaying. You should also include the EditText in another layout like Linear or Relative so it looks cleaner.
You are using an intent to call EmailAddressGetter but it doesn't have an intent filter in the manifest. Throw in something like Log.e("EmailAddressGetter", "It worked") in your onCreate and use ddms to see if it is actually opening that activity.
Also, in the updated code in your comment to Robby Pond, remove the xmlns line from EditText