Home Php C# Sql C C++ Javascript Python Java Go Android Git Linux Asp.net Django .net Node.js Ios Xcode Cocoa Iphone Mysql Tomcat Mongodb Bash Objective-c Scala Visual-studio Apache Elasticsearch Jar Eclipse Jquery Ruby-on-rails Ruby Rubygems Android-studio Spring Lua Sqlite Emacs Ubuntu Perl Docker Swift Amazon-web-services Svn Html Ajax Xml Java-ee Maven Intellij-idea Rvm Macos Unix Css Ipad Postgresql Css3 Json Windows-server Vue.js Typescript Oracle Hibernate Internet-explorer Github Tensorflow Laravel Symfony Redis Html5 Google-app-engine Nginx Firefox Sqlalchemy Lucene Erlang Flask Vim Solr Webview Facebook Zend-framework Virtualenv Nosql Ide Twitter Safari Flutter Bundle Phonegap Centos Sphinx Actionscript Tornado Register | Login | Edit Tags | New Questions | 繁体 | 简体


10 questions online user: 2

0
votes
answers
34 views
+10

無法合併dex Android studio 3.0

1

我的項目存在一些問題。在Android的工作室2.3.3它工作正常,但當我更新到3.0我有問題,以marge DEX。無法合併dex Android studio 3.0

我清理並重建項目。

什麼是錯的:

執行失敗的任務 ':應用程序:transformDexArchiveWithExternalLibsDexMergerForDebug'。 com.android.builder.dexing.DexArchiveMergerException:無法合併DEX

堆棧跟蹤:

org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'. 
at  org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeA ctions(ExecuteActionsTaskExecuter.java:100) 
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute( ExecuteActionsTaskExecuter.java:70) 
at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(Sk ipUpToDateTaskExecuter.java:63) 
at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecut er.execute(ResolveTaskOutputCachingStateExecuter.java:54) 
at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(Vali datingTaskExecuter.java:58) 
at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.ex ecute(SkipEmptySourceFilesTaskExecuter.java:88) 
at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:52) 
at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execu te(SkipTaskWithNoActionsExecuter.java:52) 
at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(Skip OnlyIfTaskExecuter.java:54) 
at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execu te(ExecuteAtMostOnceTaskExecuter.java:43) 
at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute( CatchExceptionTaskExecuter.java:34) 
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWork er$1.run(DefaultTaskGraphExecuter.java:248) 
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOpe rationWorker.execute(DefaultBuildOperationExecutor.java:336) 
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOpe rationWorker.execute(DefaultBuildOperationExecutor.java:328) 
at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultB uildOperationExecutor.java:197) 
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuild OperationExecutor.java:107) 
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWork er.execute(DefaultTaskGraphExecuter.java:241) 
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWork er.execute(DefaultTaskGraphExecuter.java:230) 
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.p rocessTask(DefaultTaskPlanExecutor.java:124) 
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.access$200(DefaultTaskPlanExecutor.java:80) 
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1 .execute(DefaultTaskPlanExecutor.java:105) 
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1 .execute(DefaultTaskPlanExecutor.java:99) 
at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute(DefaultTask ExecutionPlan.java:625) 
at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(Def aultTaskExecutionPlan.java:580) 
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.r un(DefaultTaskPlanExecutor.java:99) 
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExec ute(ExecutorPolicy.java:63) 
at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImp l.java:46) 
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run( ThreadFactoryImpl.java:55) 
Caused by: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex 
at com.android.builder.dexing.DxDexArchiveMerger.mergeMultidex(DxDexArchiveMer ger.java:266) 
at com.android.builder.dexing.DxDexArchiveMerger.mergeDexArchives(DxDexArchive Merger.java:133) 
at com.android.build.gradle.internal.transforms.DexMergerTransformCallable.cal l(DexMergerTransformCallable.java:97) 
at com.android.build.gradle.internal.transforms.ExternalLibsMergerTransform.tr ansform(ExternalLibsMergerTransform.kt:121) 
at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTa sk.java:222) 
at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTa sk.java:218) 
at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:102) 
at com.android.build.gradle.internal.pipeline.TransformTask.transform(Transfor mTask.java:213) 
at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73) 
at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$Incre mentalTaskAction.doExecute(DefaultTaskClassInfoStore.java:173) 
at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$Stand ardTaskAction.execute(DefaultTaskClassInfoStore.java:134) 
at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$Stand ardTaskAction.execute(DefaultTaskClassInfoStore.java:121) 
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.run(Ex ecuteActionsTaskExecuter.java:122) 
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOpe rationWorker.execute(DefaultBuildOperationExecutor.java:336) 
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOpe rationWorker.execute(DefaultBuildOperationExecutor.java:328) 
at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultB uildOperationExecutor.java:197) 
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuild OperationExecutor.java:107) 
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeA ction(ExecuteActionsTaskExecuter.java:111) 
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeA ctions(ExecuteActionsTaskExecuter.java:92) 
... 27 more 
Caused by: com.android.builder.dexing.DexArchiveMergerException: Unable  to merge dex 
at com.android.builder.dexing.DexArchiveMergerCallable.call(DexArchiveMergerCa llable.java:72) 
at com.android.builder.dexing.DexArchiveMergerCallable.call(DexArchiveMergerCa llable.java:36) 
... 46 more 
Caused by: com.android.dex.DexException: Multiple dex files define  Landroid/support/v4/view/accessibility/AccessibilityRecordCompatIcsMr1; 
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:661) 
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:616) 
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:598) 
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171) 
at com.android.dx.merge.DexMerger.merge(DexMerger.java:198) 
at com.android.builder.dexing.DexArchiveMergerCallable.call(DexArchiveMergerCa llable.java:61) 
... 47 more 

的build.gradle

apply plugin: 'com.android.application' 

android { 
compileSdkVersion 21 
buildToolsVersion '26.0.2' 

defaultConfig { 
    applicationId "...." 
    minSdkVersion 21 
    targetSdkVersion 21 
    versionCode 2 
    multiDexEnabled true 
    versionName "1.01" 
} 
buildTypes { 
    release { 
     minifyEnabled false 
     proguardFiles getDefaultProguardFile('proguard-android.txt'),  'proguard-rules.pro' 
    } 
} 
} 
repositories { 
mavenCentral() 

maven { url 'http://maven.livotovlabs.pro/content/groups/public' } 
} 
dependencies { 
compile fileTree(dir: 'libs', include: ['*.jar']) 
compile 'com.android.support:appcompat-v7:21.0.3' 
compile 'com.android.support:cardview-v7:21.0.3' 
compile 'com.android.support:multidex:1.0.1' //1.0.1 
compile 'com.google.android.gms:play-services:6.5.87' //6.5.87 
compile fileTree(dir: 'libs', include: 'Parse-*.jar') 
compile 'com.parse.bolts:bolts-tasks:1.4.0' 
compile 'com.parse.bolts:bolts-applinks:1.4.0' 
compile 'com.jakewharton:butterknife:8.8.0' 
compile 'it.neokree:MaterialNavigationDrawer:1.3.3' 
compile 'com.github.navasmdc:MaterialDesign:[email protected]' 
compile 'com.nineoldandroids:library:2.4.0' 
compile 'com.github.bluejamesbond:textjustify-android:2.1.0' 
compile 'it.neokree:MaterialTabs:0.11' 
compile('com.googlecode.json-simple:json-simple:1.1.1') { 
    exclude module: 'junit' 
} 
compile ('eu.livotov.labs.android:CAMView:[email protected]') {transitive=true} 
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1' 
} 

當我刪除multiDexEnable:

org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'. 
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:100) 
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:70) 
at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:63) 
at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54) 
at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58) 
at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:88) 
at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:52) 
at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52) 
at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54) 
at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43) 
at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34) 
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.run(DefaultTaskGraphExecuter.java:248) 
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336) 
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328) 
at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:197) 
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:107) 
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:241) 
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:230) 
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.processTask(DefaultTaskPlanExecutor.java:124) 
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.access$200(DefaultTaskPlanExecutor.java:80) 
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:105) 
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:99) 
at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute(DefaultTaskExecutionPlan.java:625) 
at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:580) 
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:99) 
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63) 
at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46) 
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55) 
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex 
at com.android.builder.dexing.DxDexArchiveMerger.mergeMonoDex(DxDexArchiveMerger.java:177) 
at com.android.builder.dexing.DxDexArchiveMerger.mergeDexArchives(DxDexArchiveMerger.java:118) 
at com.android.build.gradle.internal.transforms.DexMergerTransformCallable.call(DexMergerTransformCallable.java:97) 
at com.android.build.gradle.internal.transforms.ExternalLibsMergerTransform.transform(ExternalLibsMergerTransform.kt:121) 
at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:222) 
at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:218) 
at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:102) 
at com.android.build.gradle.internal.pipeline.TransformTask.transform(TransformTask.java:213) 
at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73) 
at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$IncrementalTaskAction.doExecute(DefaultTaskClassInfoStore.java:173) 
at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:134) 
at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:121) 
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.run(ExecuteActionsTaskExecuter.java:122) 
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336) 
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328) 
at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:197) 
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:107) 
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:111) 
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:92) 
... 27 more 
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex 
at com.android.builder.dexing.DxDexArchiveMerger.lambda$mergeMonoDex$0(DxDexArchiveMerger.java:171) 
Caused by: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex 
Caused by: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex 
at com.android.builder.dexing.DexArchiveMergerCallable.call(DexArchiveMergerCallable.java:72) 
at com.android.builder.dexing.DexArchiveMergerCallable.call(DexArchiveMergerCallable.java:36) 
Caused by: com.android.dex.DexException: Multiple dex files define Landroid/support/v4/view/accessibility/AccessibilityRecordCompatIcsMr1; 
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:661) 
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:616) 
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:598) 
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171) 
at com.android.dx.merge.DexMerger.merge(DexMerger.java:198) 
at com.android.builder.dexing.DexArchiveMergerCallable.call(DexArchiveMergerCa llable.java:61) 
... 1 more 
+0

你已經嘗試沒有multidex? –

+0

是的。我試圖在Android Studio 2.3.3中運行應用程序,並且它可以工作。所以這是隻有當我使用3.0版本 – qubuss

+1

只是一個猜測,但我認爲它涉及到重複的依賴關係的問題。因爲這個問題發生很多,因爲每個人都在更新到Android Studio 3.0。例如[這裏](https://stackoverflow.com/questions/47086275/trying-to-build-android-project-with-glide-package-throws-unable-to-merge-dex)。我的猜測是,如果關閉multidex庫,您可能會看到更好的堆棧跟蹤,顯示重複錯誤。 –

沙发
0
2

這與dupl有關你項目中的依賴項。發生了重複的依賴關係,這是因爲某些庫隱式依賴於相同的庫,但具有不同的版本。在Android Studio中使用的Gradle 4.1不支持庫複製。

您可以從依賴樹用下面的命令在Linux中的終端檢查(應用是你的模塊名):

./gradlew app:dependencies 

,或者如果你正在使用Windows嘗試這種在命令提示符下:

gradlew.bat app:dependencies 

然後,在找到它之後,您需要將其從庫中排除並僅使用其中一個。事情是這樣的:

compile('com.library.name:version') { 
    // this is a case for duplicate support library version. 
    exclude group: 'com.android.support' 
    exclude module: 'appcompat-v7' 
} 

需要指出的是,你最好使用的 compileSdkVersionbuildToolsVersiontargetSdkVersionSupport Library相同的版本。

板凳
0
0

在我的情況下,它與awsgateway sdk給出的gson和gson已經存在的依賴性問題有關。

gradle -q app:dependencies 

沒有顯示任何依賴關係的差異,但gradle構建堆棧跟蹤顯示它與gson相關。 引起:com.android.dex.DexException:多個dex文件定義Lcom/google/gson/FieldNamingStrategy;

繼此issue之後,我在config下添加了build.gradle,但沒有解決問題。

compile("com.google.code.gson:gson:2.3") { 
    exclude module: 'gson:2.2.4' 
} 

我不得不手動去除(SDK生成期間由給定apigateway GSON-2.2.4.jar)罐子存在於應用程序/庫文件夾。

地板
0
-2

我面臨同樣的問題,然後我發現從Here (Github)

解決方案在默認配置添加

multiDexEnabled true 

爲例

defaultConfig { 
    applicationId "my application id " 
    minSdkVersion 14 
    targetSdkVersion 27 
    versionCode 1 
    versionName '1.0' 
    multiDexEnabled true 
} 

然後添加

implementation('commons-validator:commons-validator:1.4.1') { 
    exclude group: 'commons-collections', module: 'commons-collections' 
} 

在您的依賴項中。 這對我來說是我的工作,我希望它也能解決你的問題:)

+0

爲什麼你認爲OP的問題和你的問題(或者LeakCanary列表的問題)是「一樣的」?爲什麼你建議在OPs默認配置中添加'multiDexEnabled true',當它已經在那裏?最後,爲什麼你建議OP添加一個庫而沒有給出理由呢? – kalabalik

+0

我建議,因爲我遵循的答案,但它不適合我。我想其他人可能會面臨同樣的問題,這就是爲什麼我剪切我如何解決這個問題。 –

0
votes
answers
46 views
+10

對齊屏幕底部的多個視圖

0

我是Android的新手,我想在屏幕的底部創建一個具有Buttons的設置(行)的活動。對於我的示例,我編寫了2套代碼)按鈕:對齊屏幕底部的多個視圖

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_gravity="bottom" 
    android:layout_alignParentBottom="true"> 

    <Button 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="1" /> 

    <Button 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="2" /> 

    <Button 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="3" /> 

    <Button 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="4" /> 

    <Button 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="5" /> 
</LinearLayout> 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_gravity="bottom" 
    android:layout_alignParentBottom="true"> 

    <Button 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="6" /> 

    <Button 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="7" /> 

    <Button 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="8" /> 

    <Button 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="9" /> 

    <Button 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="10" /> 
</LinearLayout> 
</RelativeLayout> 

enter image description here

我想按鈕6-10穿上(以上)的按鈕1-5(如堆棧)。

我該怎麼做?

感謝

+0

它是如何現在看?重疊? – Xenolion

+0

是按鈕6-10重疊1-5。按鈕1-5沒有顯示 – Arian

+0

我已經回答你的問題,如果這是你想要的! – Xenolion

沙发
0
1

您使用的是RelativeLayout有兩個LinearLayout秒。

你應該給雙方的LinearLayoutid秒和之後,你將定位等LinearLayout你想在上面給它的atrribute

android:layout_above="@id/the_id_of_the_one_you_want_to_be_below" 
板凳
0
1

嘗試來包裝你的兩個的LinearLayout在父linearLayout。 該父級佈局需要與底部對齊。

事情是這樣的:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_gravity="bottom" 
    android:layout_alignParentBottom="true" 
    android:orientation="vertical"> 

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    > 

     <Button 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="1" /> 

     <Button 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="2" /> 

     <Button 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="3" /> 

     <Button 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="4" /> 

     <Button 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="5" /> 
    </LinearLayout> 

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    > 

     <Button 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="6" /> 

     <Button 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="7" /> 

     <Button 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="8" /> 

     <Button 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="9" /> 

     <Button 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="10" /> 
    </LinearLayout> 
</LinearLayout> 
</RelativeLayout> 
0
votes
answers
45 views
+10

ic_launcher_foreground.xml無法找到幾個屬性,而gradle構建

0

我剛剛從android studio 2.1升級到一個穩定的3.0,我在製作新項目時出現錯誤(我也是新的android studio:D) 這裏有錯誤我得到ic_launcher_foreground.xml無法找到幾個屬性,而gradle構建

  1. 錯誤:(7)否在包「機器人」
  2. 發現錯誤的屬性「fillType」資源標識符:(28)未找到屬性資源標識符「fillType」在包'android'
  3. 錯誤:(13)未找到包'android'中屬性'endX'的資源標識符
  4. 錯誤:(13)否在包「機器人」找到的屬性「STARTX」資源標識符
  5. 錯誤:(19)未發現屬性在包「偏移」「機器人」

資源標識符和幾個例外的

  1. 錯誤:java.util.concurrent.ExecutionException:com.android.ide.common.process.ProcessException:錯誤而執行程序E: AndroidSDK 構建工具 27.0.1 帶參數的aapt.exe {package -f --no-crunch -IE: AndroidSDK platforms android-23 android.jar -M ? C: Users ShaD iLiX AndroidStudioProjects Test1 app build intermediates manifests full debug AndroidManifest.xml -SC: Users ShaD iLiX AndroidStudioProjects Test1 app build intermediates res merged debug -m -J ? C: Users ShaD iLiX AndroidStudioProjects Test1 app build generated source r debug -FC: Users ShaD iLiX AndroidStudioProjects Test1 app build intermediates res debug resources- debug.ap_ --custom-package com.example.shadilix.test1 -0 apk --output-text-symbols ? C: Users ShaD iLiX AndroidStudioProjects Test1 app build intermediates symbols debug - -no-version-vectors}
  2. 錯誤:com.android.ide.common.process.ProcessException:使用參數執行進程E: AndroidSDK build-tools 27.0.1 aapt.exe時出錯{package -f --no-crunch -IE: AndroidSDK platforms android-23 android.jar -M ? C: Users ShaD iLiX AndroidStudioProjects Test1 app build intermediates manifests full debug AndroidManifest .xml -SC: Users Sha D iLiX AndroidStudioProjects Test1 app build intermediates res merged debug -m -J ? C: Users ShaD iLiX AndroidStudioProjects Test1 app build generated source r debug -FC : Users ShaD iLiX AndroidStudioProjects Test1 app build intermediates res debug resources-debug.ap_ --custom-package com.example.shadilix.test1 -0 apk --output-text-symbols ? C: Users ShaD iLiX AndroidStudioProjects Test1 app build intermediates symbols debug --no-version-vectors}
  3. Error:org.gradle.process.internal.ExecException:Process'command'E : AndroidSDK build-tools 27.0.1 aapt.exe''以非零退出值結束1
    1. 錯誤:執行任務':app:processDebugResources'失敗。

      Failed to execute aapt

這裏是ic_Launcher_foreground.xml代碼:

<vector xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:aapt="http://schemas.android.com/aapt" 
android:width="108dp" 
android:height="108dp" 
android:viewportHeight="108" 
android:viewportWidth="108"> 
<path 
    android:fillType="evenOdd" 
    android:pathData="M32,64C32,64 38.39,52.99 44.13,50.95C51.37,48.37 70.14,49.57 70.14,49.57L108.26,87.69L108,109.01L75.97,107.97L32,64Z" 
    android:strokeColor="#00000000" 
    android:strokeWidth="1"> 
    <aapt:attr name="android:fillColor"> 
     <gradient 
      android:endX="78.5885" 
      android:endY="90.9159" 
      android:startX="48.7653" 
      android:startY="61.0927" 
      android:type="linear"> 
      <item 
       android:color="#44000000" 
       android:offset="0.0" /> 
      <item 
       android:color="#00000000" 
       android:offset="1.0" /> 
     </gradient> 
    </aapt:attr> 
</path> 
<path 
    android:fillColor="#FFFFFF" 
    android:fillType="nonZero" 
    android:pathData="M66.94,46.02L66.94,46.02C72.44,50.07 76,56.61 76,64L32,64C32,56.61 35.56,50.11 40.98,46.06L36.18,41.19C35.45,40.45 35.45,39.3 36.18,38.56C36.91,37.81 38.05,37.81 38.78,38.56L44.25,44.05C47.18,42.57 50.48,41.71 54,41.71C57.48,41.71 60.78,42.57 63.68,44.05L69.11,38.56C69.84,37.81 70.98,37.81 71.71,38.56C72.44,39.3 72.44,40.45 71.71,41.19L66.94,46.02ZM62.94,56.92C64.08,56.92 65,56.01 65,54.88C65,53.76 64.08,52.85 62.94,52.85C61.8,52.85 60.88,53.76 60.88,54.88C60.88,56.01 61.8,56.92 62.94,56.92ZM45.06,56.92C46.2,56.92 47.13,56.01 47.13,54.88C47.13,53.76 46.2,52.85 45.06,52.85C43.92,52.85 43,53.76 43,54.88C43,56.01 43.92,56.92 45.06,56.92Z" 
    android:strokeColor="#00000000" 
    android:strokeWidth="1" /> 

這裏是我的版本。gradle這個文件

apply plugin: 'com.android.application' 

android { 
    compileSdkVersion 23 
    buildToolsVersion "27.0.1" 

    defaultConfig { 
     applicationId "com.example.shadilix.test1" 
     minSdkVersion 23 
     targetSdkVersion 23 
     versionCode 1 
     versionName "1.0" 
     testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 
    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 
} 

dependencies { 
    implementation fileTree(dir: 'libs', include: ['*.jar']) 
    implementation 'com.android.support:appcompat-v7:23.+' 
    implementation 'com.android.support.constraint:constraint-layout:1.0.2' 
    testImplementation 'junit:junit:4.12' 
    androidTestImplementation 'com.android.support.test:runner:1.0.1' 
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' 
} 
沙发
0
0

乾淨的構建和/或重新啓動,並可能會失效解決問題

+0

沒有工作 –

0
votes
answers
53 views
+10

Android工作室註冊按鈕沒有響應排球請求

0

我想在android工作室中使用排球庫和PHP頁面製作註冊腳本。 PHP頁面正常工作,它已經過測試。我在像MySQL這樣的WEBSERVER上擁有它,並且連接很好,並且所有內容都經過了測試。今天我試着做一些應用程序,但我想註冊並登錄。你能告訴我爲什麼沒有反應,當我點擊註冊按鈕?我的代碼在哪裏出錯?我真的很感謝每一個幫助。Android工作室註冊按鈕沒有響應排球請求

import android.content.DialogInterface; 
import android.support.v7.app.AlertDialog; 
import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.Button; 
import android.widget.EditText; 
import android.widget.Toolbar; 

import com.android.volley.AuthFailureError; 
import com.android.volley.Request; 
import com.android.volley.Response; 
import com.android.volley.VolleyError; 
import com.android.volley.toolbox.StringRequest; 

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

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

public class Register extends AppCompatActivity { 
    Button reg_bn; 
    EditText Name,Email,UserName,Password,ConPassword; 
    String name,email,username,password,conpass; 
    AlertDialog.Builder builder; 
    String reg_url = "https://prchy.ic.cz/register.php"; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_register); 
     reg_bn = (Button)findViewById(R.id.bn_reg); 
     Name = (EditText)findViewById(R.id.reg_name); 
     Email = (EditText)findViewById(R.id.reg_email); 
     UserName = (EditText)findViewById(R.id.reg_user_name); 
     Password = (EditText)findViewById(R.id.reg_password); 
     ConPassword = (EditText)findViewById(R.id.reg_con_password); 
     builder = new AlertDialog.Builder(Register.this); 
     reg_bn.setOnClickListener(new View.OnClickListener(){ 
      @Override 
      public void onClick(View v) { 
       name = Name.getText().toString(); 
       email = Email.getText().toString(); 
       username = UserName.getText().toString(); 
       password = Password.getText().toString(); 
       conpass = ConPassword.getText().toString(); 
       if(name.equals("")||email.equals("")||username.equals("")||password.equals("")||conpass.equals("")) 
       { 
        builder.setTitle("Něco se pokazilo..."); 
        builder.setMessage("Prosím vyplňte všechny pole."); 
        displayAlert("input_error"); 
       } 
       else { 
        if(!(password.equals(conpass))) 
        { 
         builder.setTitle("Něco se pokazilo..."); 
         builder.setMessage("Vaše hesla se neshodují."); 
         displayAlert("input_error"); 
        } 
        else { 
         StringRequest stringRequest = new StringRequest(Request.Method.POST, reg_url, 
           new Response.Listener<String>() { 
            @Override 
            public void onResponse(String response) { 
             try { 
              JSONArray jsonArray = new JSONArray(response); 
              JSONObject jsonObject = jsonArray.getJSONObject(0); 
              String code = jsonObject.getString("code"); 
              String message = jsonObject.getString("message"); 
              builder.setTitle("Odpově? serveru..."); 
              builder.setMessage(message); 
              displayAlert(code); 
             } catch (JSONException e) { 
              e.printStackTrace(); 
             } 
            } 
           }, new Response.ErrorListener() { 
          @Override 
          public void onErrorResponse(VolleyError error) { 

          } 
         }){ 
          @Override 
          protected Map<String, String> getParams() throws AuthFailureError { 
           Map<String, String> params = new HashMap<String,String>(); 
           params.put("name",name); 
           params.put("email",email); 
           params.put("user_name",username); 
           params.put("password",password); 
           return params; 
          } 
         }; 
         MySingleton.getInstance(Register.this).addToRequestque(stringRequest); 


        } 
        } 
       } 
      }); 

    } 
    public void displayAlert(final String code) 
    { 
    builder.setPositiveButton("OK", new DialogInterface.OnClickListener() { 
     @Override 
     public void onClick(DialogInterface dialogInterface, int i) { 
      if(code.equals("input_error")) 
      { 
       Password.setText(""); 
       ConPassword.setText(""); 
      } 
      else if(code.equals("reg_success")){ 
       finish(); 
      } 
      else if(code.equals("reg_failed")){ 
       Name.setText(""); 
       UserName.setText(""); 
       Password.setText(""); 
       ConPassword.setText(""); 
      } 
     } 
    }); 
    AlertDialog alertDialog = builder.create(); 
    alertDialog.show(); 
    } 
} 

而且在我的XML文件是

<?xml version="1.0" encoding="utf-8"?> 
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@android:color/holo_blue_light" 
    tools:background="@android:color/holo_blue_light" 
    tools:context="com.example.admin.bongfinalapp.Register"> 

    <EditText 
     android:id="@+id/reg_name" 
     android:layout_width="368dp" 
     android:layout_height="42dp" 
     android:ems="10" 
     android:hint="Vaše jméno" 
     android:inputType="textPersonName" 
     app:layout_constraintBottom_toTopOf="@+id/reg_email" 
     app:layout_constraintEnd_toEndOf="parent" 
     app:layout_constraintEnd_toStartOf="@+id/imageView2" 
     app:layout_constraintHorizontal_bias="0.0" 
     app:layout_constraintStart_toEndOf="@+id/imageView2" 
     app:layout_constraintStart_toStartOf="parent" 
     app:layout_constraintTop_toBottomOf="@+id/imageView2" 
     app:layout_constraintVertical_bias="0.333" /> 

    <EditText 
     android:id="@+id/reg_email" 
     android:layout_width="368dp" 
     android:layout_height="wrap_content" 
     android:ems="10" 
     android:hint="E-Mail" 
     android:inputType="textEmailAddress" 
     app:layout_constraintBottom_toTopOf="@+id/reg_user_name" 
     app:layout_constraintEnd_toEndOf="parent" 
     app:layout_constraintHorizontal_bias="0.5" 
     app:layout_constraintStart_toStartOf="parent" 
     app:layout_constraintTop_toBottomOf="@+id/reg_name" /> 

    <EditText 
     android:id="@+id/reg_user_name" 
     android:layout_width="368dp" 
     android:layout_height="wrap_content" 
     android:ems="10" 
     android:hint="P?ihlašovací jméno" 
     android:inputType="textPersonName" 
     app:layout_constraintBottom_toTopOf="@+id/reg_password" 
     app:layout_constraintEnd_toEndOf="parent" 
     app:layout_constraintHorizontal_bias="0.5" 
     app:layout_constraintStart_toStartOf="parent" 
     app:layout_constraintTop_toBottomOf="@+id/reg_email" 
     app:layout_constraintVertical_bias="0.045" /> 

    <EditText 
     android:id="@+id/reg_password" 
     android:layout_width="368dp" 
     android:layout_height="wrap_content" 
     android:ems="10" 
     android:hint="Heslo" 
     android:inputType="textPassword" 
     app:layout_constraintBottom_toTopOf="@+id/reg_con_password" 
     app:layout_constraintEnd_toEndOf="parent" 
     app:layout_constraintHorizontal_bias="0.5" 
     app:layout_constraintStart_toStartOf="parent" 
     app:layout_constraintTop_toBottomOf="@+id/reg_user_name" 
     app:layout_constraintVertical_bias="0.074" /> 

    <Button 
     android:id="@+id/bn_reg" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Registruj" 
     app:layout_constraintBottom_toBottomOf="parent" 
     app:layout_constraintEnd_toEndOf="parent" 
     app:layout_constraintHorizontal_bias="0.5" 
     app:layout_constraintStart_toStartOf="parent" 
     app:layout_constraintTop_toBottomOf="@+id/reg_con_password" /> 

    <ImageView 
     android:id="@+id/imageView2" 
     android:layout_width="wrap_content" 
     android:layout_height="144dp" 
     app:layout_constraintBottom_toTopOf="@+id/reg_name" 
     app:layout_constraintEnd_toEndOf="parent" 
     app:layout_constraintHorizontal_bias="1.0" 
     app:layout_constraintStart_toStartOf="parent" 
     app:layout_constraintTop_toTopOf="parent" 
     app:srcCompat="@drawable/bong" /> 

    <EditText 
     android:id="@+id/reg_con_password" 
     android:layout_width="368dp" 
     android:layout_height="wrap_content" 
     android:ems="10" 
     android:hint="Potvr? heslo" 
     android:inputType="textPersonName" 
     app:layout_constraintBottom_toTopOf="@+id/bn_reg" 
     app:layout_constraintEnd_toEndOf="parent" 
     app:layout_constraintHorizontal_bias="0.5" 
     app:layout_constraintStart_toStartOf="parent" 
     app:layout_constraintTop_toBottomOf="@+id/reg_password" /> 
</android.support.constraint.ConstraintLayout> 
沙发
0
0

顯示MySingelton類。爲onError添加日誌以檢查您是否收到錯誤

0
votes
answers
68 views
+10

網站菜單欄不能使用WebView android,而在手機瀏覽器中正常工作

1

我正在使用WebView和使用WebView android打開網站。該網站的菜單欄在移動瀏覽器中工作正常,但是當我在WebView android中打開URL /網站時,菜單欄不起作用。網站菜單欄不能使用WebView android,而在手機瀏覽器中正常工作

當打開Android中的WebView(菜單欄不響應)

When URL open in android webview

當手機瀏覽器

When opening in mobile browser in

下面打開的是代碼我正在用WebView打開URL:

WebView mWebView = (WebView) findViewById(R.id.webview); 
WebSettings mWebSettings = mWebView.getSettings(); 
mWebSettings.setJavaScriptEnabled(true); 
mWebSettings.setSupportZoom(false); 

mWebView.setWebViewClient(new WebViewClient()); 
mWebView.setWebViewClient(new WebViewClient() { 
public boolean shouldOverrideUrlLoading(WebView view, String url) { 
    view.loadUrl(url); 
    return true; 
} 

public void onPageFinished(WebView view, String url) { 

} 

public void onReceivedError(WebView view, int errorCode, String descripti0on, String failingUrl) { 

} 
}); 

mWebView.loadUrl("https://www.buyvipgift.com"); 

請讓我知道我要去哪裏錯了!非常感謝...

沙发
0
1

我在我的代碼中添加了mWebSettings.setDomStorageEnabled(true)這行,現在工作正常。

setDomStorageEnabled(boolean flag) 

設置是否啓用DOM存儲API。

因爲登錄頁面提供的控件可用於自定義colour,fontdecorative image。當您選擇不同的選項時,該頁面即時更新;此外,您的選擇存儲在localStorage中,這樣,當您離開頁面時,稍後再加載它,您的選擇就會被記住。此外,如果您在另一個選項卡中加載此頁面,然後在着陸頁中更改您的選擇,則會在啓動StorageEvent時看到更新的存儲信息輸出。

0
votes
answers
62 views
+10

如何在沒有GUI的情況下通過BroadcastReceiver使用Android服務接收短信

0

我一直在研究一個應用程序,該應用程序用於接收短信並使用廣播接收器來顯示一個Toast,並且我有一個沒有目的的活動,構建apk並在我的手機上運行,??應用程序在收到短信時沒有響應(沒有Toast顯示),儘管剩餘的代碼與以前相同。任何人都可以幫助我,我很困難,不能幫助自己閱讀數百個答案。我研究了我應該創建一個服務,但仍然沒有吐司出現。下面是我的代碼。即使不希望自動殺死活動,我的應用程序中也不能有任何GUI。如何在沒有GUI的情況下通過BroadcastReceiver使用Android服務接收短信

BroadcastReceiver.java

package com.test.testservice; 

import android.content.BroadcastReceiver; 
import android.content.Context; 
import android.content.Intent; 
import android.os.Bundle; 
import android.telephony.SmsMessage; 
import android.widget.Toast; 



public class SmsReceiver extends BroadcastReceiver { 

    public static final String SMS_BUNDLE = "pdus"; 
    private static final String LOG = "SmsBroadcastReceiver"; 

    @Override 
    public void onReceive(Context context, Intent intent) { 

     Bundle intentExtras = intent.getExtras(); 
     if (intentExtras != null) { 
      Object[] sms = (Object[]) intentExtras.get(SMS_BUNDLE); 


      if (sms != null) 
      { 
       String smsMessageStr = ""; 

       for (int i = 0; i < sms.length; ++i) 
       { 
        SmsMessage smsMessage = SmsMessage.createFromPdu((byte[]) sms[i]); 

        String smsBody = smsMessage.getMessageBody().toString(); 
        String address = smsMessage.getOriginatingAddress(); 

        smsMessageStr += "SMS From: " + address + "
"; 
        smsMessageStr += smsBody + "
"; 
       } 
       Toast.makeText(context, smsMessageStr, Toast.LENGTH_LONG).show(); 
       //MyService objService=new MyService(); 
       //objService.startService(intent); 
       //objService.stopService(intent); 


       Intent myIntent = new Intent(context, MyService.class); 
       //myIntent.putExtra("Sender", Sender); 
       //myIntent.putExtra("Fullsms", Fullsms); 
       context.startService(myIntent); 


      } 
     } 
    } 
} 

MyService.java

package com.test.testservice; 

import android.app.Service; 
import android.content.ComponentName; 
import android.content.Intent; 
import android.os.IBinder; 
import android.support.annotation.Nullable; 
import android.util.Log; 
import android.widget.Toast; 

public class MyService extends Service { 
    private static final String LOG = "MyService"; 
    @Override 
    public boolean stopService(Intent name) { 
     if (super.stopService(name)) 
     { 
      Toast.makeText(this,"HELLO stopService",Toast.LENGTH_LONG).show(); 
      Log.i(LOG, "stopService"); 
      return true; 
     } 
     else return false; 
    } 

    @Override 
    public ComponentName startService(Intent service) { 
     return super.startService(service); 
    } 

    @Nullable 
    @Override 
    public IBinder onBind(Intent intent) { 
     return null; 
    } 

    @Override 
    public void onCreate() { 
     super.onCreate(); 
     Toast.makeText(this,"HELLO onCreate",Toast.LENGTH_LONG).show(); 
    } 

    @Override 
    public void onStart(Intent intent, int startId) { 
     super.onStart(intent, startId); 
     Toast.makeText(this,"HELLO onStart",Toast.LENGTH_LONG).show(); 
    } 
} 

的AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android" 

    package="com.test.testservice"> 

    <application 
     android:allowBackup="true" 
     android:icon="@mipmap/ic_launcher" 
     android:label="@string/app_name" 
     android:roundIcon="@mipmap/ic_launcher_round" 
     android:supportsRtl="true" 
     android:theme="@style/AppTheme"> 


     <receiver android:name=".SmsReceiver" android:enabled="true" android:exported="true"> 
      <intent-filter> 
       <action android:name="android.provider.Telephony.SMS_RECEIVED" /> 
       <action android:name="android.intent.action.BOOT_COMPLETED"/> 
       <action android:name="android.intent.action.REBOOT"/> 
      </intent-filter> 
     </receiver> 

    </application> 

    <service android:name="com.test.testservice.service.MyService"/> 

    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> 
    <uses-permission android:name="android.permission.WRITE_SMS" /> 
    <uses-permission android:name="android.permission.READ_SMS" /> 
    <uses-permission android:name="android.permission.RECEIVE_SMS" /> 
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
    <uses-permission android:name="android.permission.INTERNET" /> 
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> 
</manifest> 
+0

我可以在沒有任何GUI的情況下創建服務並將其安裝到手機上嗎?然後創建一個單獨的應用程序來運行該服務,一旦服務運行我卸載第二個應用程序? –

沙发
0
0

UNL如果您正在創建自己的手機,或者您自己的自定義ROM,則需要進行該活動。當您的應用第一次安裝時,您的BroadcastReceiver將不起作用。只有當用戶啓動您的活動(或其他使用明確的Intent來啓動您的某個組件)時,它纔會開始工作。

我不能有任何GUI在我的應用程序

那麼你的應用程序不會在Android 3.1+設備,從而彌補了廣大大多數Android設備生態系統的正常工作。

0
votes
answers
43 views
+10

Android計算器 - 加號按鈕

0

我的計算器上有一個加號按鈕。第一種說法是在沒有輸入時(計算字符串變量保存來自用戶的所有輸入)添加「+」符號。第二個陳述是防止用戶通過添加「」在一行中輸入2個「+」符號。Android計算器 - 加號按鈕

它不斷給我一個錯誤:java.lang.StringIndexOutOfBoundsException: length=0; index=0

btnMinus.setOnClickListener(new View.OnClickListener() { 
    @Override 

    public void onClick(View view) { 
     calculation = tvCalculation.getText().toString(); 

     Character lastChar = calculation.charAt(calculation.length()); 

     //App negeert deze statements 
     if(calculation.length() >= 0) { 
       tvCalculation.setText(calculation + "-"); 
     } else if (lastChar.toString().equals("+")) { 
       tvCalculation.setText(calculation + ""); 
     } 
    } 
}); 

有人告訴我,那是因爲在toString()線4

+0

當字符串爲空(長度:0)時,錯誤是錯誤的。如果您嘗試查找空字符串的最後一個字符,您認爲會發生什麼?你也應該考慮使用char而不是Character來比較它與char文字,它們使用單??引號而不是雙引號。 – vandale

+0

如果我使用char,出於某種原因我不能使用==或.equals(),所以我必須保留Character。當字符串爲空時,語句1將處理它。 –

+0

這看起來很奇怪。 'lastChar =='+''也應該有效。 – vandale

沙发
0
0

,如果你打算讀「計算」字符串的最後一個字符,那麼你需要做的;

Character lastChar = calculation.charAt(calculation.length()-1); 

注意calculate.Length(-1)後的-1。

+0

本來我有-1,有同樣的錯誤。 –

0
votes
answers
36 views
+10

使用響應和JSON的Android Studio數據庫連接

0

我試圖用我的遠程數據庫使用PHP文件和JSONObject進行連接,但代碼正在滑動Response.Listener,我不知道爲什麼... 這裏我主要包含Response.Listener:使用響應和JSON的Android Studio數據庫連接

Response.Listener<String> responseListener = new Response.Listener<String>() { 
       @Override 
       public void onResponse(String response) { 
        try { 

         Toast.makeText(Register.this, "Test00", Toast.LENGTH_SHORT).show(); 

         JSONObject jsonObject = new JSONObject(response); 
         boolean success = jsonObject.getBoolean("success"); 

         if(success) 
         { 
          Toast.makeText(Register.this, "Test01", Toast.LENGTH_SHORT).show(); 
         } 
         else 
         { 
          Toast.makeText(Register.this, "Error", Toast.LENGTH_SHORT).show(); 
         } 

        } catch (JSONException e) { 
         e.printStackTrace(); 
        } 
       } 
      }; 

      RegisterRequest registerRequest = new RegisterRequest(email, username, usernick, password, birthdate, gender, responseListener); 
      RequestQueue queue = Volley.newRequestQueue(Register.this); 
      queue.add(registerRequest); 

,在這裏我RegisterRequest類:

public class RegisterRequest extends StringRequest { 

private static final String REGISTER_REQUEST_URL = "kameo.com.br/control/ayzac_control_signin_mobile.php"; 
private Map<String, String> params; 

public RegisterRequest(String email, String name, String nickname, String password, String date, String gender, Response.Listener<String> listener) 
{ 
    super(Method.POST, REGISTER_REQUEST_URL, listener, null); 
    params = new HashMap<>(); 
    params.put("userEmail", email); 
    params.put("userName", name); 
    params.put("userNickname", nickname); 
    params.put("userPassword", password); 
    params.put("userBirth", date); 
    params.put("userGender", gender); 
} 

@Override 
public Map<String, String> getParams() { 
    return params; 
} 
} 
+0

你有沒有試着用你的API網址前加上HTTP或HTTPS – Dilip

+0

檢查您的請求params –

+0

它的工作,只需在URL之前「http://」...非常感謝! –

沙发
0
0

我測試您的網址,這裏面就有一個錯誤:kameo.com.br/control/ayzac_control_signin_mobile .php

你也需要從服務器響應讀取錯誤,嘗試創建一個錯誤監聽:

Response.Listener<String> errorListener = new Response.ErrorListener() { 
      @Override 
      public void onErrorResponse(VolleyError error) { 
       Log.e(TAG, "Error : " + error.getMessage()); 
      } 
     }; 

並進入你的RegisterRequest構造

+0

您在Log中使用的標籤具有私密訪問權限... –

+0

用任何字符串bro替換TAG – diegoveloper

0
votes
answers
53 views
+10

在一個片段,如果我按後退按鈕進入SettingsActivity.class

0

我有一個activity_settings.xml文件就像該文件下面我有3層文本的意見,如果我點擊的話,會帶我去一個片段在一個片段,如果我按後退按鈕進入SettingsActivity.class

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.example.crowderia.chat.SettingsActivity" 
    android:background="@color/black"> 

    <TextView 
     android:id="@+id/tv_added_me" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Added Me" /> 

    <TextView 
     android:id="@+id/tv_add_friends" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Add Friends" /> 

    <TextView 
     android:id="@+id/tv_my_friends" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="My Friends" /> 

    <FrameLayout 
     android:id="@+id/settings_fragment" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 
    </FrameLayout> 

</RelativeLayout> 

我SettingsActivity.class像下面

每個文本視圖onclick事件

tv_added_me.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       setFragment(new AddedMeFragment()); 
      } 
     }); 

組片段方法

public void setFragment(Fragment f) { 

     FragmentManager fragmentManager = getSupportFragmentManager(); 
     FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); 
     fragmentTransaction.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out); 
     fragmentTransaction.replace(R.id.settings_fragment, f); 
     fragmentTransaction.commit(); 
    } 

如果我點擊每個文本視圖它會帶我去每個片段,但之後我點擊回到它不會去設置活動我怎樣才能使這項工作

請幫我進出口新的這東西

沙发
0
1

您應該從點擊返回按鈕中刪除FragmentManager的所有片段。

FragmentManager fm = getSupportFragmentManager(); 
for (Fragment f : fm.getFragments()) { 
    fm.beginTransaction().remove(f).commit(); 
} 
+0

我應該在哪裏放這個,你可以在@override onBackPressed()方法中解釋一下 – HemalHerath

+1

。 –

+0

如果您願意在設備後退按鈕上執行操作,則應寫入'onBackPressed()'。如果您使用帶後退箭頭的工具欄,則應該在後退箭頭的點擊中寫入。 – Wizard

0
votes
answers
63 views
+10

刷新Android Studio中的遠程Git分支

2

遠程倉庫中有一個新的分支,但它並未出現在android studio的git分支中。如何刷新該列表以顯示新分支?刷新Android Studio中的遠程Git分支

我試過git branch -r 但新分支沒有顯示在列表中。

沙发
0
6

在你的Android Studio菜單欄中,單擊VCS > Git > Fetch

板凳
0
2

嘗試使用git fetch或使用git fetch --all

地板
0
2

您可以嘗試使用VCS (from menu)然後點擊Git,然後Fetch。 或者,您可以使用git fetch --all