任何人都可以請幫我,爲什麼我不能運行這個簡單的應用程序,它是在Udemy教程,我都檢查過很多次了,完全像它在教程爲什麼我的應用程序停止工作
package com.example.hp250.actions;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import java.lang.reflect.InvocationTargetException;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void OpenApp(View view) {
Intent intent=new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("market://details?id=com.soundcloud.android"));
startActivity(intent);
}
}
日誌貓:
02-29 06:56:17.774 4886-4886/com.example.hp250.actions I/art: Not late-enabling -Xcheck:jni (already on)
02-29 06:56:17.775 4886-4886/com.example.hp250.actions I/art: Late-enabling JIT
02-29 06:56:17.777 4886-4886/com.example.hp250.actions I/art: JIT created with code_cache_capacity=2MB compile_threshold=1000
02-29 06:56:17.843 4886-4886/com.example.hp250.actions W/System: ClassLoader referenced unknown path: /data/app/com.example.hp250.actions-1/lib/x86
02-29 06:56:18.013 4886-4910/com.example.hp250.actions D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
02-29 06:56:18.056 4886-4910/com.example.hp250.actions I/OpenGLRenderer: Initialized EGL, version 1.4
02-29 06:56:18.190 4886-4910/com.example.hp250.actions W/EGL_emulation: eglSurfaceAttrib not implemented
02-29 06:56:18.190 4886-4910/com.example.hp250.actions W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xad7607e0, error=EGL_SUCCESS
02-29 06:56:20.394 4886-4886/com.example.hp250.actions D/AndroidRuntime: Shutting down VM
02-29 06:56:20.395 4886-4886/com.example.hp250.actions E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.hp250.actions, PID: 4886
java.lang.IllegalStateException: Could not execute method for android:onClick
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:275)
at android.view.View.performClick(View.java:5198)
at android.view.View$PerformClick.run(View.java:21147)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:270)
at android.view.View.performClick(View.java:5198)
at android.view.View$PerformClick.run(View.java:21147)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=market://details?id=com.soundcloud.android }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1798)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1512)
at android.app.Activity.startActivityForResult(Activity.java:3917)
at android.app.Activity.startActivityForResult(Activity.java:3877)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:784)
at android.app.Activity.startActivity(Activity.java:4200)
at android.app.Activity.startActivity(Activity.java:4168)
at com.example.hp250.actions.MainActivity.OpenApp(MainActivity.java:23)
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:270)
at android.view.View.performClick(View.java:5198)
at android.view.View$PerformClick.run(View.java:21147)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
02-29 06:56:22.922 4886-4886/? I/Process: Sending signal. PID: 4886 SIG: 9
您可以從logcat添加日誌嗎? – TechnoBlahble
02-29 06:56:20.395 4886-4886/com.example.hp250.actions E/AndroidRuntime:致命例外:main 進程:com.example.hp250.actions,PID:4886 java.lang.IllegalStateException:可能不執行Android的方法:onClick at android.support.v7.app.AppCompatViewInflater $ DeclaredOnClickListener.onClick(AppCompatViewInflater.java:275) –
請將完整的logcat放入原始問題中,而不是作爲註釋。 –