java.lang.RuntimeException:无法实例化Android存根 [英] java.lang.RuntimeException: Unable to instantiate Android stub

查看:97
本文介绍了java.lang.RuntimeException:无法实例化Android存根的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很抱歉,如果这是一个重复的问题,它看起来很基本,但是我找不到任何答案. 我试图在Kindle Fire平板电脑上运行Amazon的SNS KindleMobilePushApp演示应用程序,但出现以下错误:

Sorry if this is a repeated question, it looks basic but I couldn't find any answer. I'm trying to run Amazon's SNS KindleMobilePushApp demo app in a Kindle Fire tablet, but I get the following error:

    10-09 14:19:33.508    3101-3101/? W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x40b05228)
10-09 14:19:33.508    3101-3101/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
    java.lang.RuntimeException: Unable to instantiate service com.amazonaws.kindletest.ADMMessageHandler: java.lang.RuntimeException: Stub!
            at android.app.ActivityThread.handleCreateService(ActivityThread.java:2315)
            at android.app.ActivityThread.access$1600(ActivityThread.java:127)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1231)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4533)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.RuntimeException: Stub!
            at com.amazon.device.messaging.ADMMessageHandlerBase.<init>(Unknown Source)
            at com.amazonaws.kindletest.ADMMessageHandler.<init>(ADMMessageHandler.java:32)
            at java.lang.Class.newInstanceImpl(Native Method)
            at java.lang.Class.newInstance(Class.java:1319)
            at android.app.ActivityThread.handleCreateService(ActivityThread.java:2312)
            at android.app.ActivityThread.access$1600(ActivityThread.java:127)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1231)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4533)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
            at dalvik.system.NativeStart.main(Native Method)
10-09 14:21:08.359    3101-3101/? E/AndroidRuntime﹕ Handle UnCaght exceptions. KILLING PID: 3101

这发生在示例项目的此类的默认构造函数中:

This happens in the default constructor of this class of the sample project:

package com.amazonaws.kindletest;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import android.app.Notification;
import android.app.Notification.Builder;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

import com.amazon.device.messaging.ADMConstants;
import com.amazon.device.messaging.ADMMessageHandlerBase;
import com.amazon.device.messaging.ADMMessageReceiver;

public class ADMMessageHandler extends ADMMessageHandlerBase {
    private static String savedMessage = null;
    private static int numberOfMissedMessages = 0;
    public static boolean inBackground = true;

    public ADMMessageHandler(){
        super(ADMMessageHandler.class.getName()); //ERROR!
    }

    ...
}

这是从亚马逊图书馆的此类中派生的:

Which is derived from this class in Amazon's library:

package com.amazon.device.messaging.ADMMessageHandlerBase

import android.app.IntentService;
import android.content.Intent;

public abstract class ADMMessageHandlerBase extends IntentService {
    public ADMMessageHandlerBase(String var1) {
        super((String)null);
        throw new RuntimeException("Stub!");
    }

    protected final void onHandleIntent(Intent var1) {
        throw new RuntimeException("Stub!");
    }

    protected abstract void onMessage(Intent var1);

    protected abstract void onRegistrationError(String var1);

    protected abstract void onRegistered(String var1);

    protected abstract void onUnregistered(String var1);
}

我知道Amazon的类是一个存根,打算由实际的实现替换,但是如何完成?这是我的build.gradle:

I understand Amazon's class is a stub intended to be replaced by an actual implementation, but how is that done?. This is my build.gradle:

buildscript {
    repositories {
        mavenCentral() // or jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:1+'
    }
}
apply plugin: 'com.android.application'
android {
    compileSdkVersion 18
    buildToolsVersion "23.0.1"

    dependencies {
        compile fileTree(dir: 'libs', include: '*.jar')
    }

    defaultConfig {
        applicationId "com.amazonaws.kindletest"
        minSdkVersion 11
        targetSdkVersion 18
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

并显示:

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

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

   <!-- This permission ensures that no other application can intercept your ADM messages. It
   should have the form packagename.permission.RECIEVE_ADM_MESSAGE where packagename is the
   name defined in the "package" property of the manifest tag. --> 
    <permission android:name="com.amazonaws.kindletest.permission.RECEIVE_ADM_MESSAGE"
        android:protectionLevel="signature"/>

    <!-- Required permissions -->
    <uses-permission android:name="com.amazonaws.kindletest.permission.RECEIVE_ADM_MESSAGE"/>
    <uses-permission android:name="com.amazon.device.messaging.permission.RECEIVE"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.WAKE_LOCK"/>

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"        
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.amazonaws.kindletest.KindleMobilePushApp"
            android:screenOrientation="portrait"
            android:label="@string/title_activity_main"
            android:launchMode="singleTop" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

        <!-- Your application's API Key -->
        <meta-data android:name="AmazonAPIKey" android:value="@string/api_key"/>

        <!--  Declare your ADMMessageHandlerBase implementation as a service -->
        <service android:name="com.amazonaws.kindletest.ADMMessageHandler" 
            android:exported="false" />

        <!-- You must explicitly enable ADM. You must also declare whether your application will run with or without ADM.
        If you specify android:required="false", your app must degrade gracefully when ADM is unavailable. -->
        <amazon:enable-feature android:name="com.amazon.device.messaging" 
            android:required="true" />

        <receiver android:name="com.amazonaws.kindletest.ADMMessageHandler$MessageAlertReceiver" 
            android:permission="com.amazon.device.messaging.permission.SEND">
            <intent-filter>
               <action android:name="com.amazon.device.messaging.intent.REGISTRATION" /> 
               <action android:name="com.amazon.device.messaging.intent.RECEIVE" /> 
               <category android:name="com.amazonaws.kindletest"/>
            </intent-filter>
        </receiver>

    </application>

</manifest>

我已经在亚马逊的开发人员中发布了发布此信息论坛尚未成功.请让我知道是否需要更多信息,谢谢.

I have posted posted about this in Amazon's developer forum with no success yet. Please let me know if you need more information, thank you.

推荐答案

这就是为什么出现此问题的原因:

Here is why you get the issue :

您需要本地amazon-device-messaging.jar文件来编译您的应用程序,但是您无需在运行时将其包括在内,因为amazon设备将具有必要的类和方法.

You need the local amazon-device-messaging.jar file to compile your app, however you do not need to include it during runtime as the amazon device will have the necessary classes and methods.

这是解决方法:

代替

compile files('libs/amazon-device-messaging-1.0.1.jar')

您必须使用

provided files('libs/amazon-device-messaging-1.0.1.jar')

在您的情况下:您可以使用以下内容替换依赖项:

In your case : you can replace your dependencies by the following :

    ...
        dependencies {
            compile fileTree(dir: 'libs', include: '*.jar', exclude: 'amazon-device-messaging-1.0.1.jar')
            provided files('libs/amazon-device-messaging-1.0.1.jar')
        }
    ...

重复的答案: Android Studio运行时错误存根!在com.amazon.device.messaging.ADMMessageReceiver中.< init>()

这篇关于java.lang.RuntimeException:无法实例化Android存根的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆