1

我下载了适用于 Android 的 Scringo SDK ( https://dev.scringo.com/downloads/scringo-android-2.1.10.zip )。

在 .zip 文件中存储了一个名为“ScringoSample”的文件夹,其中包含一个完整的 Android 应用程序结构。

当我开始这个示例时,我变成了错误

06-06 08:58:58.315: E/AndroidRuntime(1197): FATAL EXCEPTION: main
06-06 08:58:58.315: E/AndroidRuntime(1197): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.scringo.scringosample/com.scringo.scringosample.MainActivity}: android.view.InflateException: Binary XML file line #36: Error inflating class com.scringo.ScringoLeftActivationButton
06-06 08:58:58.315: E/AndroidRuntime(1197):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
06-06 08:58:58.315: E/AndroidRuntime(1197):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
06-06 08:58:58.315: E/AndroidRuntime(1197):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
06-06 08:58:58.315: E/AndroidRuntime(1197):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
06-06 08:58:58.315: E/AndroidRuntime(1197):     at android.os.Handler.dispatchMessage(Handler.java:99)
06-06 08:58:58.315: E/AndroidRuntime(1197):     at android.os.Looper.loop(Looper.java:137)
06-06 08:58:58.315: E/AndroidRuntime(1197):     at android.app.ActivityThread.main(ActivityThread.java:5039)
06-06 08:58:58.315: E/AndroidRuntime(1197):     at java.lang.reflect.Method.invokeNative(Native Method)
06-06 08:58:58.315: E/AndroidRuntime(1197):     at java.lang.reflect.Method.invoke(Method.java:511)
06-06 08:58:58.315: E/AndroidRuntime(1197):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
06-06 08:58:58.315: E/AndroidRuntime(1197):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
06-06 08:58:58.315: E/AndroidRuntime(1197):     at dalvik.system.NativeStart.main(Native Method)
06-06 08:58:58.315: E/AndroidRuntime(1197): Caused by: android.view.InflateException: Binary XML file line #36: Error inflating class com.scringo.ScringoLeftActivationButton
06-06 08:58:58.315: E/AndroidRuntime(1197):     at android.view.LayoutInflater.createView(LayoutInflater.java:613)
06-06 08:58:58.315: E/AndroidRuntime(1197):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
06-06 08:58:58.315: E/AndroidRuntime(1197):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
06-06 08:58:58.315: E/AndroidRuntime(1197):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
06-06 08:58:58.315: E/AndroidRuntime(1197):     at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
06-06 08:58:58.315: E/AndroidRuntime(1197):     at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
06-06 08:58:58.315: E/AndroidRuntime(1197):     at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
06-06 08:58:58.315: E/AndroidRuntime(1197):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
06-06 08:58:58.315: E/AndroidRuntime(1197):     at android.app.Activity.setContentView(Activity.java:1881)
06-06 08:58:58.315: E/AndroidRuntime(1197):     at com.scringo.scringosample.MainActivity.onCreate(MainActivity.java:35)
06-06 08:58:58.315: E/AndroidRuntime(1197):     at android.app.Activity.performCreate(Activity.java:5104)
06-06 08:58:58.315: E/AndroidRuntime(1197):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
06-06 08:58:58.315: E/AndroidRuntime(1197):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
06-06 08:58:58.315: E/AndroidRuntime(1197):     ... 11 more
06-06 08:58:58.315: E/AndroidRuntime(1197): Caused by: java.lang.reflect.InvocationTargetException
06-06 08:58:58.315: E/AndroidRuntime(1197):     at java.lang.reflect.Constructor.constructNative(Native Method)
06-06 08:58:58.315: E/AndroidRuntime(1197):     at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
06-06 08:58:58.315: E/AndroidRuntime(1197):     at android.view.LayoutInflater.createView(LayoutInflater.java:587)
06-06 08:58:58.315: E/AndroidRuntime(1197):     ... 23 more
06-06 08:58:58.315: E/AndroidRuntime(1197): Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x0
06-06 08:58:58.315: E/AndroidRuntime(1197):     at android.content.res.Resources.getValue(Resources.java:1014)
06-06 08:58:58.315: E/AndroidRuntime(1197):     at android.content.res.Resources.loadXmlResourceParser(Resources.java:2139)
06-06 08:58:58.315: E/AndroidRuntime(1197):     at android.content.res.Resources.getLayout(Resources.java:853)
06-06 08:58:58.315: E/AndroidRuntime(1197):     at android.view.LayoutInflater.inflate(LayoutInflater.java:394)
06-06 08:58:58.315: E/AndroidRuntime(1197):     at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
06-06 08:58:58.315: E/AndroidRuntime(1197):     at com.scringo.ScringoActivationButton.<init>(ScringoActivationButton.java:26)
06-06 08:58:58.315: E/AndroidRuntime(1197):     at com.scringo.ScringoLeftActivationButton.<init>(ScringoLeftActivationButton.java:12)
06-06 08:58:58.315: E/AndroidRuntime(1197):     ... 26 more

MainActivity.java:

package com.scringo.scringosample;

import java.io.InputStream;

import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

import com.scringo.Scringo;
import com.scringo.Scringo.ScringoIcon;
import com.scringo.ScringoActivationButton;
import com.scringo.ScringoEventHandler;
import com.scringo.ScringoLeftRibbonButton;
import com.scringo.ScringoLikeButton;
import com.scringo.ScringoLikeButton.ScringoLikeObjectType;
import com.scringo.utils.ScringoLogger.ScringoLogLevel;
//import com.scringo.ScringoRightRibbonButton;

public class MainActivity extends FragmentActivity {
    private final String RIVER_URL = "http://ichef.bbci.co.uk/naturelibrary/images/ic/credit/640x395/r/ri/river/river_1.jpg";

    private Scringo scringo = new Scringo(this);

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

        new DownloadImageTask((ImageView) findViewById(R.id.riverImage)).execute(RIVER_URL);

        scringo.setLogLevel(ScringoLogLevel.SCRINGO_LOG_LEVEL_DEBUG);
        Scringo.setDebugMode(true);
        scringo.setIcon(ScringoIcon.PERSON);
        scringo.init(savedInstanceState);

        ((ScringoActivationButton) findViewById(R.id.activationButton)).setScringo(scringo);
        ((ScringoLeftRibbonButton) findViewById(R.id.activationRibbonLeft)).setScringo(scringo);
//      ((ScringoRightRibbonButton) findViewById(R.id.activationRibbonRight)).setScringo(scringo);

        ((ScringoLikeButton) findViewById(R.id.riverLikeButton)).setLikeObject(scringo, "http://ichef.bbci.co.uk/naturelibrary/images/ic/credit/640x395/r/ri/river/river_1.jpg", ScringoLikeObjectType.IMAGE, "A River");

        findViewById(R.id.riverFeedButton).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                scringo.sendFeed("Yet another very nice river", "http://upload.wikimedia.org/wikipedia/commons/thumb/5/5c/Loboc_river.png/220px-Loboc_river.png", 
                        "Menya River", "In Papua New Guinea", "View", "http://upload.wikimedia.org/wikipedia/commons/thumb/5/5c/Loboc_river.png/220px-Loboc_river.png");
            }
        });

        scringo.setEventHandler(new ScringoEventHandler() {
            @Override
            public void onPostItemClicked(String arg0) {
                Intent intent = new Intent(MainActivity.this, ImageViewActivity.class);
                intent.putExtra("url", arg0);
                startActivity(intent);
            }

            @Override
            public void onMenuItemClicked(String arg0) {
                Toast.makeText(MainActivity.this, "The App Optional Custom button " + arg0 + " Clicked", Toast.LENGTH_LONG).show();
            }
        });
    }

    @Override
    protected void onStart() {
        super.onStart();
        scringo.onStart();
    }

    @Override
    protected void onStop() {
        super.onStop();
        scringo.onStop();
    }

    @Override
    public void onBackPressed() {
        if (!scringo.onBackPressed()) {
            super.onBackPressed();
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
          ImageView bmImage;

          public DownloadImageTask(ImageView bmImage) {
              this.bmImage = bmImage;
          }

          protected Bitmap doInBackground(String... urls) {
              String urldisplay = urls[0];
              Bitmap mIcon11 = null;
              try {
                InputStream in = new java.net.URL(urldisplay).openStream();
                mIcon11 = BitmapFactory.decodeStream(in);
              } catch (Exception e) {
                  Log.e("Error", e.getMessage());
                  e.printStackTrace();
              }
              return mIcon11;
          }

          protected void onPostExecute(Bitmap result) {
              bmImage.setImageBitmap(result);
          }
    }
}

和 ImageViewActivity.java

package com.scringo.scringosample;

import java.io.InputStream;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.widget.ImageView;

import com.scringo.Scringo;

public class ImageViewActivity extends Activity {
    private Scringo scringo = new Scringo(this);

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_image_view);
        String url = getIntent().getStringExtra("url");
        scringo.init(savedInstanceState);
        new DownloadImageTask((ImageView)findViewById(R.id.image)).execute(url);
    }

    private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
        ImageView bmImage;

        public DownloadImageTask(ImageView bmImage) {
            this.bmImage = bmImage;
        }

        protected Bitmap doInBackground(String... urls) {
            String urldisplay = urls[0];
            Bitmap mIcon11 = null;
            try {
                InputStream in = new java.net.URL(urldisplay).openStream();
                mIcon11 = BitmapFactory.decodeStream(in);
            } catch (Exception e) {
                Log.e("Error", e.getMessage());
                e.printStackTrace();
            }
            return mIcon11;
        }

        protected void onPostExecute(Bitmap result) {
            bmImage.setImageBitmap(result);
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.image_view, menu);
        return true;
    }

    @Override
    protected void onStart() {
        super.onStart();
        scringo.onStart();
    }

    @Override
    protected void onStop() {
        super.onStop();
        scringo.onStop();
    }

    @Override
    public void onBackPressed() {
        if (!scringo.onBackPressed()) {
            super.onBackPressed();
        }
    }
}
4

1 回答 1

1

这通常发生在 ScringoResources 未设置为项目的依赖项时。

  1. 将 ScringoResources 导入 Eclipse 工作区
  2. 右键项目 -> 属性 -> Android
  3. 在底部单击“添加...”并添加 ScringoResources
  4. 在 ADT 22 中有一个烦人的问题,你需要遵循这个

这通常可以解决它。

在 Scringo < 2.2 中可能导致此问题的另一个问题是,如果您没有在 scringo.properties 文件(资产文件夹)中设置 facebook.app.id

于 2013-06-06T09:18:14.143 回答