我正在尝试创建一个应用,用户可以在其中浏览一系列“菜单”以访问内容。
我创建了打开应用程序时出现的菜单
MainMenuActivity.java:
public class MainMenuActivity extends AppCompatActivity {
ListView listView;
ArrayAdapter<String> main_adapter;
String[] main_menu = {
"1 INTRO",
"2 HELP",
"3 AROUND THE WORLD"
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_menu_layout);
listView = (ListView) findViewById(R.id.main_list);
main_adapter = new ArrayAdapter<>(this, R.layout.main_list_custom_layout, R.id.main_list_item, main_menu);
listView.setAdapter(main_adapter);
}
public void openNewActivity(View view) {
EditText main_edit_text = (EditText) findViewById(R.id.main_edit_text);
String answer = main_edit_text.getText().toString().trim();
switch (answer) {
case "1": {
Intent intent = new Intent(this, IntroActivity.class);
startActivity(intent);
break;
}
case "2": {
Intent intent = new Intent(this, HelpActivity.class);
startActivity(intent);
break;
}
case "3": {
Intent intent = new Intent(this, AroundTheWorldActivity.class);
startActivity(intent);
break;
}
default: {
Intent intent = new Intent(getApplicationContext(), MainMenuActivity.class);
startActivity(intent);
break;
}
}
}
我创建了在第一个菜单上的EditText中键入“3”(案例3)时出现的菜单。
AroundTheWorldActivity.java:
public class AroundTheWorldActivity extends Activity {
ListView listView;
ArrayAdapter<String> around_the_world_adapter;
String[] around_the_world_menu = {
"1 OVERVIEW",
"2 RECEIVING"
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.around_the_world_layout);
listView = (ListView) findViewById(R.id.around_the_world_list);
around_the_world_adapter = new ArrayAdapter<>(this, R.layout.around_the_world_list_custom_layout, R.id.around_the_world_list_item, around_the_world_menu);
listView.setAdapter(around_the_world_adapter);
}
public void openNewActivity(View view) {
EditText around_the_world_edit_text = (EditText) findViewById(R.id.around_the_world_edit_text);
String answer = around_the_world_edit_text.getText().toString().trim();
switch (answer) {
case "1": {
Intent atwintent = new Intent(this, AroundTheWorldOverviewActivity.class);
startActivity(atwintent);
break;
}
case "2": {
Intent atwintent = new Intent(this, ReceivingActivity.class);
startActivity(atwintent);
break;
}
default: {
Intent atwintent = new Intent(getApplicationContext(), AroundTheWorldActivity.class);
startActivity(atwintent);
break;
}
}
}
我配置了在二级菜单中输入“1”(案例1)时打开的活动。
AroundTheWorldOverviewActivity.java:
public class AroundTheWorldOverviewActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.around_the_world_overview_layout);
}
}
around_the_world_overview_layout.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
>
<TextView
android:id="@+id/atw_overview_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-smallcaps"
android:gravity="center_horizontal"
android:padding="16dp"
android:text="Around The World Overview Text"
android:textAppearance="?android:textAppearanceLarge"
android:textColor="#ffffff"
/>
</RelativeLayout>
我能够浏览第二个菜单,但当我尝试访问第三个Activity时,该应用程序停止工作/崩溃。
logcat的:
08-01 19:54:43.500 2220-2220/com.google.android.googlequicksearchbox:search
I/MicroDetectionWorker: Micro detection mode: [mDetectionMode: [1]].
08-01 19:54:43.502 2220-2220/com.google.android.googlequicksearchbox:search
I/AudioController: Using mInputStreamFactoryBuilder
08-01 19:54:43.534 2220-4313/com.google.android.googlequicksearchbox:search I/MicroRecognitionRunner: Starting detection.
08-01 19:54:43.540 2220-2324/com.google.android.googlequicksearchbox:search I/MicrophoneInputStream: mic_starting com.google.android.apps.gsa.staticplugins.z.c@ae6a309
08-01 19:54:43.548 1365-4316/? I/AudioFlinger: AudioFlinger's thread 0xacf83540 ready to run
08-01 19:54:43.562 2220-2324/com.google.android.googlequicksearchbox:search I/MicrophoneInputStream: mic_started com.google.android.apps.gsa.staticplugins.z.c@ae6a309
08-01 19:54:43.567 2220-2324/com.google.android.googlequicksearchbox:search E/ActivityThread: Failed to find provider info for com.google.android.apps.gsa.testing.ui.audio.recorded
08-01 19:54:43.569 2220-2324/com.google.android.googlequicksearchbox:search I/MicrophoneInputStream: mic_close com.google.android.apps.gsa.staticplugins.z.c@ae6a309
08-01 19:54:43.573 2220-2220/com.google.android.googlequicksearchbox:search I/MicroDetectionWorker: onReady
08-01 19:54:43.588 2220-4313/com.google.android.googlequicksearchbox:search I/MicroRecognitionRunner: Detection finished
08-01 19:54:43.588 2220-4313/com.google.android.googlequicksearchbox:search W/ErrorReporter: reportError [type: 211, code: 524300]: Error reading from input stream
08-01 19:54:43.590 2220-2492/com.google.android.googlequicksearchbox:search I/MicroRecognitionRunner: Stopping hotword detection.
08-01 19:54:43.591 2220-4313/com.google.android.googlequicksearchbox:search W/ErrorProcessor: onFatalError, processing error from engine(4)
com.google.android.apps.gsa.shared.speech.a.g: Error reading from input stream
at com.google.android.apps.gsa.staticplugins.recognizer.i.a.a(SourceFile:342)
at com.google.android.apps.gsa.staticplugins.recognizer.i.a$1.run(SourceFile:1367)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:428)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at com.google.android.apps.gsa.shared.util.concurrent.a.ak.run(SourceFile:66)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)
at com.google.android.apps.gsa.shared.util.concurrent.a.ad$1.run(SourceFile:85)
Caused by: com.google.android.apps.gsa.shared.exception.GsaIOException: Error code: 393238 | Buffer overflow, no available space.
at com.google.android.apps.gsa.speech.audio.Tee.g(SourceFile:2531)
at com.google.android.apps.gsa.speech.audio.ap.read(SourceFile:555)
at java.io.InputStream.read(InputStream.java:101)
at com.google.android.apps.gsa.speech.audio.al.run(SourceFile:362)
at com.google.android.apps.gsa.speech.audio.ak$1.run(SourceFile:471)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:428)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at com.google.android.apps.gsa.shared.util.concurrent.a.ak.run(SourceFile:66)
at com.google.android.apps.gsa.shared.util.concurrent.a.ax.run(SourceFile:139)
at com.google.android.apps.gsa.shared.util.concurrent.a.ax.run(SourceFile:139)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)
at com.google.android.apps.gsa.shared.util.concurrent.a.ad$1.run(SourceFile:85)
08-01 19:54:43.591 2220-4313/com.google.android.googlequicksearchbox:search I/AudioController: internalShutdown
08-01 19:54:43.601 2220-2220/com.google.android.googlequicksearchbox:search I/MicroDetector: Keeping mic open: false
08-01 19:54:43.601 2220-2220/com.google.android.googlequicksearchbox:search I/MicroDetectionWorker: #onError(false)
08-01 19:54:43.603 2220-4312/com.google.android.googlequicksearchbox:search I/DeviceStateChecker: DeviceStateChecker cancelled
08-01 19:54:43.625 2220-2234/com.google.android.googlequicksearchbox:search I/art: Background sticky concurrent mark sweep GC freed 8140(454KB) AllocSpace objects, 7(2MB) LOS objects, 15% free, 14MB/17MB, paused 7.682ms total 89.059ms
08-01 19:54:45.634 1900-2821/com.android.phone I/OmtpVvmCarrierCfgHlpr: OmtpEvent:CONFIG_STATUS_SMS_TIME_OUT
08-01 19:54:45.641 1900-1900/com.android.phone I/RetryPolicy: discarding deferred status: configuration_state=4
08-01 19:54:45.655 1900-1900/com.android.phone D/VvmTaskScheduler: No more tasks, stopping service if no task are added in 5000 millis
08-01 19:54:45.661 1900-1900/com.android.phone D/VvmTaskScheduler: create task:com.android.phone.vvm.omtp.ActivationTask
08-01 19:54:45.662 1900-1900/com.android.phone D/RetryPolicy: retry #2 for com.android.phone.vvm.omtp.ActivationTask@6bd2e67 queued, executing in 5000
08-01 19:54:45.669 1900-1900/com.android.phone D/VvmTaskScheduler: minimal wait time:4995
08-01 19:54:45.671 1900-1900/com.android.phone D/VvmTaskScheduler: minimal wait time:4993
答案 0 :(得分:0)
OOPS ...我忘了在清单文件中添加一个活动 - 我感谢大家的帮助,我希望这并没有占用太多人的时间! / p>