0

help debugging a basic app in android studio

Hey guys. Uber noob to programming but have started trying to make a really basic app using a tutorial (https://developer.android.com/training/basics/firstapp/starting-activity.html) but I've run into a few road blocks. I've tried making this app twice and failed miserably lol. One issue is that the line `import android.view.ViewGroup;' keeps disappearing from the code as soon as its entered. The second issue is that the app crashes as soon as it starts. I had the first activity working initially but the app would crash when the button was clicked. I've triad clean/rebuild but it hasn't helped at all. I've also tried other basic info I could like editing or removing certain parts of the code but they didn't help either. I tried posting in Stack Overflow but even that wouldn't help :/ So at this stage any and all help would be great;y appreciated! Thanks in advance! Logcat error info 06-14 20:56:40.335 25791-25791/com.example.jacqueline.myfirstapp E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.jacqueline.myfirstapp, PID: 25791 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.jacqueline.myfirstapp/com.example.jacqueline.myfirstapp.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2711) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2772) at android.app.ActivityThread.-wrap12(ActivityThread.java)

14th Jun 2017, 12:11 PM
Bandit013
6 ответов
0
Can you copy-paste your XML and Java code?
15th Jun 2017, 3:09 PM
Elias Papachristos
Elias Papachristos - avatar
0
Main: package com.example.jacqueline.myfirstapp; import android.content.Intent; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.EditText; public class MainActivity extends AppCompatActivity { public static final String EXTRA_MESSAGE = "com.example.jacqueline.myfirstapp.MESSAGE"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void sendMessage(View view) { Intent intent = new Intent(this, DisplayMessageActivity.class); EditText editText = (EditText) findViewById(R.id.editText); String message = editText.getText().toString(); intent.putExtra(EXTRA_MESSAGE, message); startActivity(intent); } public class EXTRA_MESSAGE { } } Display message activity: package com.example.jacqueline.myfirstapp; import android.content.Intent; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.widget.TextView; public class DisplayMessageActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_display_message); //Get the Intent that started this message and extract the String Intent intent = getIntent(); String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE); //Capture the layout's TextView and set the string as its text TextView textView = (TextView) findViewById(R.id.textView); textView.setText(message); } }
15th Jun 2017, 4:58 PM
Bandit013
0
Manifest: <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.jacqueline.myfirstapp"> <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"> <activity android:name=".MainActivity" android:theme="@style/Theme.AppCompat.NoActionBar"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".DisplayMessageActivity" android:parentActivityName=".MainActivity" android:theme="@style/Theme.AppCompat.NoActionBar"> <!-- THe Meta-Data Tag is required if you support API level 15 or lower --> <meta-data android:name="android.support.PARENT_ACTIVITY" android:value=".MainActivity" /> </activity> </application> </manifest>
15th Jun 2017, 4:59 PM
Bandit013
0
UPDATED LOGCAT - 06-16 02:08:47.505 15866-15866/com.example.jacqueline.myfirstapp E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.jacqueline.myfirstapp, PID: 15866 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.jacqueline.myfirstapp/com.example.jacqueline.myfirstapp.DisplayMessageActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2711) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2772) at android.app.ActivityThread.-wrap12(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1515) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:241) at android.app.ActivityThread.main(ActivityThread.java:6217) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
15th Jun 2017, 5:02 PM
Bandit013
0
I've followed the instructions of the link (https://developer.android.com/training/basics/firstapp/creating-project.html) and it works for me. At your Manifest you write: <activity android:name=".DisplayMessageActivity" android:parentActivityName=".MainActivity" android:theme="@style/Theme.AppCompat.NoActionBar"> try it as it tells you instead: <activity android:name=".DisplayMessageActivity" android:parentActivityName=".MainActivity" >
15th Jun 2017, 10:28 PM
Elias Papachristos
Elias Papachristos - avatar
0
I initially didn't have that line there. when I remove it I get other error - 06-16 15:51:17.532 19324-19324/com.example.jacqueline.myfirstapp E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.jacqueline.myfirstapp, PID: 19324 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.jacqueline.myfirstapp/com.example.jacqueline.myfirstapp.DisplayMessageActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2711) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2772) at android.app.ActivityThread.-wrap12(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1515) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:241) at android.app.ActivityThread.main(ActivityThread.java:6217) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
16th Jun 2017, 6:23 AM
Bandit013