由於某些原因,我的應用程序崩潰時,我cLick Button
。我在互聯網上搜索了 ,一切似乎都很好。 我將非常感謝您的建議,以幫助我找出問題所在。 這是我點擊Button
的第一個Java。 我想知道什麼是problem.Thanksonclicklistener函數onclick崩潰
package nir.rauc.mapstutori;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class Details extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_details);
final Button button1 = (Button) findViewById(R.id.button1);
button1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Details.this, Pictures.class);
startActivity(intent);
}
});
}
}
acitivty_details.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FF00FF00" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="38dp"
android:layout_marginTop="60dp"
android:text="price : 2.4 M "
android:textSize="40sp" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignRight="@+id/textView1"
android:layout_marginBottom="31dp"
android:background="#4004F0"
android:text="Click to Check for pictures" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView1"
android:layout_marginTop="44dp"
android:text="Street: Biking botoom"
android:textSize="40sp" />
</RelativeLayout>
第二java的文件:
package nir.rauc.mapstutori;
import android.app.Activity;
import android.os.Bundle;
public class Pictures extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.picturescroll);
}
}
picturescroll.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fillViewport="true"
android:scrollbars="horizontal|vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="@+id/viewImage1"
android:layout_width="125dp"
android:layout_height="125dp"
android:padding="15dp"
android:src="@drawable/first" />
<ImageView
android:id="@+id/viewImage2"
android:layout_width="125dp"
android:layout_height="125dp"
android:padding="15dp"
android:src="@drawable/second" />
<ImageView
android:id="@+id/viewImage3"
android:layout_width="125dp"
android:layout_height="125dp"
android:padding="15dp"
android:src="@drawable/third" />
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
編輯:MyManifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="nir.rauc.mapstutori"
android:versionCode="1"
android:versionName="1.0" >
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity
android:name="nir.rauc.mapstutori.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="CANTWRITHEITONSTACKOVERFLOW" />
<activity
android:name="nir.rauc.mapstutori.Details"
android:label="@string/title_activity_details" >
</activity>
<activity
android:name="nir.rauc.mapstutori.Pictures"
android:label="something" >
</activity>
</application>
</manifest>
編輯:Logtag
04-11 22:16:05.631: E/dalvikvm-heap(12095): Out of memory on a 53934352-byte allocation.
04-11 22:16:05.656: E/AndroidRuntime(12095): FATAL EXCEPTION: main
04-11 22:16:05.656: E/AndroidRuntime(12095): java.lang.RuntimeException: Unable to start activity ComponentInfo{nir.rauc.mapstutori/nir.rauc.mapstutori.Pictures}: android.view.InflateException: Binary XML file line #33: Error inflating class <unknown>
04-11 22:16:05.656: E/AndroidRuntime(12095): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2295)
04-11 22:16:05.656: E/AndroidRuntime(12095): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2349)
04-11 22:16:05.656: E/AndroidRuntime(12095): at android.app.ActivityThread.access$700(ActivityThread.java:159)
04-11 22:16:05.656: E/AndroidRuntime(12095): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
04-11 22:16:05.656: E/AndroidRuntime(12095): at android.os.Handler.dispatchMessage(Handler.java:99)
04-11 22:16:05.656: E/AndroidRuntime(12095): at android.os.Looper.loop(Looper.java:137)
04-11 22:16:05.656: E/AndroidRuntime(12095): at android.app.ActivityThread.main(ActivityThread.java:5419)
04-11 22:16:05.656: E/AndroidRuntime(12095): at java.lang.reflect.Method.invokeNative(Native Method)
04-11 22:16:05.656: E/AndroidRuntime(12095): at java.lang.reflect.Method.invoke(Method.java:525)
04-11 22:16:05.656: E/AndroidRuntime(12095): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)
04-11 22:16:05.656: E/AndroidRuntime(12095): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
04-11 22:16:05.656: E/AndroidRuntime(12095): at dalvik.system.NativeStart.main(Native Method)
04-11 22:16:05.656: E/AndroidRuntime(12095): Caused by: android.view.InflateException: Binary XML file line #33: Error inflating class <unknown>
04-11 22:16:05.656: E/AndroidRuntime(12095): at android.view.LayoutInflater.createView(LayoutInflater.java:626)
04-11 22:16:05.656: E/AndroidRuntime(12095): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
04-11 22:16:05.656: E/AndroidRuntime(12095): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:675)
04-11 22:16:05.656: E/AndroidRuntime(12095): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:700)
04-11 22:16:05.656: E/AndroidRuntime(12095): at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
04-11 22:16:05.656: E/AndroidRuntime(12095): at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
04-11 22:16:05.656: E/AndroidRuntime(12095): at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
04-11 22:16:05.656: E/AndroidRuntime(12095): at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
04-11 22:16:05.656: E/AndroidRuntime(12095): at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
04-11 22:16:05.656: E/AndroidRuntime(12095): at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
04-11 22:16:05.656: E/AndroidRuntime(12095): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:361)
04-11 22:16:05.656: E/AndroidRuntime(12095): at android.app.Activity.setContentView(Activity.java:1956)
04-11 22:16:05.656: E/AndroidRuntime(12095): at nir.rauc.mapstutori.Pictures.onCreate(Pictures.java:11)
04-11 22:16:05.656: E/AndroidRuntime(12095): at android.app.Activity.performCreate(Activity.java:5372)
04-11 22:16:05.656: E/AndroidRuntime(12095): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)
04-11 22:16:05.656: E/AndroidRuntime(12095): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2257)
04-11 22:16:05.656: E/AndroidRuntime(12095): ... 11 more
04-11 22:16:05.656: E/AndroidRuntime(12095): Caused by: java.lang.reflect.InvocationTargetException
04-11 22:16:05.656: E/AndroidRuntime(12095): at java.lang.reflect.Constructor.constructNative(Native Method)
04-11 22:16:05.656: E/AndroidRuntime(12095): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
04-11 22:16:05.656: E/AndroidRuntime(12095): at android.view.LayoutInflater.createView(LayoutInflater.java:600)
04-11 22:16:05.656: E/AndroidRuntime(12095): ... 26 more
04-11 22:16:05.656: E/AndroidRuntime(12095): Caused by: java.lang.OutOfMemoryError
04-11 22:16:05.656: E/AndroidRuntime(12095): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
04-11 22:16:05.656: E/AndroidRuntime(12095): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:596)
04-11 22:16:05.656: E/AndroidRuntime(12095): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444)
04-11 22:16:05.656: E/AndroidRuntime(12095): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:832)
04-11 22:16:05.656: E/AndroidRuntime(12095): at android.content.res.Resources.loadDrawable(Resources.java:2988)
04-11 22:16:05.656: E/AndroidRuntime(12095): at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
04-11 22:16:05.656: E/AndroidRuntime(12095): at android.widget.ImageView.<init>(ImageView.java:131)
04-11 22:16:05.656: E/AndroidRuntime(12095): at android.widget.ImageView.<init>(ImageView.java:121)
04-11 22:16:05.656: E/AndroidRuntime(12095): ... 29 more
你是否聲明瞭清單文件中的圖片 – Raghunandan
發佈logcat。 – codeMagic
發佈您的清單和圖片類代碼 – Libin