Android应用程序在打开时关闭

时间:2014-01-27 14:26:12

标签: java android compiler-errors forceclose

我试图创建一个图像,当它被点击时打开一个新的活动..我试过,我试过..但最后我想我已经成功了..我没有错误,我检查清单,我宣布所有活动,但应用程序是开始时关闭力量,我不知道为什么..

以下是我的代码:

清单:

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

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

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.QEwqewqewq.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="Doi"
        android:label="Doi">
</activity>

    </application>


</manifest>

main.xml中:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:gravity="center"
   >

<ImageView
    android:id="@+id/image_id"
    android:layout_width="fill_parent" android:layout_height="wrap_content"
    android:src="@drawable/water"
    android:onClick="onClick"  
 android:contentDescription="@null" />

</LinearLayout>

MainActivity.java:

package com.QEwqewqewq;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

class MainActivity extends Activity{
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.main);
    }

        public void onClick(View view) {

            if( view.getId() == R.id.image_id)
                startActivity(new Intent(this, Doi.class));
            else
                Log.i("Image", "Try to open the Activity from another view different from ImageView");
        } 
    }

谢谢,请尽快帮助我。

编辑:

logcat的:

01-27 16:21:41.504: E/AndroidRuntime(288): FATAL EXCEPTION: main
01-27 16:21:41.504: E/AndroidRuntime(288): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.QEwqewqewq/com.QEwqewqewq.MainActivity}: java.lang.IllegalAccessException: access to class not allowed
01-27 16:21:41.504: E/AndroidRuntime(288):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
01-27 16:21:41.504: E/AndroidRuntime(288):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
01-27 16:21:41.504: E/AndroidRuntime(288):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
01-27 16:21:41.504: E/AndroidRuntime(288):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
01-27 16:21:41.504: E/AndroidRuntime(288):  at android.os.Handler.dispatchMessage(Handler.java:99)
01-27 16:21:41.504: E/AndroidRuntime(288):  at android.os.Looper.loop(Looper.java:123)
01-27 16:21:41.504: E/AndroidRuntime(288):  at android.app.ActivityThread.main(ActivityThread.java:4627)
01-27 16:21:41.504: E/AndroidRuntime(288):  at java.lang.reflect.Method.invokeNative(Native Method)
01-27 16:21:41.504: E/AndroidRuntime(288):  at java.lang.reflect.Method.invoke(Method.java:521)
01-27 16:21:41.504: E/AndroidRuntime(288):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
01-27 16:21:41.504: E/AndroidRuntime(288):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-27 16:21:41.504: E/AndroidRuntime(288):  at dalvik.system.NativeStart.main(Native Method)
01-27 16:21:41.504: E/AndroidRuntime(288): Caused by: java.lang.IllegalAccessException: access to class not allowed
01-27 16:21:41.504: E/AndroidRuntime(288):  at java.lang.Class.newInstanceImpl(Native Method)
01-27 16:21:41.504: E/AndroidRuntime(288):  at java.lang.Class.newInstance(Class.java:1429)
01-27 16:21:41.504: E/AndroidRuntime(288):  at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
01-27 16:21:41.504: E/AndroidRuntime(288):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
01-27 16:21:41.504: E/AndroidRuntime(288):  ... 11 more

Doi.java:

package com.QEwqewqewq;

import android.app.Activity;
import android.os.Bundle;

public class Doi extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.doi);

    }
}

2 个答案:

答案 0 :(得分:0)

尝试在MainActivity课程中插入“公开”:

[...]
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

public class MainActivity extends Activity{
    public void onCreate(Bundle savedInstanceState) {
[...]

答案 1 :(得分:0)

将您的“MainActivity”公开活动。