Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/338.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java ACRA不是';不工作,但我设置正确_Java_Android_Acra - Fatal编程技术网

Java ACRA不是';不工作,但我设置正确

Java ACRA不是';不工作,但我设置正确,java,android,acra,Java,Android,Acra,我在Android Studio中使用Android上的ACRA作为我的应用程序,我非常确信所有设置都是正确的: package prospect.firmname.net.prospect; import android.app.Application; import android.content.Context; import org.acra.*; import org.acra.annotation.*; import org.acra.sender.HttpSender; imp

我在Android Studio中使用Android上的ACRA作为我的应用程序,我非常确信所有设置都是正确的:

package prospect.firmname.net.prospect;
import android.app.Application;
import android.content.Context;

import org.acra.*;
import org.acra.annotation.*;
import org.acra.sender.HttpSender;

import static org.acra.ACRA.log;

@ReportsCrashes(
    formUri = "http://prospect.firmname.net/report.php",
    reportType = HttpSender.Type.JSON,
    httpMethod = HttpSender.Method.POST,
    customReportContent = {
            ReportField.APP_VERSION_CODE,
            ReportField.APP_VERSION_NAME,
            ReportField.ANDROID_VERSION,
            ReportField.PACKAGE_NAME,
            ReportField.REPORT_ID,
            ReportField.BUILD,
            ReportField.STACK_TRACE
    },
    mode = ReportingInteractionMode.TOAST
)
public class ProspectApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        log.e("ACRA BOOTING","OK");
        ACRA.init(this);
    }
    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        ACRA.init(this);
    }
  }
我添加了
log.e(“ACRA引导”,“OK”),它出现在调试中,出于绝望,我加入了两个
@覆盖
,但最初它是:

最主要的是这样的

<application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:name="ProspectApplication"
        android:theme="@style/AppTheme">            
           ~~~~
    </application>
apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "25.0.0"
    defaultConfig {
        applicationId "prospect.firmname.net.prospect"
        minSdkVersion 14
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:24.2.1'
    compile 'com.googlecode.json-simple:json-simple:1.1'
    compile 'ch.acra:acra:4.9.2'
    testCompile 'junit:junit:4.12'
}

android {
    useLibrary 'org.apache.http.legacy'
}
当我访问url
http://prospect.firmname.net/report.php
手动(触摸网站)它会记录访问,因为我使用了此代码(我添加了一个错误日志以100%确保它工作正常),所以它会记录访问,当我手动操作时,它不会记录访问,如果应用程序崩溃:

report.php 
<?php
    // Outputs all POST parameters to a text file. The file name is the date_time of the report reception
    error_log("_REQUEST called " . print_r($_REQUEST,true),0);
    $fileName = 'acra/'.date('Y-m-d_H-i-s').'.txt';
    $file = fopen($fileName,'w') or die('Could not create report file: ' . $fileName);
    foreach($_POST as $key => $value) {
    $reportLine = $key." = ".$value."\n";
        fwrite($file, $reportLine) or die ('Could not write to report file ' . $reportLine);
    }
    fclose($file);
?>
report.php

有人能解释为什么什么都没发生吗?

首先,在名称之前需要一个
android:name=“.ProspectApplication”

第二,你有这一行:

 mode = ReportingInteractionMode.TOAST
但是你在祝酒词中没有文本显示。您需要添加resToastId:

resToastText=R.string.errorMessage

或者在AndroidManifest.xml中的Toast中没有显示任何内容,在自定义应用程序类的名称中,您应该在类名前添加一个点,如以下所示
android:name=“.ProspectApplication”
,我相信您添加了internet权限谢谢:我将其更改为
,这没有帮助,(这就是为什么
log.e
在那里,并且一直在运行)是的,我有
但是你在
ACRA.init(this)
行之前调用
log.e(“ACRA BOOTING”,“OK”);
,你不能在初始化库之前发送错误…
log.e(“ACRA BOOTING”,“OK”)
不是错误,它只是写入管道,供调试器使用-我使用
抛出新RuntimeException(“ACRA处于活动状态!”);
在init之前触发ActivityMainCall中的ACRA
ACRA.DEV_LOGGING=true
并在日志中过滤带有
ACRA
标记的任何消息。谢谢,但我已经对“.”进行了评论TOAST(或没有)与这些有什么关系?如果你愿意,可以忽略这一行。这不会使它起作用TOAST是我在他的代码中看到的一个bug,他显示了一个没有内容的TOAST。