启动应用程序时ClassNotFound

时间:2015-06-22 15:41:03

标签: android wear-os

我正在尝试为Android服装创建一个应用程序,但是一旦应用程序启动我就会收到此错误。

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "com.demo.wear"
        minSdkVersion 21
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.google.android.support:wearable:1.2.0'
    compile 'com.google.android.gms:play-services-wearable:7.5.0'

    provided "org.projectlombok:lombok:1.16.4"

    compile 'com.jakewharton:butterknife:6.1.0'
}

我看到很多关于这个主题的问题,但我找不到解决方案。

以下是需要的清单和gradle文件。

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.demo.wear" >

    <uses-feature android:name="android.hardware.type.watch" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.DeviceDefault" >
        <activity
            android:name="com.demo.wear.ui.WishesActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

</manifest>

清单

package com.demo.wear.ui;

import android.app.Activity;
import android.content.Intent;
import android.content.IntentSender;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.wearable.view.WearableListView;
import android.widget.Toast;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.wearable.Asset;
import com.google.android.gms.wearable.DataApi;
import com.google.android.gms.wearable.DataEvent;
import com.google.android.gms.wearable.DataEventBuffer;
import com.google.android.gms.wearable.DataMap;
import com.google.android.gms.wearable.DataMapItem;
import com.google.android.gms.wearable.Wearable;
import com.demo.wear.R;
import com.demo.wear.models.Wish;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

import butterknife.ButterKnife;
import butterknife.InjectView;

public class WishesActivity extends Activity implements
        DataApi.DataListener,
        GoogleApiClient.ConnectionCallbacks,
        GoogleApiClient.OnConnectionFailedListener, WearableListView.ClickListener {

    private static final String WISH_LIST_PATH = "/whishlist";
    private static final int RC_GOOGLE_API_CONNECTION_ERROR = 0;

    @InjectView(R.id.lstWishes_wishesActivity) WearableListView lstWishes;

    private GoogleApiClient googleApiClient;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_wishes);
        ButterKnife.inject(this);

        lstWishes.setAdapter(new WishesAdapter());
        lstWishes.setClickListener(WishesActivity.this);

        googleApiClient = new GoogleApiClient.Builder(this)
                .addApi(Wearable.API)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .build();
    }

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

    @Override
    protected void onStop() {
        Wearable.DataApi.removeListener(googleApiClient, this);
        googleApiClient.disconnect();
        super.onStop();
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        switch (requestCode) {
            case RC_GOOGLE_API_CONNECTION_ERROR:
                if (resultCode == RESULT_OK) {
                    if (!googleApiClient.isConnecting() && !googleApiClient.isConnected()) {
                        googleApiClient.connect();
                    }
                }
                break;
        }
    }

    @Override
    public void onConnected(Bundle bundle) {
        Wearable.DataApi.addListener(googleApiClient, this);
    }

    @Override
    public void onConnectionSuspended(int i) {
        googleApiClient.connect();
    }

    @Override
    public void onConnectionFailed(ConnectionResult connectionResult) {
        if (connectionResult.hasResolution()) {
            try {
                connectionResult.startResolutionForResult(this, RC_GOOGLE_API_CONNECTION_ERROR);
            } catch (IntentSender.SendIntentException e) {
                googleApiClient.connect();
            }
        } else {
            Toast.makeText(this, "Error connecting with google API", Toast.LENGTH_SHORT).show();
        }
    }

    @Override
    public void onDataChanged(DataEventBuffer dataEventBuffer) {
        for (DataEvent dataEvent : dataEventBuffer) {
            if (dataEvent.getDataItem().getUri().getPath().equals(WISH_LIST_PATH)) {
                DataMap dataMap = DataMapItem.fromDataItem(dataEvent.getDataItem()).getDataMap();
                List<Wish> wishes = new ArrayList<>();
                for (DataMap wishDataMap : dataMap.getDataMapArrayList("wishes")) {
                    Bitmap image = loadBitmapFromAsset(wishDataMap.getAsset("image"));
                    Wish wish = new Wish(wishDataMap.getString("name"), image);
                    wishes.add(wish);
                }

            }
        }
    }

    public Bitmap loadBitmapFromAsset(Asset asset) {
        ConnectionResult result = googleApiClient.blockingConnect(10000, TimeUnit.MILLISECONDS);
        if (!result.isSuccess()) {
            return null;
        }

        // convert asset into a file descriptor and block until it's ready
        InputStream assetInputStream = Wearable.DataApi.getFdForAsset(googleApiClient, asset).await().getInputStream();
        googleApiClient.disconnect();

        if (assetInputStream == null) {
            return null;
        }
        // decode the stream into a bitmap
        return BitmapFactory.decodeStream(assetInputStream);
    }

    @Override
    public void onClick(WearableListView.ViewHolder viewHolder) {
        Wish wish = (Wish) viewHolder.itemView.getTag();

    }

    @Override
    public void onTopEmptyRegionClick() {

    }
}

这里是相关的活动

selecteddata_all = data.select(name = "Temperature")[0]

selecteddata1, lats1, lons1 = selecteddata_all.data(lat1=20,lat2=60,lon1=335,lon2=360)
selecteddata2, lats2, lons2 = selecteddata_all.data(lat1=20,lat2=60,lon1=0,lon2=30)

lons         = np.hstack((lons1,lons2))
lats         = np.hstack((lats1,lats2))
selecteddata = np.hstack((selecteddata1,selecteddata2))

1 个答案:

答案 0 :(得分:0)

一个正常的原因是活动的$scope.toHtml = function(string){ return $sce.trustAsHtml(string); }; - 属性中的包名称是错误的,但据我所知,在你的情况下它是正确的,我也看了一些我自己的gradle- / manifest-files,你的两个似乎都没问题。

因此我建议尝试清理整个项目,然后完全重建它(假设您使用的是Android Studio:Build-&gt; Clean Project和Build-&gt; Make Project)。这通常对我的情况有帮助。