java - app crashes when launching emulator -


my logcat:

01-01 05:13:28.690: d/androidruntime(696): shutting down vm 01-01 05:13:28.690: w/dalvikvm(696): threadid=1: thread exiting uncaught exception (group=0x40a13300) 01-01 05:13:28.741: e/androidruntime(696): fatal exception: main 01-01 05:13:28.741: e/androidruntime(696): java.lang.runtimeexception: unable start activity componentinfo{com.example.myfunapp/com.example.myfunapp.mainactivity}: java.lang.runtimeexception: content must have listview id attribute 'android.r.id.list' 01-01 05:13:28.741: e/androidruntime(696):  @ android.app.activitythread.performlaunchactivity(activitythread.java:2059) 01-01 05:13:28.741: e/androidruntime(696):  @ android.app.activitythread.handlelaunchactivity(activitythread.java:2084) 01-01 05:13:28.741: e/androidruntime(696):  @ android.app.activitythread.access$600(activitythread.java:130) 01-01 05:13:28.741: e/androidruntime(696):  @ android.app.activitythread$h.handlemessage(activitythread.java:1195) 01-01 05:13:28.741: e/androidruntime(696):  @ android.os.handler.dispatchmessage(handler.java:99) 01-01 05:13:28.741: e/androidruntime(696):  @ android.os.looper.loop(looper.java:137) 01-01 05:13:28.741: e/androidruntime(696):  @ android.app.activitythread.main(activitythread.java:4745) 01-01 05:13:28.741: e/androidruntime(696):  @ java.lang.reflect.method.invokenative(native method) 01-01 05:13:28.741: e/androidruntime(696):  @ java.lang.reflect.method.invoke(method.java:511) 01-01 05:13:28.741: e/androidruntime(696):  @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:786) 01-01 05:13:28.741: e/androidruntime(696):  @ com.android.internal.os.zygoteinit.main(zygoteinit.java:553) 01-01 05:13:28.741: e/androidruntime(696):  @ dalvik.system.nativestart.main(native method) 01-01 05:13:28.741: e/androidruntime(696): caused by: java.lang.runtimeexception: content must have listview id attribute 'android.r.id.list' 01-01 05:13:28.741: e/androidruntime(696):  @ android.app.listactivity.oncontentchanged(listactivity.java:243) 01-01 05:13:28.741: e/androidruntime(696):  @ com.android.internal.policy.impl.phonewindow.setcontentview(phonewindow.java:259) 01-01 05:13:28.741: e/androidruntime(696):  @ android.app.activity.setcontentview(activity.java:1867) 01-01 05:13:28.741: e/androidruntime(696):  @ com.example.myfunapp.mainactivity.oncreate(mainactivity.java:39) 01-01 05:13:28.741: e/androidruntime(696):  @ android.app.activity.performcreate(activity.java:5008) 01-01 05:13:28.741: e/androidruntime(696):  @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1079) 01-01 05:13:28.741: e/androidruntime(696):  @ android.app.activitythread.performlaunchactivity(activitythread.java:2023) 01-01 05:13:28.741: e/androidruntime(696):  ... 11 more 01-01 05:13:33.503: i/process(696): sending signal. pid: 696 sig: 9 

its says "unfortunately myapp has closed", did include @android:id/list @ listview in xml file. still gives me same error upon launching of emulator. please help, quite new this..

this mainactivity.java class:

public class mainactivity extends listactivity { private static final int capture_image_activity_request_code = 100;    @override public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main); }   @override public boolean oncreateoptionsmenu(menu menu) {     menuinflater inflater = getmenuinflater();     inflater.inflate(r.menu.fun_menu, menu);     return true; }  @override public boolean onoptionsitemselected(menuitem item) {     // handle item selection     switch (item.getitemid()) {         case r.id.takephoto:             cam();             return true;         case r.id.music:            startactivity(new intent(this, mplayer.class));             return true;         default:             return super.onoptionsitemselected(item);     }  }     public void cam() { intent intent = new     intent(android.provider.mediastore.action_image_capture);          file file = new file(environment.getexternalstoragedirectory(),                     "my-photo.jpg");              uri photopath = uri.fromfile(file);             intent.putextra(mediastore.extra_output, photopath);              startactivityforresult(intent, capture_image_activity_request_code);             startactivityforresult(intent, 0);          } 

this mplayer.java class implementing music player. have used switch case in mainactivity. 1 music player , other camera api in android. have called method directly implemented in mainactivity camera option. music player, created new class called mplayer.java containing code.

import java.io.file; import java.io.filenamefilter; import java.util.arraylist; import java.util.list;  import com.example.myfunapp.mp3filter; import com.example.myfunapp.r;   import android.app.listactivity; import android.media.mediaplayer; import android.os.bundle; import android.view.view; import android.view.view.onclicklistener; import android.widget.arrayadapter; import android.widget.button;   class mp3filter implements filenamefilter{ public boolean accept(file dir, string name){     return(name.endswith(".mp3")); }   public static class mplayer extends listactivity{  private static final string sd_path =new string("/sdcard/"); private list<string> songs = new arraylist<string>(); private mediaplayer mp = new mediaplayer();  @override public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.msicplayer);     updateplaylist();       button stopplay = (button) findviewbyid(r.id.stopbtn);     stopplay.setonclicklistener(new onclicklistener() {          public void onclick(view v) {             mp.stop();          }     }); 

}

private void updateplaylist(){     file home = new file(sd_path);     if (home.listfiles(new mp3filter()).length > 0){         (file file : home.listfiles(new mp3filter())){             songs.add(file.getname());         } arrayadapter<string> songlist =new arrayadapter<string>(this,r.layout.song_item,songs);         setlistadapter(songlist);     } } 

} }

this music player layout code:

<linearlayout   android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" >     <listview     android:id="@+id/list"     android:layout_width="match_parent"     android:layout_height="wrap_content" >  </listview>     <button     android:id="@+id/stopbtn"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:text="@string/stopbtn" />  </linearlayout>  

as error log indicates, android unable find view right id. because need add as,

android:id="@+id/list" 

Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -