我正在开发一个独立的应用程序,并且正在学习一些基础教程。从我所知道的,代码几乎与我正在遵循的指南相同,但是当我尝试在模拟器上运行应用程序时,我发现“不幸的是已停止工作”消息。我在解释logcat中的错误时遇到了一些困难,因为许多有向代码行是我启动新文件时创建的默认代码。任何帮助都会得到赞赏,谢谢
03-28 18:45:27.390: D/FragmentManager(1033): mCreated=truemResumed=false mStopped=false mReallyStopped=false
03-28 18:45:27.390: D/FragmentManager(1033): mLoadersStarted=false
03-28 18:45:27.400: D/FragmentManager(1033): Active Fragments in b3d357b8:
03-28 18:45:27.400: D/FragmentManager(1033): #0: PlaceholderFragment{b3d35b68 #0 id=0x7f06003c}
03-28 18:45:27.400: D/FragmentManager(1033): mFragmentId=#7f06003c mContainerId=#7f06003c mTag=null
03-28 18:45:27.400: D/FragmentManager(1033): mState=0 mIndex=0 mWho=android:fragment:0 mBackStackNesting=0
03-28 18:45:27.400: D/FragmentManager(1033): mAdded=true mRemoving=false mResumed=false mFromLayout=false mInLayout=false
03-28 18:45:27.400: D/FragmentManager(1033): mHidden=false mDetached=false mMenuVisible=true mHasMenu=false
03-28 18:45:27.400: D/FragmentManager(1033): mRetainInstance=false mRetaining=false mUserVisibleHint=true
03-28 18:45:27.400: D/FragmentManager(1033): mFragmentManager=FragmentManager{b3d357b8 in MainActivity{b3d34660}}
03-28 18:45:27.400: D/FragmentManager(1033): mActivity=com.example.cooldog.MainActivity@b3d34660
03-28 18:45:27.400: D/FragmentManager(1033): Added Fragments:
03-28 18:45:27.400: D/FragmentManager(1033): #0: PlaceholderFragment{b3d35b68 #0 id=0x7f06003c}
03-28 18:45:27.410: D/FragmentManager(1033): FragmentManager misc state:
03-28 18:45:27.410: D/FragmentManager(1033): mActivity=com.example.cooldog.MainActivity@b3d34660
03-28 18:45:27.170: D/dalvikvm(1033): GC_FOR_ALLOC freed 83K, 6% free 2860K/3012K, paused 52ms, total 54ms
03-28 18:45:27.180: I/dalvikvm-heap(1033): Grow heap (frag case) to 3.575MB for 756876-byte allocation
03-28 18:45:27.260: D/dalvikvm(1033): GC_FOR_ALLOC freed 2K, 5% free 3596K/3752K, paused 74ms, total 74ms
03-28 18:45:27.380: E/FragmentManager(1033): No view found for id 0x7f06003c (com.example.cooldog:id/container) for fragment PlaceholderFragment{b3d35b68 #0 id=0x7f06003c}
03-28 18:45:27.380: E/FragmentManager(1033): Activity state:
03-28 18:45:27.390: D/FragmentManager(1033): Local FragmentActivity b3d34660 State:
03-28 18:45:27.420: D/FragmentManager(1033): mContainer=android.support.v4.app.FragmentActivity$2@b3d36130
03-28 18:45:27.420: D/FragmentManager(1033): mCurState=2 mStateSaved=false mDestroyed=false
03-28 18:45:27.420: D/FragmentManager(1033): View Hierarchy:
03-28 18:45:27.420: D/FragmentManager(1033): com.android.internal.policy.impl.PhoneWindow$DecorView{b3d3acc0 V.E..... ... 0,0-0,0}
03-28 18:45:27.430: D/FragmentManager(1033): com.android.internal.widget.ActionBarOverlayLayout{b3d3bdb8 V.ED.... ... 0,0-0,0 #1020313 android:id/action_bar_overlay_layout}
03-28 18:45:27.430: D/FragmentManager(1033): android.widget.FrameLayout{b3d3d528 V.E..... ... 0,0-0,0 #1020002 android:id/content}
03-28 18:45:27.430: D/FragmentManager(1033): android.widget.RelativeLayout{b3d52388 V.E..... ... 0,0-0,0 #7f06003d app:id/RelativeLayout1}
03-28 18:45:27.430: D/FragmentManager(1033): android.widget.TextView{b3d33db8 V.ED.... ... 0,0-0,0 #7f06003e app:id/TextView1}
03-28 18:45:27.440: D/FragmentManager(1033): android.widget.Button{b3d336a0 VFED..C. ... 0,0-0,0 #7f06003f app:id/readWish}
03-28 18:45:27.440: D/FragmentManager(1033): com.android.internal.widget.ActionBarContainer{b3d3dac0 V.ED.... ... 0,0-0,0 #1020314 android:id/action_bar_container}
03-28 18:45:27.440: D/FragmentManager(1033): com.android.internal.widget.ActionBarView{b3d40678 V.E..... ... 0,0-0,0 #1020315 android:id/action_bar}
03-28 18:45:27.440: D/FragmentManager(1033): android.widget.LinearLayout{b3d40e58 V.....C. ... 0,0-0,0}
03-28 18:45:27.440: D/FragmentManager(1033): com.android.internal.widget.ActionBarView$HomeView{b3d44d30 V.E..... ... 0,0-0,0}
03-28 18:45:27.440: D/FragmentManager(1033): android.widget.ImageView{b3d45278 G.ED.... ... 0,0-0,0 #102025a android:id/up}
03-28 18:45:27.440: D/FragmentManager(1033): android.widget.ImageView{b3d463d8 V.ED.... ... 0,0-0,0 #102002c android:id/home}
03-28 18:45:27.440: D/FragmentManager(1033): android.widget.LinearLayout{b3d47a88 G.E..... ... 0,0-0,0}
03-28 18:45:27.440: D/FragmentManager(1033): android.widget.TextView{b3d47fa8 V.ED.... ... 0,0-0,0 #1020265 android:id/action_bar_title}
03-28 18:45:27.440: D/FragmentManager(1033): android.widget.TextView{b3d48d10 G.ED.... ... 0,0-0,0 #1020266 android:id/action_bar_subtitle}
03-28 18:45:27.440: D/FragmentManager(1033): com.android.internal.widget.ActionBarContextView{b3d49478 G.E..... ... 0,0-0,0 #1020316 android:id/action_context_bar}
03-28 18:45:27.440: D/FragmentManager(1033): com.android.internal.widget.ActionBarContainer{b3d4bee8 G.ED.... ... 0,0-0,0 #1020317 android:id/split_action_bar}
03-28 18:45:27.460: D/AndroidRuntime(1033): Shutting down VM
03-28 18:45:27.460: W/dalvikvm(1033): threadid=1: thread exiting with uncaught exception (group=0xb3a72ba8)
03-28 18:45:27.480: E/AndroidRuntime(1033): FATAL EXCEPTION: main
03-28 18:45:27.480: E/AndroidRuntime(1033): Process: com.example.cooldog, PID: 1033
03-28 18:45:27.480: E/AndroidRuntime(1033): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.cooldog/com.example.cooldog.MainActivity}: java.lang.IllegalArgumentException: No view found for id 0x7f06003c (com.example.cooldog:id/container) for fragment PlaceholderFragment{b3d35b68 #0 id=0x7f06003c}
03-28 18:45:27.480: E/AndroidRuntime(1033): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
03-28 18:45:27.480: E/AndroidRuntime(1033): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
03-28 18:45:27.480: E/AndroidRuntime(1033): at android.app.ActivityThread.access$800(ActivityThread.java:135)
03-28 18:45:27.480: E/AndroidRuntime(1033): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
03-28 18:45:27.480: E/AndroidRuntime(1033): at android.os.Handler.dispatchMessage(Handler.java:102)
03-28 18:45:27.480: E/AndroidRuntime(1033): at android.os.Looper.loop(Looper.java:136)
03-28 18:45:27.480: E/AndroidRuntime(1033): at android.app.ActivityThread.main(ActivityThread.java:5017)
03-28 18:45:27.480: E/AndroidRuntime(1033): at java.lang.reflect.Method.invokeNative(Native Method)
03-28 18:45:27.480: E/AndroidRuntime(1033): at java.lang.reflect.Method.invoke(Method.java:515)
03-28 18:45:27.480: E/AndroidRuntime(1033): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
03-28 18:45:27.480: E/AndroidRuntime(1033): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
03-28 18:45:27.480: E/AndroidRuntime(1033): at dalvik.system.NativeStart.main(Native Method)
03-28 18:45:27.480: E/AndroidRuntime(1033): Caused by: java.lang.IllegalArgumentException: No view found for id 0x7f06003c (com.example.cooldog:id/container) for fragment PlaceholderFragment{b3d35b68 #0 id=0x7f06003c}
03-28 18:45:27.480: E/AndroidRuntime(1033): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:919)
03-28 18:45:27.480: E/AndroidRuntime(1033): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
03-28 18:45:27.480: E/AndroidRuntime(1033): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
03-28 18:45:27.480: E/AndroidRuntime(1033): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1467)
03-28 18:45:27.480: E/AndroidRuntime(1033): at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:570)
03-28 18:45:27.480: E/AndroidRuntime(1033): at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1171)
03-28 18:45:27.480: E/AndroidRuntime(1033): at android.app.Activity.performStart(Activity.java:5241)
03-28 18:45:27.480: E/AndroidRuntime(1033): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2168)
03-28 18:45:27.480: E/AndroidRuntime(1033): ... 11 more
03-28 18:45:33.480: I/Process(1033): Sending signal. PID: 1033 SIG: 9
=============================================== ===============
=============================================== ===============
package com.example.cooldog;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import android.os.Build;
public class MainActivity extends ActionBarActivity {
//Fields//
int wishes;
Button read;
TextView currentlyReadWish; //travis's display
//Methods//
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_main);
wishes = 0;
read = (Button) findViewById(R.id.readWish);
currentlyReadWish = (TextView) findViewById(wishes); //REPLACE WITH DATABASE MSG
read.setOnClickListener(new View.OnClickListener() { //new View.onClickListener might be wrong, this changes whats already on the screen, we want it to transition to another one with a different view entirely
public void onClick(View v) {
//Auto-generated method stub WHAT HAPPENS WHEN U CLICK
//BRINGS YOU TO NEW SCREEN OR POPS UP A ENCOMPASSING WINDOW ON ABOVE SCREEN
//DISPLAYS WISH
currentlyReadWish.setText("THEWISHMSG");
}
});
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@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_main, container,
false);
return rootView;
}
}
}
=============================================== ===============
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/ice_cream"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.cooldog.MainActivity$PlaceholderFragment" >
<TextView
android:id="@+id/TextView1"
android:layout_width="207dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="26dp"
android:gravity="center"
android:text="@string/greeting1"
android:textSize="18sp" />
<Button
android:id="@+id/readWish"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_alignRight="@+id/TextView1"
android:layout_centerVertical="true"
android:orientation="horizontal" />
=============================================== ===============
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.cooldog"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.cooldog.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" /> <!-- WHAT ACTIVITY OPENS UPON LAUNCH, HAVE JUST ONE IDIOT -->
</intent-filter>
</activity>
<activity
android:name="com.example.cooldog.WishingCenter"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.example.cooldog.WISHINGCENTER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
=============================================== ===============
package com.example.cooldog;
import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
public class Transition1 extends Activity {
MediaPlayer transitionSong;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.ice_cream);
transitionSong = MediaPlayer.create(Transition1.this, R.raw.beasts);
transitionSong.start();
Thread timer = new Thread() {
public void run(){
try{
sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
Intent openNextWindow = new Intent("com.example.cooldog.WISHINGCENTER");
startActivity(openNextWindow);
}
}
};
timer.start();
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
transitionSong.release();
finish();
}
}
=============================================== ===============
package com.example.cooldog;
import android.app.Activity;
import android.os.Bundle;
public class WishingCenter extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.ice_cream);
}
}
=============================================== ===============
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/ice_cream">
</FrameLayout>
=============================================== ===============
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<string android:id="@+id/app_name" name="app_name">cooldog</string>
<string android:id="@+id/hello_world" name="hello_world">Hello world!</string>
<string android:id="@+id/action_settings" name="action_settings">Settings</string>
<string android:id="@+id/greeting1" name="greeting1">Welcome back, </string>
<string android:id="@+id/greeting2" android:layout_height="wrap_content" android:layout_width="wrap_content" name="greeting2"> new messages</string>
</resources>
答案 0 :(得分:0)
我认为您在Fragment活动的setContentView()
方法的onCreate()
中指定了错误的布局。
答案 1 :(得分:0)
好的,事实证明,当我启动应用程序时自动实现的一些默认代码是造成我的问题的原因。删除后,它按预期工作。感谢所有人的帮助和贡献。