android - How to create a list menu from the list Activity Class,,,what i'm doing wrong???help out -
//main activity java file: in java file create various classess below shown 1 class example(textplay) want create list activity in menu list,,when run code in emulator seen application forced clossly i'm doing wrongly//
package com.example.eeeramsong; import android.app.listactivity; import android.content.intent; import android.database.datasetobserver; import android.os.bundle; import android.view.view; import android.view.viewgroup; import android.widget.arrayadapter; import android.widget.listadapter; import android.widget.listview; public class menu extends listactivity{ string classes[]={"counter","textplay","example3","example4","example5"}; @override protected void oncreate(bundle savedinstancestate) { // todo auto-generated method stub super.oncreate(savedinstancestate); setlistadapter(new arrayadapter<string> (menu.this,android.r.layout.simple_expandable_list_item_1, classes)); } @override protected void onlistitemclick(listview l, view v, int position, long id) { // todo auto-generated method stub super.onlistitemclick(l, v, position, id); string cheese=classes[position]; try{ class classss=class.forname("com.example.eeramsong." + cheese); intent inte=new intent(menu.this,classss); startactivity(inte); }catch(classnotfoundexception e) { e.printstacktrace(); } } /** * @param args */ public static void main(string[] args) { // todo auto-generated method stub } }
second java file:
package com.example.eeeramsong; import android.app.activity; import android.os.bundle; import android.widget.button; import android.widget.edittext; import android.widget.textview; import android.widget.togglebutton; public class textplay extends activity{ @override protected void oncreate(bundle savedinstancestate) { // todo auto-generated method stub super.oncreate(savedinstancestate); setcontentview(r.layout.text); button chkb=(button)findviewbyid(r.id.txtbutton); togglebutton chktog=(togglebutton)findviewbyid(r.id.txttog); edittext tex= (edittext)findviewbyid(r.id.edtext); textview txtview=(textview)findviewbyid(r.id.txttv); } /** * @param args */ public static void main(string[] args) { // todo auto-generated method stub }}
xml file:
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:padding="30dp" > <edittext android:id="@+id/edtext" android:layout_width="fill_parent" android:layout_height="wrap_content" android:password="true" android:paddingbottom="20dp" android:hint="type anything...:-)" /> <linearlayout android:weightsum="100" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" android:padding="20dp"> <button android:id="@+id/txtbutton" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="50" android:text="command" /> <togglebutton android:id="@+id/txttog" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="50" android:checked="false" /> </linearlayout> <textview android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center" android:id="@+id/txttv" android:text="invalid"/> </linearlayout>
logcat:
03-25 17:39:06.102: e/androidruntime(335): fatal exception: main 03-25 17:39:06.102: e/androidruntime(335): java.lang.runtimeexception: unable instantiate activity componentinfo{com.example.errortest/com.example.errortest.menu}: java.lang.classnotfoundexception: com.example.errortest.menu in loader dalvik.system.pathclassloader[/data/app/com.example.errortest-1.apk] 03-25 17:39:06.102: e/androidruntime(335): @ android.app.activitythread.performlaunchactivity(activitythread.java:1569) 03-25 17:39:06.102: e/androidruntime(335): @ android.app.activitythread.handlelaunchactivity(activitythread.java:1663) 03-25 17:39:06.102: e/androidruntime(335): @ android.app.activitythread.access$1500(activitythread.java:117) 03-25 17:39:06.102: e/androidruntime(335): @ android.app.activitythread$h.handlemessage(activitythread.java:931) 03-25 17:39:06.102: e/androidruntime(335): @ android.os.handler.dispatchmessage(handler.java:99) 03-25 17:39:06.102: e/androidruntime(335): @ android.os.looper.loop(looper.java:123) 03-25 17:39:06.102: e/androidruntime(335): @ android.app.activitythread.main(activitythread.java:3683) 03-25 17:39:06.102: e/androidruntime(335): @ java.lang.reflect.method.invokenative(native method) 03-25 17:39:06.102: e/androidruntime(335): @ java.lang.reflect.method.invoke(method.java:507) 03-25 17:39:06.102: e/androidruntime(335): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:839) 03-25 17:39:06.102: e/androidruntime(335): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:597) 03-25 17:39:06.102: e/androidruntime(335): @ dalvik.system.nativestart.main(native method) 03-25 17:39:06.102: e/androidruntime(335): caused by: java.lang.classnotfoundexception: com.example.errortest.menu in loader dalvik.system.pathclassloader[/data/app/com.example.errortest-1.apk] 03-25 17:39:06.102: e/androidruntime(335): @ dalvik.system.pathclassloader.findclass(pathclassloader.java:240) 03-25 17:39:06.102: e/androidruntime(335): @ java.lang.classloader.loadclass(classloader.java:551) 03-25 17:39:06.102: e/androidruntime(335): @ java.lang.classloader.loadclass(classloader.java:511) 03-25 17:39:06.102: e/androidruntime(335): @ android.app.instrumentation.newactivity(instrumentation.java:1021) 03-25 17:39:06.102: e/androidruntime(335): @ android.app.activitythread.performlaunchactivity(activitythread.java:1561) 03-25 17:39:06.102: e/androidruntime(335): ... 11 more
manifest file
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.errortest" 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=".menu" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> <activity android:name="textplay" 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>
please add menu activity in project menifeast file.
Comments
Post a Comment