0

当我单击 Order 按钮时,此 CatalogActivity.java 显示致命错误。

package com.example.barcode;

import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.ListView;

public class CatalogActivity extends Activity {

private List<Product> mProductList;
Button button;

 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.catalog);



 // Obtain a reference to the product catalog
    mProductList = ShoppingCartHelper.getCatalog(getResources());

   // Create the list
   ListView listViewCatalog = (ListView) findViewById(R.id.ListViewCatalog);
   listViewCatalog.setAdapter(new ProductAdapter(mProductList, getLayoutInflater(),      false));

   listViewCatalog.setOnItemClickListener(new OnItemClickListener() {




   @Override
   public void onItemClick(AdapterView<?> parent, View view, int position,
     long id) {
    Intent productDetailsIntent = new         Intent(getBaseContext(),ProductDetailsActivity.class);
    productDetailsIntent.putExtra(ShoppingCartHelper.PRODUCT_INDEX, position);
    startActivity(productDetailsIntent);
   }
  });

   Button viewShoppingCart = (Button) findViewById(R.id.ButtonViewCart);
   viewShoppingCart.setOnClickListener(new OnClickListener() {

   @Override
   public void onClick(View v) {
    Intent viewShoppingCartIntent = new Intent(getBaseContext(), ShoppingCartActivity.class);
    startActivity(viewShoppingCartIntent);
   }
  });

 }
}

04-08 12:25:17.893: W/KeyCharacterMap(478): No keyboard for id 0
04-08 12:25:17.893: W/KeyCharacterMap(478): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
04-08 12:25:22.663: D/AndroidRuntime(478): Shutting down VM
04-08 12:25:22.673: W/dalvikvm(478): threadid=1: thread exiting with uncaught exception (group=0x40015560)
04-08 12:25:22.693: E/AndroidRuntime(478): FATAL EXCEPTION: main
04-08 12:25:22.693: E/AndroidRuntime(478): java.lang.IllegalStateException: Could not execute method of the activity
04-08 12:25:22.693: E/AndroidRuntime(478):  at android.view.View$1.onClick(View.java:2144)
04-08 12:25:22.693: E/AndroidRuntime(478):  at android.view.View.performClick(View.java:2485)
04-08 12:25:22.693: E/AndroidRuntime(478):  at android.view.View$PerformClick.run(View.java:9080)
04-08 12:25:22.693: E/AndroidRuntime(478):  at android.os.Handler.handleCallback(Handler.java:587)
04-08 12:25:22.693: E/AndroidRuntime(478):  at android.os.Handler.dispatchMessage(Handler.java:92)
04-08 12:25:22.693: E/AndroidRuntime(478):  at android.os.Looper.loop(Looper.java:123)
04-08 12:25:22.693: E/AndroidRuntime(478):  at android.app.ActivityThread.main(ActivityThread.java:3683)
04-08 12:25:22.693: E/AndroidRuntime(478):  at java.lang.reflect.Method.invokeNative(Native Method)
04-08 12:25:22.693: E/AndroidRuntime(478):  at java.lang.reflect.Method.invoke(Method.java:507)
04-08 12:25:22.693: E/AndroidRuntime(478):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-08 12:25:22.693: E/AndroidRuntime(478):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-08 12:25:22.693: E/AndroidRuntime(478):  at dalvik.system.NativeStart.main(Native Method)
04-08 12:25:22.693: E/AndroidRuntime(478): Caused by: java.lang.reflect.InvocationTargetException
04-08 12:25:22.693: E/AndroidRuntime(478):  at java.lang.reflect.Method.invokeNative(Native Method)
04-08 12:25:22.693: E/AndroidRuntime(478):  at java.lang.reflect.Method.invoke(Method.java:507)
04-08 12:25:22.693: E/AndroidRuntime(478):  at android.view.View$1.onClick(View.java:2139)
04-08 12:25:22.693: E/AndroidRuntime(478):  ... 11 more
04-08 12:25:22.693: E/AndroidRuntime(478): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.barcode/com.example.barcode.CatalogActivity}; have you declared this activity in your AndroidManifest.xml?
04-08 12:25:22.693: E/AndroidRuntime(478):  at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1405)
04-08 12:25:22.693: E/AndroidRuntime(478):  at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379)
04-08 12:25:22.693: E/AndroidRuntime(478):  at android.app.Activity.startActivityForResult(Activity.java:2827)
04-08 12:25:22.693: E/AndroidRuntime(478):  at android.app.Activity.startActivity(Activity.java:2933)
04-08 12:25:22.693: E/AndroidRuntime(478):  at com.example.barcode.Barcodemain.Order(Barcodemain.java:30)
04-08 12:25:22.693: E/AndroidRuntime(478):  ... 14 more
4

1 回答 1

1

添加到清单以下行:

<activity android:name="com.example.barcode.CatalogActivity" />
于 2013-04-08T12:36:43.673 回答