有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java E/AndroidRuntime:致命异常:天气应用程序的主

这就是我得到的错误:

E/AndroidRuntime:致命异常:主 进程:com。安德罗斯托克。myweatherapp,PID:25225 JAVAlang.RuntimeException:无法实例化活动组件信息{com.androstock.myweatherapp/com.androstock.myweatherapp.MainActivity}:java。lang.ClassNotFoundException:在路径:DexPathList[[zip文件”/data/app/com.androstock.myweatherapp-UMxK9GKnMSBzW_UbsKC4Nw==/base.apk],zip文件/data/app/com.androstock.myweatherapp-UMxK9GKnMSBzW_-UbsKC4Nw==/split_libu dependencies_apk.apk],zip文件中未找到类“com.androstock.myweatherapp.myweatherapp-umk9gknmsbzw==/com“/data/app/com.androstock.myweatherapp-UMxK9GKnMSBzW_UbsKC4Nw==/split_lib_slice_0_apk.apk”,zip文件/data/app/com.androstock.myweatherapp-UMxK9GKnMSBzW_UbsKC4Nw==/split_lib slice_1_apk.apk”,zip文件“/data/app/com.androstock.myweatherapp-umk9gknmsbzw=/split lib_ubskc2; slice=/apk”,zip文件“/data/app/com.androstock.myweatherapp-UMxK9GKnMSBzW_UbsKC4Nw=/split_lib_slice_3_apk.apk”,zip文件“/data/app/com.androstock.myweatherapp-UMxK9GKnMSBzW_UbsKC4Nw==/split_lib slice_slice_4_apk.apk”,zip文件“/data/app/com.androstock.myweatherapp-umx9gknmsbzw_UbsKC4Nw=/split lib slice.apk=/apk”,zip文件“/data/app/com.androstock.myweatherapp-UMxK9GKnMSBzW_UbsKC4Nw=/split_lib_slice_6_apk.apk”,zip文件“/data/app/com.androstock.myweatherapp-UMxK9GKnMSBzW_UbsKC4Nw==/split_lib slice_slice_7_apk.apk”,zip文件“/data/app/com.androstock.myweatherapp-umx9gknmsbzw_UbsKC4Nw=/split lib lib slice=,zip文件“/data/app/com.androstock.myweatherapp-UMxK9GKnMSBzW_UbsKC4Nw==/split_lib_slice_9_apk.apk”],nativeLibraryDirectories=[/data/app/com.androstock.myweatherapp-UMxK9GKnMSBzW_UbsKC4Nw===/lib/x86,/system/lib,/vendor/lib]] 在安卓。应用程序。活动线程。performLaunchActivity(ActivityThread.java:2679) 在安卓。应用程序。活动线程。handleLaunchActivity(ActivityThread.java:2856) 在安卓。应用程序。活动线程-wrap11(未知来源:0) 在安卓。应用程序。ActivityThread$H.handleMessage(ActivityThread.java:1589) 在安卓。操作系统。汉德勒。dispatchMessage(Handler.java:106) 在安卓。操作系统。活套。loop(Looper.java:164) 在安卓。应用程序。活动线程。main(ActivityThread.java:6494) 在爪哇。朗,反思一下。方法调用(本机方法) 在com上。安卓内部的操作系统。RuntimeInit$MethodAndArgsCaller。run(RuntimeInit.java:438) 在com上。安卓内部的操作系统。合子体。main(ZygoteInit.java:807) 原因:java。lang.ClassNotFoundException:在路径:DexPathList[[zip文件”/data/app/com.androstock.myweatherapp-UMxK9GKnMSBzW_UbsKC4Nw==/base.apk],zip文件/data/app/com.androstock.myweatherapp-UMxK9GKnMSBzW_-UbsKC4Nw==/split_libu dependencies_apk.apk],zip文件中未找到类“com.androstock.myweatherapp.myweatherapp-umk9gknmsbzw==/com“/data/app/com.androstock.myweatherapp-UMxK9GKnMSBzW_UbsKC4Nw==/split_lib_slice_0_apk.apk”,zip文件/data/app/com.androstock.myweatherapp-UMxK9GKnMSBzW_UbsKC4Nw==/split_lib slice_1_apk.apk”,zip文件“/data/app/com.androstock.myweatherapp-umk9gknmsbzw=/split lib_ubskc2; slice=/apk”,zip文件“/data/app/com.androstock.myweatherapp-UMxK9GKnMSBzW_UbsKC4Nw=/split_lib_slice_3_apk.apk”,zip文件“/data/app/com.androstock.myweatherapp-UMxK9GKnMSBzW_UbsKC4Nw==/split_lib slice_slice_4_apk.apk”,zip文件“/data/app/com.androstock.myweatherapp-umx9gknmsbzw_UbsKC4Nw=/split lib slice.apk=/apk”,zip文件“/data/app/com.androstock.myweatherapp-UMxK9GKnMSBzW_UbsKC4Nw=/split_lib_slice_6_apk.apk”,zip文件“/data/app/com.androstock.myweatherapp-UMxK9GKnMSBzW_UbsKC4Nw==/split_lib slice_slice_7_apk.apk”,zip文件“/data/app/com.androstock.myweatherapp-umx9gknmsbzw_UbsKC4Nw=/split lib lib slice=,zip文件“/data/app/com.androstock.myweatherapp-UMxK9GKnMSBzW_UbsKC4Nw==/split_lib_slice_9_apk.apk”],nativeLibraryD目录=[/data/app/com.androstock.myweatherapp-UMxK9GKnMSBzW_UbsKC4Nw==/lib/x86,/system/lib,/vendor/lib]] 在达尔维克。系统BaseDexClassLoader。findClass(BaseDexClassLoader.java:125) 在爪哇。lang.ClassLoader。loadClass(ClassLoader.java:379) 在爪哇。lang.ClassLoader。loadClass(ClassLoader.java:312) E/AndroidRuntime:在安卓上。应用程序。仪器。newActivity(Instrumentation.java:1174) 在安卓。应用程序。活动线程。performLaunchActivity(ActivityThread.java:2669) ... 9更多

这是一个简单的天气应用程序

这是我的Android清单xml文件

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
package="com.androstock.myweatherapp" >

<uses-permission 安卓:name="安卓.permission.INTERNET"/>

<application
    安卓:allowBackup="true"
    安卓:icon="@mipmap/ic_launcher"
    安卓:label="MyWeatherApp"
    安卓:roundIcon="@mipmap/ic_launcher_round"
    安卓:supportsRtl="true"
    安卓:theme="@style/AppTheme">
    <activity 安卓:name=".MainActivity">
        <intent-filter>
            <action 安卓:name="安卓.intent.action.MAIN" />

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

</manifest>

这是我的活动主mxl文件

<RelativeLayout 
xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
xmlns:tools="http://schemas.安卓.com/tools"
安卓:layout_width="match_parent"
安卓:layout_height="match_parent"
安卓:background="#3F51B5"
安卓:padding="20dp">

<TextView
    安卓:id="@+id/city_field"
    安卓:layout_width="wrap_content"
    安卓:layout_height="wrap_content"
    安卓:layout_alignParentTop="true"
    安卓:layout_centerHorizontal="true"
    安卓:textColor="#FFFFFF"
    安卓:textAppearance="?安卓:attr/textAppearanceLarge" />

<TextView
    安卓:id="@+id/updated_field"
    安卓:layout_width="wrap_content"
    安卓:layout_height="wrap_content"
    安卓:layout_below="@+id/city_field"
    安卓:layout_centerHorizontal="true"
    安卓:textColor="#FFFFFF"
    安卓:textAppearance="?安卓:attr/textAppearanceMedium"
    安卓:textSize="13sp" />

<TextView
    安卓:id="@+id/weather_icon"
    安卓:layout_width="wrap_content"
    安卓:layout_height="wrap_content"
    安卓:layout_centerVertical="true"
    安卓:layout_centerHorizontal="true"
    安卓:textColor="#FFFFFF"
    安卓:textAppearance="?安卓:attr/textAppearanceLarge"
    安卓:textSize="90sp"
    />

<TextView
    安卓:id="@+id/current_temperature_field"
    安卓:layout_width="wrap_content"
    安卓:layout_height="wrap_content"
    安卓:layout_alignParentBottom="true"
    安卓:layout_centerHorizontal="true"
    安卓:textColor="#FFFFFF"
    安卓:textAppearance="?安卓:attr/textAppearanceLarge"
    安卓:textSize="50sp" />

<TextView
    安卓:id="@+id/details_field"
    安卓:layout_width="wrap_content"
    安卓:layout_height="wrap_content"
    安卓:layout_below="@+id/weather_icon"
    安卓:layout_centerHorizontal="true"
    安卓:textColor="#FFFFFF"
    安卓:textAppearance="?安卓:attr/textAppearanceMedium"
    />
<TextView
    安卓:id="@+id/humidity_field"
    安卓:layout_width="wrap_content"
    安卓:layout_height="wrap_content"
    安卓:layout_below="@+id/details_field"
    安卓:layout_centerHorizontal="true"
    安卓:textColor="#FFFFFF"
    安卓:textAppearance="?安卓:attr/textAppearanceMedium"
    />
<TextView
    安卓:id="@+id/pressure_field"
    安卓:layout_width="wrap_content"
    安卓:layout_height="wrap_content"
    安卓:layout_below="@+id/humidity_field"
    安卓:layout_centerHorizontal="true"
    安卓:textColor="#FFFFFF"
    安卓:textAppearance="?安卓:attr/textAppearanceMedium"
    />

</RelativeLayout>

这是我的功能。java文件

package com.androstock.myweatherapp;

import 安卓.os.AsyncTask;
import 安卓.util.Log;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.text.DateFormat;
import java.util.Date;
import java.util.Locale;

public class Function {

// Project Created by Ferdousur Rahman Shajib
// www.androstock.com

private static final String OPEN_WEATHER_MAP_URL = 
"http://api.openweathermap.org/data/2.5/weather? 
lat=%s&lon=%s&units=metric";

private static final String OPEN_WEATHER_MAP_API = 
"61c4e901819fba78364061df78e90f9a";

public static String setWeatherIcon(int actualId, long sunrise, long 
sunset) {
    int id = actualId / 100;
    String icon = "";
    if (actualId == 800) {
        long currentTime = new Date().getTime();
        if (currentTime >= sunrise && currentTime < sunset) {
            icon = "&#xf00d;";
        } else {
            icon = "&#xf02e;";
        }
    } else {
        switch (id) {
            case 2:
                icon = "&#xf01e;";
                break;
            case 3:
                icon = "&#xf01c;";
                break;
            case 7:
                icon = "&#xf014;";
                break;
            case 8:
                icon = "&#xf013;";
                break;
            case 6:
                icon = "&#xf01b;";
                break;
            case 5:
                icon = "&#xf019;";
                break;
        }
    }
    return icon;
}


public interface AsyncResponse {

    void processFinish(String output1, String output2, String output3, 
String output4, String output5, String output6, String output7, String 
output8);
}


public static class placeIdTask extends AsyncTask<String, Void, 
JSONObject> {

    public AsyncResponse delegate = null;//Call back interface

    public placeIdTask(AsyncResponse asyncResponse) {
        delegate = asyncResponse;//Assigning call back 
interfacethrough constructor
    }

    @Override
    protected JSONObject doInBackground(String... params) {

        JSONObject jsonWeather = null;
        try {
            jsonWeather = getWeatherJSON(params[0], params[1]);
        } catch (Exception e) {
            Log.d("Error", "Cannot process JSON results", e);
        }


        return jsonWeather;
    }

    @Override
    protected void onPostExecute(JSONObject json) {
        try {
            if (json != null) {
                JSONObject details 
json.getJSONArray("weather").getJSONObject(0);
                JSONObject main = json.getJSONObject("main");
                DateFormat df = DateFormat.getDateTimeInstance();


                String city = 
json.getString("name").toUpperCase(Locale.US) + ", " + 
json.getJSONObject("sys").getString("country");
                String description = 
details.getString("description").toUpperCase(Locale.US);
                String temperature = String.format("%.2f", 
main.getDouble("temp")) + "°";
                String humidity = main.getString("humidity") + "%";
                String pressure = main.getString("pressure") + " hPa";
                String updatedOn = df.format(new 
Date(json.getLong("dt") * 1000));
                String iconText = setWeatherIcon(details.getInt("id"),
                        json.getJSONObject("sys").getLong("sunrise") * 
1000,
                        json.getJSONObject("sys").getLong("sunset") * 
1000);

                delegate.processFinish(city, description, temperature, 
humidity, pressure, updatedOn, iconText, "" + 
(json.getJSONObject("sys").getLong("sunrise") * 1000));

            }
        } catch (JSONException e) {
            //Log.e(LOG_TAG, "Cannot process JSON results", e);
        }


    }
}


public static JSONObject getWeatherJSON(String lat, String lon) {
    try {
        URL url = new URL(String.format(OPEN_WEATHER_MAP_URL, lat, 
lon));
        HttpURLConnection connection =
                (HttpURLConnection) url.openConnection();

        connection.addRequestProperty("x-api-key", 
OPEN_WEATHER_MAP_API);

        BufferedReader reader = new BufferedReader(
                new InputStreamReader(connection.getInputStream()));

        StringBuffer json = new StringBuffer(1024);
        String tmp = "";
        while ((tmp = reader.readLine()) != null)
            json.append(tmp).append("\n");
        reader.close();

        JSONObject data = new JSONObject(json.toString());

        // This value will be 404 if the request was not
        // successful
        if (data.getInt("cod") != 200) {
            return null;
        }

        return data;
    } catch (Exception e) {
        return null;
    }


}


}

这是我的主要活动。java文件

package com.androstock.myweatherapp;
/**
* Created by SHAJIB on 7/4/2017.
*/
import 安卓.graphics.Typeface;
import 安卓.os.Bundle;
import 安卓.support.v7.app.AppCompatActivity;
import 安卓.text.Html;
import 安卓.widget.TextView;

public class MainActivity extends AppCompatActivity {

// Project Created by Ferdousur Rahman Shajib
// www.androstock.com


TextView cityField, detailsField, currentTemperatureField, 
humidity_field, pressure_field, weatherIcon, updatedField;

Typeface weatherFont;

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


    weatherFont = 
Typeface.createFromAsset(getApplicationContext().getAssets(), 
"fonts/weathericons-regular-webfont.ttf");

    cityField = (TextView)findViewById(R.id.city_field);
    updatedField = (TextView)findViewById(R.id.updated_field);
    detailsField = (TextView)findViewById(R.id.details_field);
    currentTemperatureField = 
(TextView)findViewById(R.id.current_temperature_field);
    humidity_field = (TextView)findViewById(R.id.humidity_field);
    pressure_field = (TextView)findViewById(R.id.pressure_field);
    weatherIcon = (TextView)findViewById(R.id.weather_icon);
    weatherIcon.setTypeface(weatherFont);


    Function.placeIdTask asyncTask =new Function.placeIdTask(new 
Function.AsyncResponse() {
        public void processFinish(String weather_city, String 
weather_description, String weather_temperature, String 
weather_humidity, String weather_pressure, String weather_updatedOn, 
String weather_iconText, String sun_rise) {

            cityField.setText(weather_city);
            updatedField.setText(weather_updatedOn);
            detailsField.setText(weather_description);
            currentTemperatureField.setText(weather_temperature);
            humidity_field.setText("Humidity: "+weather_humidity);
            pressure_field.setText("Pressure: "+weather_pressure);
            weatherIcon.setText(Html.fromHtml(weather_iconText));

        }
    });
    asyncTask.execute("25.180000", "89.530000"); //  
asyncTask.execute("Latitude", "Longitude")



}


}

我的java中有什么东西混在一起吗?我也只使用模拟器来运行代码,而不是物理设备

人们似乎对我的问题投了反对票。如果有更好的表达方式,请随时通知我。也许你还记得你刚当程序员的时候


共 (0) 个答案