Android Studio-MainActivity甚至不存在于新项目中



我发布了一个问题,关于我在android studio中收到的一个空指针,该指针与始终为空的上下文有关。此外,无论我如何分配,这个错误都会不断出现。

我一直没能找到这个问题的解决方案,所以决定开始一个全新的项目——没有写一行代码,我也会遇到同样的错误。

控制台错误

$ adb shell am start -n "za.co.freelanceweb.scheduler/za.co.freelanceweb.scheduler.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Error while executing: am start -n "za.co.freelanceweb.scheduler/za.co.freelanceweb.scheduler.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=za.co.freelanceweb.scheduler/.MainActivity }
Error type 3
Error: Activity class {za.co.freelanceweb.scheduler/za.co.freelanceweb.scheduler.MainActivity} does not exist.
Error while Launching activity

AndroidManifest.xml(UNTOUCHED(

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="za.co.freelanceweb.scheduler">
<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=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

渐变项目文件(UNTOUCHED(

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

gradle应用程序文件(UNTOUCHED(

apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "za.co.freelanceweb.scheduler"
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

MainActivity.java(未完成(

package za.co.freelanceweb.scheduler;
import androidx.appcompat.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);
}
}

删除此Three文件夹并重新启动android Studio。这样做不会删除旧项目。但不要删除Android Studio项目文件夹

最新更新