0

好吧 - 似乎在过去的几天里,我已经阅读了几乎所有关于这个主题的威胁,但没有一个有效!

我刚刚开始开发一个新应用程序,一旦创建项目,就会出现错误。

仅作为最后的手段,可以请一些人(或 gal :) )观察他们是否可以发现可能阻碍我的应用程序功能的问题?

主应用程序.java;

 package com.sony.thirdtest;

import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.view.View;
import android.widget.Toast;
import com.sony.smallapp.SmallAppWindow;
import com.sony.smallapp.SmallApplication;

public class MainApplication extends SmallApplication {
private Configuration mConfig;

@Override
public void onCreate() {
    super.onCreate();
    mConfig = new Configuration(getResources().getConfiguration());

    setContentView(R.layout.activity_main);
    setTitle(R.string.app_name);

    SmallAppWindow.Attributes attr = getWindow().getAttributes();
    attr.minWidth = 200;
    attr.minHeight = 200;
    attr.width = 400;
    attr.height = 300;
    attr.flags |= SmallAppWindow.Attributes.FLAG_RESIZABLE;
    getWindow().setAttributes(attr);

    findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Toast.makeText(MainApplication.this, R.string.hello, Toast.LENGTH_SHORT).show();
        }
    });
}

@Override
public void onDestroy() {
    super.onDestroy();
}

@Override
public void onStart() {
    super.onStart();
}

@Override
public void onStop() {
    super.onStop();
}

@Override
protected boolean onSmallAppConfigurationChanged(Configuration newConfig) {
    int diff = newConfig.diff(mConfig);
    mConfig = new Configuration(getResources().getConfiguration());
    // Avoid application from restarting when orientation changed
    if ((diff & ActivityInfo.CONFIG_ORIENTATION) != 0) {
        return true;
    }
    return super.onSmallAppConfigurationChanged(newConfig);
}

}

main_activity.xml;

<manifest  
package="com.sony.thirdtest" 
android:versionCode="1" 
android:versionName="1.0"
xmlns:android="http://schemas.android.com/apk/res/android" >

<uses-sdk android:minSdkVersion="14"
          android:targetSdkVersion="15" />

<uses-permission android:name="com.sony.smallapp.permission.SMALLAPP" />

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >   


    <uses-library android:name="com.sony.smallapp.framework" />

    <service 
        android:name="MainApplication"

        android:exported="true" >

        <intent-filter >

            <action android:name="com.sony.smallapp.intent.action.MAIN" />

            <category android:name="com.sony.smallapp.intent.category.LAUNCHER" />

        </intent-filter>

    </service>

</application>

我能否明确指出这是最后的手段,

亲切的问候。

4

3 回答 3

0

已经很晚了,但我多次面临这个问题,我想分享我的意见。问题在于您的资源文件。检查您的布局、值等。Adt 总是会说import android.Ror import com.yourpackage.R。不要认为快速修复。

于 2013-08-14T12:49:52.107 回答
0

这是可能的错误。findViewById(R.id.button).setOnClickListener(new View.OnClickListener()

以这种方式声明按钮并尝试

            public class MainApplication extends SmallApplication {
             private Configuration mConfig;
             Button button1;

                  @Override
                 public void onCreate() {
                button1 = (Button) findViewById(R.id.button1);
                  button1.setOnClickListener(new OnClickListener()
                      {
                         Toast.makeText(getBaseContext(), 
                    "your message", 
                    Toast.LENGTH_SHORT).show();
                    }
                 }
于 2013-05-23T15:54:07.300 回答
0

它在最终文件中缺少清单应答器。最好先放 xmlns 属性。尝试这个:

<manifest  
    xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.sony.thirdtest" 
    android:versionCode="1" 
    android:versionName="1.0"
     >

    <uses-sdk android:minSdkVersion="14"
              android:targetSdkVersion="15" />

    <uses-permission android:name="com.sony.smallapp.permission.SMALLAPP" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >   


        <uses-library android:name="com.sony.smallapp.framework" />

        <service 
            android:name="MainApplication"

            android:exported="true" >

            <intent-filter >

                <action android:name="com.sony.smallapp.intent.action.MAIN" />

                <category android:name="com.sony.smallapp.intent.category.LAUNCHER" />

            </intent-filter>

        </service>

    </application>
    </manifest>
于 2013-05-23T15:55:07.750 回答