java - App is not opening , though no errors..! -
i have tried make simple app . first app in android , not new java . app has customised background , sound (song) playing on homescreen . builds . no errors @ all..!!! have taken care of warnings..
but app doesn't work on device (i dont use emulator..!!) says , "unfortunately [appname] has stopped "..
why????
here java code..:
package com.exmple.worth; import android.app.activity; import android.media.mediaplayer; import android.os.bundle; import android.view.view; import android.widget.button; public class mainactivity extends activity { mediaplayer bfmv = mediaplayer.create(mainactivity.this, r.raw.saf ) ; button b1 ; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); b1 = (button) findviewbyid(r.id.b1) ; bfmv.start() ; b1.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub bfmv.stop() ; } }); } }
here xml file :
<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" tools:context="${packagename}.${activityclass}" android:background="@drawable/qwe" >" <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" /> <button android:id="@+id/b1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentbottom="true" android:layout_centerhorizontal="true" android:layout_marginbottom="14dp" android:text="pause" /> </relativelayout>
and here android manifest :
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.exmple.worth" android:versioncode="1" android:versionname="1.0" > <uses-sdk android:minsdkversion="13" 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.exmple.worth.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>
i tried code. way instantiate bfmv wrong.
mediaplayer bfmv = mediaplayer.create(mainactivity.this, r.raw.saf ) ;
it should this: on outer class declare object:
mediaplayer bfmv;
and on oncreate method instantiate it:
bfmv = mediaplayer.create(mainactivity.this, r.raw.saf ) ;
the reason force close context mainactivity.this null before oncreate called.
Comments
Post a Comment