Android的致命错误:主 [英] Android Fatal error:main

查看:122
本文介绍了Android的致命错误:主的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我点击按钮顺序,这CatalogActivity.java,它给我致命的错误。

 包com.example.bar code;进口的java.util.List;进口android.app.Activity;
进口android.content.Intent;
进口android.os.Bundle;
进口android.view.View;
进口android.view.View.OnClickListener;
进口android.widget.AdapterView;
进口android.widget.AdapterView.OnItemClickListener;
进口android.widget.Button;
进口android.widget.ListView;公共类CatalogActivity延伸活动{私人列表<产品与GT; mProductList;
Button按钮; / **当第一次创建活动调用。 * /
 @覆盖
 公共无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.catalog); //获取到产品目录的参考
    mProductList = ShoppingCartHelper.getCatalog(getResources());   //创建列表
   ListView控件listViewCatalog =(ListView控件)findViewById(R.id.ListViewCatalog);
   listViewCatalog.setAdapter(新ProductAdapter(mProductList,getLayoutInflater(),FALSE));   listViewCatalog.setOnItemClickListener(新OnItemClickListener(){
   @覆盖
   公共无效onItemClick(适配器视图<>母公司,观景,INT位置,
     长ID){
    意图productDetailsIntent =新意图(getBaseContext(),ProductDetailsActivity.class);
    productDetailsIntent.putExtra(ShoppingCartHelper.PRODUCT_INDEX,位置);
    startActivity(productDetailsIntent);
   }
  });   按钮viewShoppingCart =(按钮)findViewById(R.id.ButtonViewCart);
   viewShoppingCart.setOnClickListener(新OnClickListener(){   @覆盖
   公共无效的onClick(视图v){
    意图viewShoppingCartIntent =新意图(getBaseContext(),ShoppingCartActivity.class);
    startActivity(viewShoppingCartIntent);
   }
  }); }
}


  12月4日至8日:25:17.893:W / KeyCharacterMap(478):无键盘ID 0
十二月四日至八日:25:17.893:W / KeyCharacterMap(478):使用默认的键盘对应:/system/usr/keychars/qwerty.kcm.bin
十二月四日至八日:25:22.663:D / AndroidRuntime(478):关闭VM
十二月四日至八日:25:22.673:W / dalvikvm(478):主题ID = 1:螺纹未捕获的异常(组= 0x40015560)退出
十二月四日至八日:25:22.693:E / AndroidRuntime(478):致命异常:主要
十二月四日至八日:25:22.693:E / AndroidRuntime(478):java.lang.IllegalStateException:无法执行活动的方法
十二月四日至八日:25:22.693:E / AndroidRuntime(478):在android.view.View $ 1.onClick(View.java:2144)
十二月四日至八日:25:22.693:E / AndroidRuntime(478):在android.view.View.performClick(View.java:2485)
十二月四日至八日:25:22.693:E / AndroidRuntime(478):在android.view.View $ PerformClick.run(View.java:9080)
十二月四日至八日:25:22.693:E / AndroidRuntime(478):在android.os.Handler.handleCallback(Handler.java:587)
十二月四日至八日:25:22.693:E / AndroidRuntime(478):在android.os.Handler.dispatchMessage(Handler.java:92)
十二月四日至八日:25:22.693:E / AndroidRuntime(478):在android.os.Looper.loop(Looper.java:123)
十二月四日至八日:25:22.693:E / AndroidRuntime(478):在android.app.ActivityThread.main(ActivityThread.java:3683)
十二月四日至八日:25:22.693:E / AndroidRuntime(478):在java.lang.reflect.Method.invokeNative(本机方法)
十二月四日至八日:25:22.693:E / AndroidRuntime(478):在java.lang.reflect.Method.invoke(Method.java:507)
十二月四日至八日:25:22.693:E / AndroidRuntime(478):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:839)
十二月四日至八日:25:22.693:E / AndroidRuntime(478):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
十二月四日至八日:25:22.693:E / AndroidRuntime(478):在dalvik.system.NativeStart.main(本机方法)
十二月四日至八日:25:22.693:E / AndroidRuntime(478):由:java.lang.reflect.InvocationTargetException
十二月四日至八日:25:22.693:E / AndroidRuntime(478):在java.lang.reflect.Method.invokeNative(本机方法)
十二月四日至八日:25:22.693:E / AndroidRuntime(478):在java.lang.reflect.Method.invoke(Method.java:507)
十二月四日至八日:25:22.693:E / AndroidRuntime(478):在android.view.View $ 1.onClick(View.java:2139)
十二月四日至八日:25:22.693:E / AndroidRuntime(478):11 ...更多
十二月四日至八日:25:22.693:E / AndroidRuntime(478):android.content.ActivityNotFoundException:产生的原因无法找到明确的活动类{com.example.bar code / com.example.bar code.CatalogActivity};有你宣布你的Andr​​oidManifest.xml这个活动?
十二月四日至八日:25:22.693:E / AndroidRuntime(478):在android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1405)
十二月四日至八日:25:22.693:E / AndroidRuntime(478):在android.app.Instrumentation.execStartActivity(Instrumentation.java:1379)
十二月四日至八日:25:22.693:E / AndroidRuntime(478):在android.app.Activity.startActivityForResult(Activity.java:2827)
十二月四日至八日:25:22.693:E / AndroidRuntime(478):在android.app.Activity.startActivity(Activity.java:2933)
十二月四日至八日:25:22.693:E / AndroidRuntime(478):在com.example.bar code.Bar codemain.Order(酒吧codemain.java:30)
十二月四日至八日:25:22.693:E / AndroidRuntime(478):14 ...更多


解决方案

添加到下面的表现行:

 <活动机器人:名字=com.example.bar code.CatalogActivity/>

when i click button Order, to this CatalogActivity.java, it show me fatal error.

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

解决方案

Add to manifest below line:

<activity android:name="com.example.barcode.CatalogActivity" />

这篇关于Android的致命错误:主的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆