startactivity()关闭应用程序

时间:2013-07-13 12:58:28

标签: java android

我有以下活动, 当调用startactivity()时,应用程序被强制关闭,我几天都在搜索失败,有人可以帮助我吗?

应用程式:

package com.example.deceunincktechniekers;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
  import android.widget.ListView;



public class OpeningsMenu extends ListActivity {
//hier maken we de Array (lijst) met de namen die in de menu moeten komen
String classes[] = {"bezoekrapporten" ,"BTWcontrole" ,"voorbeeld3"};


// hier zetten we de layout van deze class niet gelijk aan een xml maar aan een            lijst van knoppen volgens simple list item 1
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setListAdapter(new ArrayAdapter<String>(OpeningsMenu.this, android.R.layout.simple_list_item_1, classes));

}
// hier zetten we de actie als er op de lijst geklikt wordt
//
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    // 
    super.onListItemClick(l, v, position, id);
    String positie = classes[position];
    try{
    Class onzeclass = Class.forName("com.example.deceunincktechniekers." + positie);
    Intent onzeIntent = new Intent(OpeningsMenu.this, onzeclass);
    startActivity(onzeIntent);
    }catch (ClassNotFoundException e){
        e.printStackTrace();
    }
}    

logcat的:

07-13 12:48:47.204: D/dalvikvm(785): GC_CONCURRENT freed 73K, 8% free 2768K/2984K, paused 14ms+57ms, total 148ms
07-13 12:48:47.664: I/Choreographer(785): Skipped 81 frames!  The application may be doing too much work on its main thread.
07-13 12:48:47.714: D/gralloc_goldfish(785): Emulator without GPU emulation detected.
07-13 12:53:35.678: D/dalvikvm(785): newInstance failed: Lcom/example/deceunincktechniekers/bezoekrapporten; not accessible to Landroid/app/Instrumentation;
07-13 12:53:35.678: D/AndroidRuntime(785): Shutting down VM
07-13 12:53:35.678: W/dalvikvm(785): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
07-13 12:53:35.738: E/AndroidRuntime(785): FATAL EXCEPTION: main
07-13 12:53:35.738: E/AndroidRuntime(785): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.deceunincktechniekers/com.example.deceunincktechniekers.bezoekrapporten}: java.lang.IllegalAccessException: access to class not allowed
07-13 12:53:35.738: E/AndroidRuntime(785):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2106)
07-13 12:53:35.738: E/AndroidRuntime(785):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
07-13 12:53:35.738: E/AndroidRuntime(785):  at android.app.ActivityThread.access$600(ActivityThread.java:141)
07-13 12:53:35.738: E/AndroidRuntime(785):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
07-13 12:53:35.738: E/AndroidRuntime(785):  at android.os.Handler.dispatchMessage(Handler.java:99)
07-13 12:53:35.738: E/AndroidRuntime(785):  at android.os.Looper.loop(Looper.java:137)
07-13 12:53:35.738: E/AndroidRuntime(785):  at android.app.ActivityThread.main(ActivityThread.java:5041)
07-13 12:53:35.738: E/AndroidRuntime(785):  at java.lang.reflect.Method.invokeNative(Native Method)
07-13 12:53:35.738: E/AndroidRuntime(785):  at java.lang.reflect.Method.invoke(Method.java:511)
07-13 12:53:35.738: E/AndroidRuntime(785):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
07-13 12:53:35.738: E/AndroidRuntime(785):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
07-13 12:53:35.738: E/AndroidRuntime(785):  at dalvik.system.NativeStart.main(Native Method)
07-13 12:53:35.738: E/AndroidRuntime(785): Caused by: java.lang.IllegalAccessException: access to class not allowed
07-13 12:53:35.738: E/AndroidRuntime(785):  at java.lang.Class.newInstanceImpl(Native Method)
07-13 12:53:35.738: E/AndroidRuntime(785):  at java.lang.Class.newInstance(Class.java:1319)
07-13 12:53:35.738: E/AndroidRuntime(785):  at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
07-13 12:53:35.738: E/AndroidRuntime(785):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
07-13 12:53:35.738: E/AndroidRuntime(785):  ... 11 more
07-13 12:53:38.838: I/Process(785): Sending signal. PID: 785 SIG: 9

如果您需要更多信息,请提出要求

3 个答案:

答案 0 :(得分:1)

你的日志说

  

java.lang.IllegalAccessException不允许访问类

可能是这个名为

的班级
  

com.example.deceunincktechniekers。 + positie

没有公共构造函数

答案 1 :(得分:1)

没有名为com.example.deceunincktechniekers.bezoekrapporten的类,或者它不是public,或者它没有public构造函数。

答案 2 :(得分:0)

我有同样的问题;我检查了AndroidManifest.xml,想通过 startActivity(Intent)调用的活动丢失了。 添加活动(检查以下内容)后,可以调用我的活动(条目):