-1

メインのアクティビティからリストアクティビティに切り替えることができません。ビデオチュートリアルを見てリストアクティビティを作成し、同じ手順を実行しましたが、ボタンをクリックしてメニューに切り替えるとすぐに、「残念ながらプログラム動作を停止しました」

Button button1; 
    button1 = (Button)findViewById(R.id.but1);


    button1.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            Intent i = new Intent(MainActivity.this,Menu.class);
            startActivity(i);

Menuクラスは次のとおりです。

public class Menu extends ListActivity{
String classes[] = {"First","Second","Third"};

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setListAdapter(new ArrayAdapter<String>(Menu.this,android.R.layout.simple_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 ourClass=Class.forName("com.ashsoft.basiccprogram." + cheese);
    Intent ourIntent=new Intent(Menu.this,ourClass);
    startActivity(ourIntent);
    }catch(ClassNotFoundException e){

        e.printStackTrace();
    }

Logcat:

Log file : `01-13 13:53:03.481: W/Trace(1400): Unexpected value from nativeGetEnabledTags: 0
01-13 13:53:03.481: W/Trace(1400): Unexpected value from nativeGetEnabledTags: 0
01-13 13:53:03.481: W/Trace(1400): Unexpected value from nativeGetEnabledTags: 0
01-13 13:53:04.511: W/Trace(1400): Unexpected value from nativeGetEnabledTags: 0
01-13 13:53:04.521: W/Trace(1400): Unexpected value from nativeGetEnabledTags: 0
01-13 13:53:05.602: W/Trace(1400): Unexpected value from nativeGetEnabledTags: 0
01-13 13:53:05.602: W/Trace(1400): Unexpected value from nativeGetEnabledTags: 0
01-13 13:53:05.681: W/Trace(1400): Unexpected value from nativeGetEnabledTags: 0
01-13 13:53:05.771: W/Trace(1400): Unexpected value from nativeGetEnabledTags: 0
01-13 13:53:06.001: W/Trace(1400): Unexpected value from nativeGetEnabledTags: 0
01-13 13:53:06.071: W/Trace(1400): Unexpected value from nativeGetEnabledTags: 0
01-13 13:53:06.071: W/Trace(1400): Unexpected value from nativeGetEnabledTags: 0
01-13 13:53:06.181: I/Choreographer(1400): Skipped 68 frames!  The application may be doing too much work on its main thread.
01-13 13:53:06.362: W/Trace(1400): Unexpected value from nativeGetEnabledTags: 0
01-13 13:53:06.442: W/Trace(1400): Unexpected value from nativeGetEnabledTags: 0
01-13 13:53:06.491: W/Trace(1400): Unexpected value from nativeGetEnabledTags: 0
01-13 13:53:06.501: W/Trace(1400): Unexpected value from nativeGetEnabledTags: 0
01-13 13:53:06.511: W/Trace(1400): Unexpected value from nativeGetEnabledTags: 0
01-13 13:53:06.532: W/Trace(1400): Unexpected value from nativeGetEnabledTags: 0
01-13 13:53:06.581: D/gralloc_goldfish(1400): Emulator without GPU emulation detected.
01-13 13:53:06.702: W/Trace(1400): Unexpected value from nativeGetEnabledTags: 0
01-13 13:53:06.851: W/Trace(1400): Unexpected value from nativeGetEnabledTags: 0
01-13 13:53:16.741: W/Trace(1400): Unexpected value from nativeGetEnabledTags: 0
01-13 13:53:16.782: W/Trace(1400): Unexpected value from nativeGetEnabledTags: 0
01-13 13:53:16.801: W/Trace(1400): Unexpected value from nativeGetEnabledTags: 0
01-13 13:53:16.801: W/Trace(1400): Unexpected value from nativeGetEnabledTags: 0
01-13 13:53:16.872: W/Trace(1400): Unexpected value from nativeGetEnabledTags: 0
01-13 13:53:16.911: W/Trace(1400): Unexpected value from nativeGetEnabledTags: 0
01-13 13:53:16.931: W/Trace(1400): Unexpected value from nativeGetEnabledTags: 0
01-13 13:53:16.951: W/Trace(1400): Unexpected value from nativeGetEnabledTags: 0
01-13 13:53:17.052: D/AndroidRuntime(1400): Shutting down VM
01-13 13:53:17.052: W/dalvikvm(1400): threadid=1: thread exiting with uncaught exception (group=0x40a70930)
01-13 13:53:17.151: E/AndroidRuntime(1400): FATAL EXCEPTION: main
01-13 13:53:17.151: E/AndroidRuntime(1400): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.ashsoft.basiccprogram/android.view.Menu}; have you declared this activity in your AndroidManifest.xml?
01-13 13:53:17.151: E/AndroidRuntime(1400):     at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1618)
01-13 13:53:17.151: E/AndroidRuntime(1400):     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1417)
01-13 13:53:17.151: E/AndroidRuntime(1400):     at android.app.Activity.startActivityForResult(Activity.java:3370)
01-13 13:53:17.151: E/AndroidRuntime(1400):     at android.app.Activity.startActivityForResult(Activity.java:3331)
01-13 13:53:17.151: E/AndroidRuntime(1400):     at android.app.Activity.startActivity(Activity.java:3566)
01-13 13:53:17.151: E/AndroidRuntime(1400):     at android.app.Activity.startActivity(Activity.java:3534)
01-13 13:53:17.151: E/AndroidRuntime(1400):     at com.ashsoft.basiccprogram.MainActivity$1.onClick(MainActivity.java:27)
01-13 13:53:17.151: E/AndroidRuntime(1400):     at android.view.View.performClick(View.java:4202)
01-13 13:53:17.151: E/AndroidRuntime(1400):     at android.view.View$PerformClick.run(View.java:17340)
01-13 13:53:17.151: E/AndroidRuntime(1400):     at android.os.Handler.handleCallback(Handler.java:725)
01-13 13:53:17.151: E/AndroidRuntime(1400):     at android.os.Handler.dispatchMessage(Handler.java:92)
01-13 13:53:17.151: E/AndroidRuntime(1400):     at android.os.Looper.loop(Looper.java:137)
01-13 13:53:17.151: E/AndroidRuntime(1400):     at android.app.ActivityThread.main(ActivityThread.java:5039)
01-13 13:53:17.151: E/AndroidRuntime(1400):     at java.lang.reflect.Method.invokeNative(Native Method)
01-13 13:53:17.151: E/AndroidRuntime(1400):     at java.lang.reflect.Method.invoke(Method.java:511)
01-13 13:53:17.151: E/AndroidRuntime(1400):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
01-13 13:53:17.151: E/AndroidRuntime(1400):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
01-13 13:53:17.151: E/AndroidRuntime(1400):     at dalvik.system.NativeStart.main(Native Method)
01-13 13:53:25.911: I/Process(1400): Sending signal. PID: 1400 SIG: 9
`

マニフェストコード:

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

     <activity
        android:name="com.ashsoft.basiccprogram.First"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.FIRST" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
        <activity
        android:name="com.ashsoft.basiccprogram.Menu"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MENU" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>


</application>

私が使用したチュートリアルでは、リストにxmlファイルを使用していませんでした。

主な問題は、リストが表示されないことです。メインアクティビティからメニューのボタンをクリックすると、機能しなくなります。

4

1 に答える 1

0

そのMenuクラスをマニフェストファイルに登録していないようです。

それでも機能しない場合は、logcatを投稿して、回答が編集される可能性があります。

編集:

まず、長いプロセスタスクをasynctaskで囲む必要があります。

とりあえずそのままにしておきましょう。これを試してみてください:

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

     <activity
        android:name="com.ashsoft.basiccprogram.First"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.FIRST" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
        <activity
        android:name=".ListScreenActivity"
        android:label="@string/app_name" >

    </activity>

ListScreenActivity:

public class ListScreenActivity extends ListActivity{
String classes[] = {"First","Second","Third"};

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);


    setListAdapter(new ArrayAdapter<String>(ListScreenActivity.this,android.R.layout.simple_list_item_1, classes));


               ListView listView = getListView();
           listView.setTextFilterEnabled(true);




listView.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {
               //show toast
                Toast.makeText(getApplicationContext(),"Clicked on "+classes[position], Toast.LENGTH_SHORT).show();
            }
        });

}
于 2013-01-13T13:29:17.893 に答える