Eclipse:App没有安装!我猜错误是在清单文件中。建议?

时间:2021-07-23 15:23:35

So I've made a test app. The main activity has a button. If you click that button, you go to another activity. But it just doesnt get installed on my phone. I've compiled with API 23 for my Kitkat device. I just cant build an app with two classes when I use intent.

所以我做了一个测试应用程序。主要活动有一个按钮。如果单击该按钮,则转到另一个活动。但它并没有安装在我的手机上。我已经使用API​​ 23编译了我的Kitkat设备。当我使用intent时,我无法构建一个包含两个类的应用程序。

Here is the main activity:

这是主要活动:

 public class MainActivity extends Activity {

 Button b1;

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

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

            Intent i = new Intent("android.intent.action.GOTHAM");
            startActivity(i);
            }
    });

  }


  } 

The second activity:

第二项活动:

 public class gotham extends Activity {

 @Override
 protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.gotham);

 }
 }

Here is the manifest:

这是清单:

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

<uses-sdk
    android:minSdkVersion="11"
    android:targetSdkVersion="21" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".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=".gotham"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.GOTHAM" />

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


 </manifest>

1 个解决方案

#1


1  

First of all, you should name your java classes beginning with an upper-case letter, like Gotham and not gotham.

首先,你应该用大写字母命名你的java类,比如Gotham而不是gotham。

Also in the manifest you can delete the intent filter as it is not needed at all, and you can create the intent in you MainActivity like this:

同样在清单中,您可以删除根本不需要的intent过滤器,并且您可以在MainActivity中创建意图,如下所示:

Intent intent = new Intent(this, Gotham.class);

After you've renamed your gotham activity to Gotham.

在您将Gotham活动重命名为Gotham之后。

If these changes does not solve your problem, check the logcat output and also any error that eclipse produces when trying to build your app.

如果这些更改无法解决您的问题,请检查logcat输出以及eclipse在尝试构建应用程序时产生的任何错误。

#1


1  

First of all, you should name your java classes beginning with an upper-case letter, like Gotham and not gotham.

首先,你应该用大写字母命名你的java类,比如Gotham而不是gotham。

Also in the manifest you can delete the intent filter as it is not needed at all, and you can create the intent in you MainActivity like this:

同样在清单中,您可以删除根本不需要的intent过滤器,并且您可以在MainActivity中创建意图,如下所示:

Intent intent = new Intent(this, Gotham.class);

After you've renamed your gotham activity to Gotham.

在您将Gotham活动重命名为Gotham之后。

If these changes does not solve your problem, check the logcat output and also any error that eclipse produces when trying to build your app.

如果这些更改无法解决您的问题,请检查logcat输出以及eclipse在尝试构建应用程序时产生的任何错误。