Android Studio说“ AndroidManifest.xml中未声明Mainactivity”吗?

时间:2019-03-14 10:42:27

标签: android android-activity manifest declare

这是我运行应用程序时的清单文件,上面写着“ AndroidManifest.xml中未声明主要活动”

我尝试了重建,使缓存无效/重新启动,添加了

<activity
    android:name=".MainActivity"
    android:label="@string/app_name"  to my manifest

还有许多其他问题,这些问题来自股票溢出的其他答案,但没有解决我的问题。请帮我。 我昨天做了apk,直到现在为止一切正常,但是今天当我打开它时,它显示了此错误。

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

        <application
            android:allowBackup="true"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:roundIcon="@mipmap/ic_launcher_round"
            android:supportsRtl="true"

            android:theme="@style/AppTheme">
            <activity android:name=".pprath">
            </activity>
            <activity android:name=".mpurn" />
            <activity android:name=".mprath" />
            <activity android:name=".Prambhik" />
            <activity android:name=".Exams" />



            <activity android:name=".Kalyan"/>
            <activity android:name=".Thats" />
            <activity android:name=".MainActivity">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />


                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>

        </application>

    </manifest>

这是MainActivity.java

package com.keval.raagbhandaar;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {


    private Button button4;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        button4 = (Button) findViewById(R.id.button4);
        button4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                openActivityexam();


            }

            public void openActivityexam() {
                Intent intent = new Intent(MainActivity.this, Exams.class);
                startActivity(intent);
            }


        });
    }}

logcat

2019-03-14 17:02:33.492 5363-5363 / com.keval.raagbhandaar E / AndroidRuntime:FATAL EXCEPTION:main     流程:com.keval.raagbhandaar,PID:5363     java.lang.RuntimeException:画布:试图绘制太大(558306000bytes)的位图。         在android.view.DisplayListCanvas.throwIfCannotDraw(DisplayListCanvas.java:229)         在android.view.RecordingCanvas.drawBitmap(RecordingCanvas.java:97)         在android.graphics.drawable.BitmapDrawable.draw(BitmapDrawable.java:529)         在android.view.View.getDrawableRenderNode(View.java:19450)         在android.view.View.drawBackground(View.java:19386)         在android.view.View.draw(View.java:19183)         在android.view.View.updateDisplayListIfDirty(View.java:18142)         在android.view.View.draw(View.java:18920)         在android.view.ViewGroup.drawChild(ViewGroup.java:4236)         在android.view.ViewGroup.dispatchDraw(ViewGroup.java:4022)         在android.view.View.updateDisplayListIfDirty(View.java:18133)         在android.view.View.draw(View.java:18920)         在android.view.ViewGroup.drawChild(ViewGroup.java:4236)         在android.view.ViewGroup.dispatchDraw(ViewGroup.java:4022)         在android.view.View.updateDisplayListIfDirty(View.java:18133)         在android.view.View.draw(View.java:18920)         在android.view.ViewGroup.drawChild(ViewGroup.java:4236)         在android.view.ViewGroup.dispatchDraw(ViewGroup.java:4022)         在android.view.View.updateDisplayListIfDirty(View.java:18133)         在android.view.View.draw(View.java:18920)         在android.view.ViewGroup.drawChild(ViewGroup.java:4236)         在android.view.ViewGroup.dispatchDraw(ViewGroup.java:4022)         在android.view.View.updateDisplayListIfDirty(View.java:18133)         在android.view.View.draw(View.java:18920)         在android.view.ViewGroup.drawChild(ViewGroup.java:4236)         在android.view.ViewGroup.dispatchDraw(ViewGroup.java:4022)         在android.view.View.draw(View.java:19195)         在com.android.internal.policy.DecorView.draw(DecorView.java:788)         在android.view.View.updateDisplayListIfDirty(View.java:18142)         在android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:669)         在android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:675)         在android.view.ThreadedRenderer.draw(ThreadedRenderer.java:783)         在android.view.ViewRootImpl.draw(ViewRootImpl.java:2992)         在android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2806)         在android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2359)         在android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1392)         在android.view.ViewRootImpl $ TraversalRunnable.run(ViewRootImpl.java:6752)         在android.view.Choreographer $ CallbackRecord.run(Choreographer.java:911)         在android.view.Choreographer.doCallbacks(Choreographer.java:723)         在android.view.Choreographer.doFrame(Choreographer.java:658)         在android.view.Choreographer $ FrameDisplayEventReceiver.run(Choreographer.java:897)         在android.os.Handler.handleCallback(Handler.java:790)         在android.os.Handler.dispatchMessage(Handler.java:99)         在android.os.Looper.loop(Looper.java:164)         在android.app.ActivityThread.main(ActivityThread.java:6494)         在java.lang.reflect.Method.invoke(本机方法)         在com.android.internal.os.RuntimeInit $ MethodAndArgsCaller.run(RuntimeInit.java:438)         在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

4 个答案:

答案 0 :(得分:2)

可能有两种情况。

1)您拥有MainActivity.java类,但尚未创建activity_main.xml,这就是为什么您没有在Android清单中将您声明为Activity的原因。

2)您同时拥有java类和xml类,但没有在android清单中声明您的活动。

注意仅当您忘记在android清单中声明您的活动时,才会发生此问题。

答案 1 :(得分:1)

此错误的可能性如下。

  1. 您忘记延长您的活动

     var AWS = require("aws-sdk");
    
     AWS.config.update({
       region: "us-west-2",
       endpoint: "http://localhost:8000"
     });
    
     var docClient = new AWS.DynamoDB.DocumentClient();
    
    
     var params = {
         isDeleted : false
     };
    
     docClient.query(params, function(err, data) {
         if (err) {
             console.error("Unable to query. Error:", JSON.stringify(err, null, 2));
         } else {
             console.log("Query succeeded.");
         }
     });
    
  2. 您使用了错误的软件包名称来注册您的活动

    class MainActvity extends AppCompatActivity
    

根据您的包裹名称:

MainActivity.java

     <activity
        android:name="com.keval.raagbhandaar.MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

AndroidManifest.xml

package com.keval.raagbhandaar;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}

答案 2 :(得分:0)

.MainActivity是您的类路径吗?

您需要将整个路径设置为“ .myfolder.MainActivity”吗?

答案 3 :(得分:0)

您是否检查了日志错误 java.lang.RuntimeException:画布:试图绘制太大(558306000bytes)的位图。在

处的android.view.RecordingCanvas.drawBitmap(RecordingCanvas.java:97)处android.view.DisplayListCanvas.throwIfCannotDraw(DisplayListCanvas.java:229)处

是说您正在使用的图像尺寸过大,请尝试减小图像尺寸并重新运行。可能会起作用