RuntimeException:无法实例化活动组件信息Android。

时间:2022-04-10 00:22:34

I'm trying to code something in android but I can't get it working on my external device. It always force quits. I've coded one or two things in android and I was always able to launch them, so I have no idea where this error is coming from.

我试着在android上编程,但我无法让它在我的外部设备上运行。它总是强迫退出。我在安卓系统中编码了一两个东西,我总是能够启动它们,所以我不知道这个错误是从哪里来的。

This is the code of the launcher activity:

这是发射器活动的代码:

package sander.bylemans.alarm;

import java.util.ArrayList;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends ActionBarActivity {

    final int setAlarm = 214;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button add = (Button) findViewById(R.id.add);
        add.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                startActivityForResult(new Intent(MainActivity.this,AlarmScreen.class), setAlarm);
            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data){
        if(requestCode == setAlarm){
            if(resultCode == RESULT_OK){
                String name = data.getStringExtra("Name");
                String time = data.getStringExtra("Time");  //In h:m format
                String days = data.getStringExtra("Days");  //Seperated by ;

                String[] t = time.split(":");
                String[] d = days.split(";");

                int[] hrsAndMin = new int[t.length];
                for(int i = 0; i < t.length; i++){
                    hrsAndMin[i] = Integer.parseInt(t[i]);
                }

                ArrayList<Day> ds = new ArrayList<Day>();
                for(int i = 0; i < d.length; i++){
                    switch(d[i]){
                    case("Monday"):
                        ds.add(Day.Monday);
                    case("Tuesday"):
                        ds.add(Day.Tuesday);
                    case("Wednesday"):
                        ds.add(Day.Wednesday);
                    case("Thursday"):
                        ds.add(Day.Thursday);
                    case("Friday"):
                        ds.add(Day.Friday);
                    case("Saturday"):
                        ds.add(Day.Saturday);
                    case("Sunday"):
                        ds.add(Day.Sunday);
                    }
                }

                Alarm alarm = new Alarm(name, hrsAndMin[0], hrsAndMin[1] , Status.ON, ds);

                addAlarm(alarm);
            }
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    private void addAlarm(Alarm alarm){

    }
}

This is the AndroidManifest.xml:

这是AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="sander.bylemans.alarm"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="16" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="sander.bylemans.alarm.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="sander.bylemans.alarm.AlarmScreen"
            android:label="@string/title_activity_alarm_screen" >
        </activity>
    </application>

</manifest>

And this is the error I receive and I don't know how to resolve:

这是我收到的错误,我不知道如何解决:

10-27 20:56:52.278: W/dalvikvm(14367): Unable to resolve superclass of Lsander/bylemans/alarm/MainActivity; (4)
10-27 20:56:52.278: W/dalvikvm(14367): Link of class 'Lsander/bylemans/alarm/MainActivity;' failed
10-27 20:56:52.298: W/dalvikvm(14367): threadid=1: thread exiting with uncaught exception (group=0x4001d560)
10-27 20:56:52.398: E/AndroidRuntime(14367): FATAL EXCEPTION: main
10-27 20:56:52.398: E/AndroidRuntime(14367): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{sander.bylemans.alarm/sander.bylemans.alarm.MainActivity}: java.lang.ClassNotFoundException: sander.bylemans.alarm.MainActivity in loader dalvik.system.PathClassLoader[/data/app/sander.bylemans.alarm-2.apk]
10-27 20:56:52.398: E/AndroidRuntime(14367):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1573)
10-27 20:56:52.398: E/AndroidRuntime(14367):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
10-27 20:56:52.398: E/AndroidRuntime(14367):    at android.app.ActivityThread.access$1500(ActivityThread.java:117)
10-27 20:56:52.398: E/AndroidRuntime(14367):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
10-27 20:56:52.398: E/AndroidRuntime(14367):    at android.os.Handler.dispatchMessage(Handler.java:99)
10-27 20:56:52.398: E/AndroidRuntime(14367):    at android.os.Looper.loop(Looper.java:130)
10-27 20:56:52.398: E/AndroidRuntime(14367):    at android.app.ActivityThread.main(ActivityThread.java:3687)
10-27 20:56:52.398: E/AndroidRuntime(14367):    at java.lang.reflect.Method.invokeNative(Native Method)
10-27 20:56:52.398: E/AndroidRuntime(14367):    at java.lang.reflect.Method.invoke(Method.java:507)
10-27 20:56:52.398: E/AndroidRuntime(14367):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
10-27 20:56:52.398: E/AndroidRuntime(14367):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
10-27 20:56:52.398: E/AndroidRuntime(14367):    at dalvik.system.NativeStart.main(Native Method)
10-27 20:56:52.398: E/AndroidRuntime(14367): Caused by: java.lang.ClassNotFoundException: sander.bylemans.alarm.MainActivity in loader dalvik.system.PathClassLoader[/data/app/sander.bylemans.alarm-2.apk]
10-27 20:56:52.398: E/AndroidRuntime(14367):    at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
10-27 20:56:52.398: E/AndroidRuntime(14367):    at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
10-27 20:56:52.398: E/AndroidRuntime(14367):    at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
10-27 20:56:52.398: E/AndroidRuntime(14367):    at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
10-27 20:56:52.398: E/AndroidRuntime(14367):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1565)
10-27 20:56:52.398: E/AndroidRuntime(14367):    ... 11 more

I searched a long time for a solution and can't seem to find one that solves the problem. I tried different things but none of them work. If someone could help me I would be forever thankfull.

我花了很长时间寻找解决方案,似乎找不到解决问题的办法。我尝试了不同的方法,但没有一个奏效。如果有人能帮助我,我会永远心存感激。

Greets

问候

2 个解决方案

#1


0  

VM is not able to find android.support.v7.app.ActionBarActivity; Check the location of your support library jar. It should be in project's libs folder to work

VM无法找到android.support.v7.app.ActionBarActivity;检查支持库jar的位置。它应该在项目的libs文件夹中工作。

#2


0  

It seems that the needed jar is not in your libs folder. Copy the jar to your libs folder

似乎需要的jar不在您的libs文件夹中。将jar复制到libs文件夹。

You need to make sure that the lib is checked in the following path

您需要确保在以下路径中检查lib。

Go to Properties->Java Build Path->Order and Export and make sure the library is checked.

#1


0  

VM is not able to find android.support.v7.app.ActionBarActivity; Check the location of your support library jar. It should be in project's libs folder to work

VM无法找到android.support.v7.app.ActionBarActivity;检查支持库jar的位置。它应该在项目的libs文件夹中工作。

#2


0  

It seems that the needed jar is not in your libs folder. Copy the jar to your libs folder

似乎需要的jar不在您的libs文件夹中。将jar复制到libs文件夹。

You need to make sure that the lib is checked in the following path

您需要确保在以下路径中检查lib。

Go to Properties->Java Build Path->Order and Export and make sure the library is checked.