Stuck in Android programming

vickybat

I am the night...I am...
Guys i'm trying my hands on android programming recently using java and xml.

I know a bit of java but completely new to xml ( i somewhat know html5 and familiar with markup language tags).

Been following a beginners guide and trying to create my first app. Its simply like a "hello-world" code for newbies but prints "batman" instead.
Code is fairly simply as its generated by eclipse linked with android sdk. It creates all the xml and java codes only slightly modified by me.

I'm running this in an emulator and the apk is getting generated and installed and my app icon shows up in the menu screen. But the moment i fire it, it stops and the log throws
a lot of exceptions. Since i'm knew to android, i'm not able to understand the head or tail of the problem since the apk is generated successfully.

I've figured that the problem is in the AndroidManifest.xml file but still cannot figure anything. Posting all the codes separately including one for java and three xml's including the manifest file. Can anybody trace out the problem?? The application stops working when fired.

Java

Code:
package Test.Android;

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.activity_main, menu);
		return true;
	}

}
Strings.xml

Code:
<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="app_name">.TestAndroid</string>
    <string name="hello_world">Batman </string>
    <string name="menu_settings">Settings</string>

</resources>

activity_main.xml

Code:
<RelativeLayout xmlns:android="*schemas.android.com/apk/res/android"
    xmlns:tools="*schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="@string/hello_world" />

</RelativeLayout>

AndroidManifest.xml

Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="*schemas.android.com/apk/res/android"
    package="Test.Android"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="14" android:maxSdkVersion="16"/>

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".Test.Android.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>

</manifest>

The setContentView method in the java code basically points to the activity_main.xml which has reference with string.xml

Can anybody help me out? This should be simple for android developers here.
 

guru_urug

iGoogle
Try replacing the following in your AndroidManifest.xml

android:name=".Test.Android.MainActivity"
with
android:name=".MainActivity"

Im assuming that your MainActivity.java is under
src>Test.Android>MainActivity.java
 
OP
vickybat

vickybat

I am the night...I am...
^^ Thanks a lot mate. :)

It worked and app is getting fired with the desired output. So the java name ( subclass) has to be mentioned in the android:name with a . prefix.
But now the apk is not getting installed in the emulator with my custom icon like before. Any fix for that buddy?
 

guru_urug

iGoogle
Hi extremely sorry for such a late post reply, Ive been busy at work, so no time for TDF lately. Finally got some time off to check today. Your PM inbox is full, I cant send you messages.

Anyway back to your question,
I suggest you try testing your app on an android device instead of the emulator. The emulator can be extremely slow and buggy. Testing on an android device is much faster, just enable android debugging on your android device and connect to your PC. The ADT will detect your device and then you can run the project and it will select your phone/tablet. Also try cleaning your project in Eclipse (Project>Clean) in the menu bar.
 
Top Bottom