새로운 활동을 추가하고 해당 활동으로 이동하는 버튼을 추가하지만 "보내기"버튼을 누른 후 런타임 예외 오류 (응용 프로그램 충돌)가 계속 발생하여 Android 튜토리얼 애플리케이션을 편집하려고 시도했습니다. 비슷한 많은 문제들을 살펴 봤지만 다른 사람들을 위해 일한 해결책은 나를 위해 일하지 않습니다. DisplayMessageActivity.xmladdView 런타임 예외
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.myfirstapp.DisplayMessageActivity"
tools:ignore="MergeRootFrame" >
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
android:onClick="switchActivity"
android:text="@string/next" />
</LinearLayout>
DisplayMessageActivity.java
package com.example.myfirstapp;
import android.app.Activity;
import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;
public class DisplayMessageActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get the message from the intent
Intent intent = getIntent();
String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
// Create the text view
TextView textView = new TextView(this);
textView.setTextSize(40);
textView.setText(message);
ViewGroup layout = (ViewGroup) findViewById(R.id.container);
layout.addView(textView);
// Set the text view as the activity layout
setContentView(R.layout.activity_display_message);
//setContentView(textView);
}
@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();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() { }
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_display_message,
container, false);
return rootView;
}
}
public void switchActivity (View view) {
Intent maxIntent = new Intent(this, Selection.class);
startActivity(maxIntent);
}
}
당신이 내 오류를 찾을 수 있기를 바랍니다. 미리 감사드립니다.
자세한 정보를 제공해야합니다. 스택 추적은 어디에 있습니까? 특히 오류를 수정하려고 시도한 적이 있습니까? – Keppil
'super.onCreate()'아래에서'setContentView (R.layout.activity_display_message);'이동 – Apoorv