线程退出与android上的未捕获异常

时间:2015-11-10 18:58:33

标签: android

我在尝试创建自定义列表视图时收到此错误消息。我的主xml中有按钮,我调用oncreate函数在mainactiviy中使用intent。 我使用log.d来跟踪错误,但是它通过了startActivity(intent),但是无法访问listview1 oncreate函数 你能帮忙吗? 谢谢

package com.emre.onder.hw2;


import java.io.InputStream;
import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

public class ListView1 extends Activity {
    ArrayList<Music> arr=new ArrayList<Music>();
    ListView listView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);

        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.listview_custom);
            listView =(ListView) findViewById(R.id.listView);

            Music m1=new Music();
            m1.setAlbum_name("album name");
            m1.setLength(3.40);
            m1.setMusic_name("adagio for strings");
            m1.setMusician_name("Tiesto");

            InputStream is = getResources().openRawResource(R.raw.tiesto);
            Bitmap bitmap = BitmapFactory.decodeStream(is);
            m1.setImage(bitmap);
            arr.add(m1);

            listView.setAdapter(new CustomAdapter(this, arr));



           /* ParcelableMusic parcelableLaptop = (ParcelableMusic) intent
                    .getParcelableExtra("music");

            Music music = parcelableLaptop.getMusic();
            // Create Parcelable object
            ParcelableMusic parcelableMusic = new ParcelableMusic(music);

            // Store Parcelable object in Intent
        //  intent.putExtra("music", parcelableMusic); */

    }


}
11-10 11:41:25.344: D/gralloc_goldfish(3011): Emulator without GPU emulation detected.
11-10 11:41:34.204: D/AndroidRuntime(3011): Shutting down VM
11-10 11:41:34.204: W/dalvikvm(3011): threadid=1: thread exiting with uncaught exception (group=0x41465730)
11-10 11:41:34.374: E/AndroidRuntime(3011): FATAL EXCEPTION: main
11-10 11:41:34.374: E/AndroidRuntime(3011): java.lang.IllegalStateException: Could not execute method of the activity
11-10 11:41:34.374: E/AndroidRuntime(3011):     at android.view.View$1.onClick(View.java:3633)
11-10 11:41:34.374: E/AndroidRuntime(3011):     at android.view.View.performClick(View.java:4240)
11-10 11:41:34.374: E/AndroidRuntime(3011):     at android.view.View$PerformClick.run(View.java:17721)
11-10 11:41:34.374: E/AndroidRuntime(3011):     at android.os.Handler.handleCallback(Handler.java:730)
11-10 11:41:34.374: E/AndroidRuntime(3011):     at android.os.Handler.dispatchMessage(Handler.java:92)
11-10 11:41:34.374: E/AndroidRuntime(3011):     at android.os.Looper.loop(Looper.java:137)
11-10 11:41:34.374: E/AndroidRuntime(3011):     at android.app.ActivityThread.main(ActivityThread.java:5103)
11-10 11:41:34.374: E/AndroidRuntime(3011):     at java.lang.reflect.Method.invokeNative(Native Method)
11-10 11:41:34.374: E/AndroidRuntime(3011):     at java.lang.reflect.Method.invoke(Method.java:525)
11-10 11:41:34.374: E/AndroidRuntime(3011):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
11-10 11:41:34.374: E/AndroidRuntime(3011):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-10 11:41:34.374: E/AndroidRuntime(3011):     at dalvik.system.NativeStart.main(Native Method)
11-10 11:41:34.374: E/AndroidRuntime(3011): Caused by: java.lang.reflect.InvocationTargetException
11-10 11:41:34.374: E/AndroidRuntime(3011):     at java.lang.reflect.Method.invokeNative(Native Method)
11-10 11:41:34.374: E/AndroidRuntime(3011):     at java.lang.reflect.Method.invoke(Method.java:525)
11-10 11:41:34.374: E/AndroidRuntime(3011):     at android.view.View$1.onClick(View.java:3628)
11-10 11:41:34.374: E/AndroidRuntime(3011):     ... 11 more
11-10 11:41:34.374: E/AndroidRuntime(3011): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.emre.onder.hw2/com.emre.onder.hw2.ListView1}; have you declared this activity in your AndroidManifest.xml?
11-10 11:41:34.374: E/AndroidRuntime(3011):     at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1628)
11-10 11:41:34.374: E/AndroidRuntime(3011):     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1424)
11-10 11:41:34.374: E/AndroidRuntime(3011):     at android.app.Activity.startActivityForResult(Activity.java:3390)
11-10 11:41:34.374: E/AndroidRuntime(3011):     at android.app.Activity.startActivityForResult(Activity.java:3351)
11-10 11:41:34.374: E/AndroidRuntime(3011):     at android.app.Activity.startActivity(Activity.java:3587)
11-10 11:41:34.374: E/AndroidRuntime(3011):     at android.app.Activity.startActivity(Activity.java:3555)
11-10 11:41:34.374: E/AndroidRuntime(3011):     at com.emre.onder.hw2.MainActivity.onClick(MainActivity.java:45)
11-10 11:41:34.374: E/AndroidRuntime(3011):     ... 14 more
11-10 11:46:34.554: I/Process(3011): Sending signal. PID: 3011 SIG: 9

1 个答案:

答案 0 :(得分:1)

来自例外:

android.content.ActivityNotFoundException: Unable to find explicit activity class {com.emre.onder.hw2/com.emre.onder.hw2.ListView1}; 

您是否已在AndroidManifest.xml中声明此活动?

确保将新活动放在AndroidManifest.xml