AndroidRuntime:FATAL EXCEPTION:main java.lang.RuntimeException:无法启动活动ComponentInfo

时间:2015-10-22 22:22:12

标签: java android parse-platform

美好的一天。我想提前道歉,因为我是Android的新手。有人可以帮助我,我目前正在关注LiveUpdate教程,但无论我做什么,我都无法让它工作,它一直给我致命的错误信息。

这是我的HomepageActivity.java

package com.parse.liveupdate2;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;

import com.parse.ParseObject;

public class HomepageActivity extends AppCompatActivity {

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

        ParseObject gameScore = new ParseObject("GameScore");
        gameScore.put("score", 1337);
        gameScore.put("playerName", "Sean Plott");
        gameScore.put("cheatMode", false);
        gameScore.saveInBackground();

    }

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

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}
}

我的activity_homepage.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context=".MainActivity">

    <TextView
        android:id="@+id/map"
        android:text="@string/hello_world"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

</RelativeLayout>

我的AndroidManifest.xml

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

    <application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".HomepageActivity"
        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>

我的build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "com.parse.liveupdate2"
        minSdkVersion 8
        targetSdkVersion 23
        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.android.support:appcompat-v7:23.0.1'
}

我的logcat

            10-22 22:06:53.652  19945-19945/com.parse.liveupdate2 D/dalvikvm﹕ Late-enabling CheckJNI
            10-22 22:06:53.876  19945-19945/com.parse.liveupdate2 W/dalvikvm﹕ VFY: unable to find class referenced in signature (Landroid/view/SearchEvent;)
            10-22 22:06:53.876  19945-19945/com.parse.liveupdate2 I/dalvikvm﹕ Could not find method android.view.Window$Callback.onSearchRequested, referenced from method android.support.v7.internal.view.WindowCallbackWrapper.onSearchRequested
            10-22 22:06:53.876  19945-19945/com.parse.liveupdate2 W/dalvikvm﹕ VFY: unable to resolve interface method 14132: Landroid/view/Window$Callback;.onSearchRequested (Landroid/view/SearchEvent;)Z
            10-22 22:06:53.876  19945-19945/com.parse.liveupdate2 D/dalvikvm﹕ VFY: replacing opcode 0x72 at 0x0002
            10-22 22:06:53.876  19945-19945/com.parse.liveupdate2 I/dalvikvm﹕ Could not find method android.view.Window$Callback.onWindowStartingActionMode, referenced from method android.support.v7.internal.view.WindowCallbackWrapper.onWindowStartingActionMode
            10-22 22:06:53.876  19945-19945/com.parse.liveupdate2 W/dalvikvm﹕ VFY: unable to resolve interface method 14136: Landroid/view/Window$Callback;.onWindowStartingActionMode (Landroid/view/ActionMode$Callback;I)Landroid/view/ActionMode;
            10-22 22:06:53.876  19945-19945/com.parse.liveupdate2 D/dalvikvm﹕ VFY: replacing opcode 0x72 at 0x0002
            10-22 22:06:53.968  19945-19945/com.parse.liveupdate2 I/dalvikvm﹕ Could not find method android.view.ViewGroup.onRtlPropertiesChanged, referenced from method android.support.v7.widget.Toolbar.onRtlPropertiesChanged
            10-22 22:06:53.968  19945-19945/com.parse.liveupdate2 W/dalvikvm﹕ VFY: unable to resolve virtual method 14033: Landroid/view/ViewGroup;.onRtlPropertiesChanged (I)V
            10-22 22:06:53.968  19945-19945/com.parse.liveupdate2 D/dalvikvm﹕ VFY: replacing opcode 0x6f at 0x0007
            10-22 22:06:53.992  19945-19945/com.parse.liveupdate2 I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.internal.widget.TintTypedArray.getChangingConfigurations
            10-22 22:06:53.992  19945-19945/com.parse.liveupdate2 W/dalvikvm﹕ VFY: unable to resolve virtual method 437: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
            10-22 22:06:53.992  19945-19945/com.parse.liveupdate2 D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
            10-22 22:06:53.992  19945-19945/com.parse.liveupdate2 I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.internal.widget.TintTypedArray.getType
            10-22 22:06:53.992  19945-19945/com.parse.liveupdate2 W/dalvikvm﹕ VFY: unable to resolve virtual method 459: Landroid/content/res/TypedArray;.getType (I)I
            10-22 22:06:53.992  19945-19945/com.parse.liveupdate2 D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
            10-22 22:06:54.004  19945-19945/com.parse.liveupdate2 D/AndroidRuntime﹕ Shutting down VM
            10-22 22:06:54.024  19945-19945/com.parse.liveupdate2 W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xa62d9288)
            10-22 22:06:54.044  19945-19945/com.parse.liveupdate2 E/AndroidRuntime﹕ FATAL EXCEPTION: main
                java.lang.RuntimeException: Unable to start activity ComponentInfo{com.parse.liveupdate2/com.parse.liveupdate2.HomepageActivity}: java.lang.RuntimeException: You must call Parse.initialize(context, oauthKey, oauthSecret) before using the Parse library.
                        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
                        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
                        at android.app.ActivityThread.access$600(ActivityThread.java:130)
                        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
                        at android.os.Handler.dispatchMessage(Handler.java:99)
                        at android.os.Looper.loop(Looper.java:137)
                        at android.app.ActivityThread.main(ActivityThread.java:4745)
                        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:786)
                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
                        at dalvik.system.NativeStart.main(Native Method)
                 Caused by: java.lang.RuntimeException: You must call Parse.initialize(context, oauthKey, oauthSecret) before using the Parse library.
                        at com.parse.ParseUser.checkApplicationContext(ParseUser.java:1104)
                        at com.parse.ParseUser.getCurrentUser(ParseUser.java:904)
                        at com.parse.ParseUser.getCurrentSessionToken(ParseUser.java:960)
                        at com.parse.ParseObject.saveAsync(ParseObject.java:1421)
                        at com.parse.ParseObject$9.then(ParseObject.java:1410)
                        at com.parse.ParseObject$9.then(ParseObject.java:1406)
                        at com.parse.TaskQueue.enqueue(TaskQueue.java:58)
                        at com.parse.ParseObject.saveAsync(ParseObject.java:1406)
                        at com.parse.ParseObject.saveInBackground(ParseObject.java:1497)
                        at com.parse.ParseObject.saveInBackground(ParseObject.java:1505)
                        at com.parse.liveupdate2.HomepageActivity.onCreate(HomepageActivity.java:21)
                        at android.app.Activity.performCreate(Activity.java:5008)
                        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
                        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
                        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
                        at android.app.ActivityThread.access$600(ActivityThread.java:130)
                        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
                        at android.os.Handler.dispatchMessage(Handler.java:99)
                        at android.os.Looper.loop(Looper.java:137)
                        at android.app.ActivityThread.main(ActivityThread.java:4745)
                        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:786)
                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
                        at dalvik.system.NativeStart.main(Native Method)
            10-22 22:06:54.048  19945-19949/com.parse.liveupdate2 D/dalvikvm﹕ GC_CONCURRENT freed 244K, 3% free 10949K/11271K, paused 13ms+1ms, total 28ms
            10-22 22:06:54.056  19945-19945/com.parse.liveupdate2 D/dalvikvm﹕ WAIT_FOR_CONCURRENT_GC blocked 5ms
            10-22 22:11:54.140  19945-19945/? I/Process﹕ Sending signal. PID: 19945 SIG: 9

请有人帮助我,或者如果有人知道我在哪里可以找到完成的教程,我会非常感激。如果我的代码没有错误,有人可以分享一个链接,我可以下载正确的libs文件进行解析。

1 个答案:

答案 0 :(得分:1)

如果您查看异常的堆栈跟踪,您将看到:

  

引起:java.lang.RuntimeException:你必须调用   在使用之前使用Parse.initialize(context,oauthKey,oauthSecret)   解析库。

所以你必须先这样做。 请参阅本教程:

http://michaelevans.org/blog/2013/08/14/tutorial-building-an-android-to-do-list-app-using-parse/

Soruce:

Getting data from Parse.com using fragments