在Onclick上获取错误,java.lang.IllegalStateException:无法执行活动的方法

时间:2015-11-13 15:46:59

标签: android onclick

尝试制作Android应用。点击按钮我收到以下错误。请帮我。我假设它与空值/不启动有关。 帮助,不要给予否定。经常搜索。

MainActivity:

public class MainActivity extends Activity   {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.home_screen);
}


public void ScanBarcode(View view){
    Intent newScreen = new Intent("com.aaa.fyp.SimpleScannerActivity");
   // finish();

    startActivity(newScreen);
    finish();
 }

SimpleScannerActivity

public class SimpleScannerActivity extends Activity implements ZXingScannerView.ResultHandler {
private ZXingScannerView mScannerView ;
private static final String TAG = "CameraPreview";

@Override
    public void onCreate(Bundle state) {
        super.onCreate(state);
        mScannerView = new ZXingScannerView(this);    
        setContentView(mScannerView);                
 }

错误:

11-13 20:35:26.978 1245-1245/com.aaa.fyp W/dalvikvm: threadid=1: calling UncaughtExceptionHandler
11-13 20:35:26.980 1245-1245/com.aaa.fyp E/AndroidRuntime: FATAL EXCEPTION: main
11-13 20:35:26.980 1245-1245/com.aaa.fyp E/AndroidRuntime: java.lang.IllegalStateException: Could not execute method of the activity
11-13 20:35:26.980 1245-1245/com.aaa.fyp E/AndroidRuntime:     at android.view.View$1.onClick(View.java:3625)
11-13 20:35:26.980 1245-1245/com.aaa.fyp E/AndroidRuntime:     at android.view.View.performClick(View.java:4230)
11-13 20:35:26.980 1245-1245/com.aaa.fyp E/AndroidRuntime:     at android.view.View$PerformClick.run(View.java:17660)
11-13 20:35:26.980 1245-1245/com.aaa.fyp E/AndroidRuntime:     at android.os.Handler.handleCallback(Handler.java:800)
11-13 20:35:26.980 1245-1245/com.aaa.fyp E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:100)
11-13 20:35:26.980 1245-1245/com.aaa.fyp E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:194)
11-13 20:35:26.980 1245-1245/com.aaa.fyp E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5433)
11-13 20:35:26.980 1245-1245/com.aaa.fyp E/AndroidRuntime:     at java.lang.reflect.Method.invokeNative(Native Method)
11-13 20:35:26.980 1245-1245/com.aaa.fyp E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Method.java:525)
11-13 20:35:26.980 1245-1245/com.aaa.fyp E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:924)
11-13 20:35:26.980 1245-1245/com.aaa.fyp E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:691)
11-13 20:35:26.980 1245-1245/com.aaa.fyp E/AndroidRuntime:     at dalvik.system.NativeStart.main(Native Method)
11-13 20:35:26.980 1245-1245/com.aaa.fyp E/AndroidRuntime:  Caused by: java.lang.reflect.InvocationTargetException
11-13 20:35:26.980 1245-1245/com.aaa.fyp E/AndroidRuntime:     at java.lang.reflect.Method.invokeNative(Native Method)
11-13 20:35:26.980 1245-1245/com.aaa.fyp E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Method.java:525)
11-13 20:35:26.980 1245-1245/com.aaa.fyp E/AndroidRuntime:     at android.view.View$1.onClick(View.java:3620)
11-13 20:35:26.980 1245-1245/com.aaa.fyp E/AndroidRuntime:     at android.view.View.performClick(View.java:4230) 
11-13 20:35:26.980 1245-1245/com.aaa.fyp E/AndroidRuntime:     at android.view.View$PerformClick.run(View.java:17660) 
11-13 20:35:26.980 1245-1245/com.aaa.fyp E/AndroidRuntime:     at android.os.Handler.handleCallback(Handler.java:800) 
11-13 20:35:26.980 1245-1245/com.aaa.fyp E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:100) 
11-13 20:35:26.980 1245-1245/com.aaa.fyp E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:194) 
11-13 20:35:26.980 1245-1245/com.aaa.fyp E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5433) 
11-13 20:35:26.980 1245-1245/com.aaa.fyp E/AndroidRuntime:     at java.lang.reflect.Method.invokeNative(Native Method) 
11-13 20:35:26.980 1245-1245/com.aaa.fyp E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Method.java:525) 
11-13 20:35:26.980 1245-1245/com.aaa.fyp E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:924) 
11-13 20:35:26.980 1245-1245/com.aaa.fyp E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:691) 
11-13 20:35:26.980 1245-1245/com.aaa.fyp E/AndroidRuntime:     at dalvik.system.NativeStart.main(Native Method) 
11-13 20:35:26.980 1245-1245/com.aaa.fyp E/AndroidRuntime:  Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.aaa.fyp.SimpleScannerActivity }
11-13 20:35:26.980 1245-1245/com.aaa.fyp E/AndroidRuntime:     at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1693)
11-13 20:35:26.980 1245-1245/com.aaa.fyp E/AndroidRuntime:     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1488)
11-13 20:35:26.980 1245-1245/com.aaa.fyp E/AndroidRuntime:     at android.app.Activity.startActivityForResult(Activity.java:3425)
11-13 20:35:26.980 1245-1245/com.aaa.fyp E/AndroidRuntime:     at android.app.Activity.startActivityForResult(Activity.java:3376)
11-13 20:35:26.980 1245-1245/com.aaa.fyp E/AndroidRuntime:     at android.app.Activity.startActivity(Activity.java:3621)
11-13 20:35:26.980 1245-1245/com.aaa.fyp E/AndroidRuntime:     at android.app.Activity.startActivity(Activity.java:3589)
11-13 20:35:26.980 1245-1245/com.aaa.fyp E/AndroidRuntime:     at com.aaa.fyp.MainActivity.ScanBarcode(MainActivity.java:30)
11-13 20:35:26.980 1245-1245/com.aaa.fyp E/AndroidRuntime:     at java.lang.reflect.Method.invokeNative(Native Method) 
11-13 20:35:26.980 1245-1245/com.aaa.fyp E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Method.java:525) 
11-13 20:35:26.980 1245-1245/com.aaa.fyp E/AndroidRuntime:     at android.view.View$1.onClick(View.java:3620) 
11-13 20:35:26.980 1245-1245/com.aaa.fyp E/AndroidRuntime:     at android.view.View.performClick(View.java:4230) 
11-13 20:35:26.980 1245-1245/com.aaa.fyp E/AndroidRuntime:     at android.view.View$PerformClick.run(View.java:17660) 
11-13 20:35:26.980 1245-1245/com.aaa.fyp E/AndroidRuntime:     at android.os.Handler.handleCallback(Handler.java:800) 
11-13 20:35:26.980 1245-1245/com.aaa.fyp E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:100) 
11-13 20:35:26.980 1245-1245/com.aaa.fyp E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:194) 
11-13 20:35:26.980 1245-1245/com.aaa.fyp E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5433) 
11-13 20:35:26.980 1245-1245/com.aaa.fyp E/AndroidRuntime:     at java.lang.reflect.Method.invokeNative(Native Method) 
11-13 20:35:26.980 1245-1245/com.aaa.fyp E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Method.java:525) 

告诉我是否应该提供更多代码。

1 个答案:

答案 0 :(得分:0)

首先,我没有足够的声誉留下评论,但你必须做的就是使用意图是

Intent newScreen = new Intent(this, YourClass.class);
startActivity(newScreen);