ورود

View Full Version : اجرا نشدن اکتیویتی پیش فرض



m.toosi
یک شنبه 14 بهمن 1397, 20:48 عصر
سلام عرض شد
شبتون بخیر

دوستان هر کاری که می کنم ، این صفحه برای من اجرا نمیشه و در نهایت در اندروید خطا میده که برنامه متوقف شد :افسرده::ناراحت:
4 تا خط برنامه ساده است
چکار کنم بنظرتون ؟


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/activity_main"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<EditText
android:id="@+id/input_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:hint="Name"
android:inputType="textPersonName" />

<EditText
android:id="@+id/input_phone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:hint="phone No."
android:inputType="phone" />

<CheckBox
android:text="share my phone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/cbSharePhone"
android:checked="true"
/>
<view
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="@color/colorPrimary"
android:layout_marginTop="10dp"
/>

</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="10dp">

<EditText
android:id="@+id/input_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:layout_marginRight="0dp"
android:hint="Email"
android:inputType="textWebEmailAddress" />

<view
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="@color/colorPrimary"
android:layout_marginTop="10dp"
/>
<Button
android:id="@+id/btnSubmitFormInfo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Submit"
style="@style/Widget.AppCompat.Button.Colored" />
</LinearLayout>
</LinearLayout>

godofphp
یک شنبه 14 بهمن 1397, 22:20 عصر
لاگ کت را نگاه کنید ببینید خطا چیه . همون موقع که در اندروید خطای متوقف شد میدهد در لاگ کت علت آنرا مینویسد که میتونید متنش را در اینترنت سرچ کنید یا اینجابفرستید راهنمایی شود

آواسام مرجع آموزش انلاین برنامه نویسی ایران (http://avasam.ir)

m.toosi
دوشنبه 15 بهمن 1397, 20:29 عصر
لاگ کت را نگاه کنید ببینید خطا چیه . همون موقع که در اندروید خطای متوقف شد میدهد در لاگ کت علت آنرا مینویسد که میتونید متنش را در اینترنت سرچ کنید یا اینجابفرستید راهنمایی شود

آواسام مرجع آموزش انلاین برنامه نویسی ایران (http://avasam.ir)

ممنون از پاسخت دوست عزیز
اشتباه متوجه شده بودم ، چند ساعت داشتم سعی میکردم لاگ کت رو جنی موشن نصب کنم :افسرده::ناراحت:

نگاه کنم ، باز خطاشو میفرستم براتون

m.toosi
دوشنبه 15 بهمن 1397, 21:30 عصر
لاگ کت را نگاه کنید ببینید خطا چیه . همون موقع که در اندروید خطای متوقف شد میدهد در لاگ کت علت آنرا مینویسد که میتونید متنش را در اینترنت سرچ کنید یا اینجابفرستید راهنمایی شود

آواسام مرجع آموزش انلاین برنامه نویسی ایران (http://avasam.ir)

متن خطا اینه
منکه چیزی ازش سر درنیاوردم

آخه باهمین دستورات کار میکرد ، من فقط یک پیج اضافه کردم که خطارو ازون صفحه نمیگیره و از صفحه مین اصلی میگیره :ناراحت:


02-04 17:00:34.934 7631-7631/ir.mtoosi.helloworld3_acrivity E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{ir.mtoosi.helloworld3_acrivity/ir.mtoosi.helloworld3_acrivity.MainActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(A ctivityThread.java:2059)
at android.app.ActivityThread.handleLaunchActivity(Ac tivityThread.java:2084)
at android.app.ActivityThread.access$600(ActivityThre ad.java:130)
at android.app.ActivityThread$H.handleMessage(Activit yThread.java:1195)
at android.os.Handler.dispatchMessage(Handler.java:99 )
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.jav a:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCa ller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit .java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at ir.mtoosi.helloworld3_acrivity.MainActivity.onCrea te(MainActivity.java:34)
at android.app.Activity.performCreate(Activity.java:5 008)
at android.app.Instrumentation.callActivityOnCreate(I nstrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(A ctivityThread.java:2023)
at android.app.ActivityThread.handleLaunchActivity(Ac tivityThread.java:2084)
at android.app.ActivityThread.access$600(ActivityThre ad.java:130)
at android.app.ActivityThread$H.handleMessage(Activit yThread.java:1195)
at android.os.Handler.dispatchMessage(Handler.java:99 )
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.jav a:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCa ller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit .java:553)
at dalvik.system.NativeStart.main(Native Method)
02-04 17:05:35.010 7631-7631/? I/Process: Sending signal. PID: 7631 SIG: 9

farhad_shiri_ex
سه شنبه 16 بهمن 1397, 08:59 صبح
متن خطا اینه
منکه چیزی ازش سر درنیاوردم

آخه باهمین دستورات کار میکرد ، من فقط یک پیج اضافه کردم که خطارو ازون صفحه نمیگیره و از صفحه مین اصلی میگیره :ناراحت:


02-04 17:00:34.934 7631-7631/ir.mtoosi.helloworld3_acrivity E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{ir.mtoosi.helloworld3_acrivity/ir.mtoosi.helloworld3_acrivity.MainActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(A ctivityThread.java:2059)
at android.app.ActivityThread.handleLaunchActivity(Ac tivityThread.java:2084)
at android.app.ActivityThread.access$600(ActivityThre ad.java:130)
at android.app.ActivityThread$H.handleMessage(Activit yThread.java:1195)
at android.os.Handler.dispatchMessage(Handler.java:99 )
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.jav a:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCa ller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit .java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at ir.mtoosi.helloworld3_acrivity.MainActivity.onCrea te(MainActivity.java:34)
at android.app.Activity.performCreate(Activity.java:5 008)
at android.app.Instrumentation.callActivityOnCreate(I nstrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(A ctivityThread.java:2023)
at android.app.ActivityThread.handleLaunchActivity(Ac tivityThread.java:2084)
at android.app.ActivityThread.access$600(ActivityThre ad.java:130)
at android.app.ActivityThread$H.handleMessage(Activit yThread.java:1195)
at android.os.Handler.dispatchMessage(Handler.java:99 )
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.jav a:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCa ller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit .java:553)
at dalvik.system.NativeStart.main(Native Method)
02-04 17:05:35.010 7631-7631/? I/Process: Sending signal. PID: 7631 SIG: 9


این پیغام خطا که Null Pointer هست که می تونه دلایل مختلفی داشته باشه! بهتر بود اون قسمت از برنامه تون را هم که مشکل داشت را اینجا قرار بدید تا مشکلتون را رفع شود!

m.toosi
سه شنبه 16 بهمن 1397, 19:31 عصر
این پیغام خطا که Null Pointer هست که می تونه دلایل مختلفی داشته باشه! بهتر بود اون قسمت از برنامه تون را هم که مشکل داشت را اینجا قرار بدید تا مشکلتون را رفع شود!



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/layout_form_info"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp">


<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:hint="Name"
android:id="@+id/input_name"
android:layout_weight="7" />

<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:inputType="phone"
android:hint="Phone No."
android:maxLength="11"
android:id="@+id/input_phone"
android:layout_weight="3"
android:textSize="12sp"/>

</LinearLayout>

<CheckBox
android:text="Share my phone number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checked="true"
android:id="@+id/cb_share_phone" />

<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#d63605"
android:layout_marginTop="10dp" />

<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp">

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:hint="Email"
android:ems="10"
android:id="@+id/input_email"
android:layout_weight="1" />
</LinearLayout>

<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#2391b9"
android:layout_marginTop="10dp" />

<Button
style="@style/Widget.AppCompat.Button.Colored"
android:text="Submit"
android:layout_marginTop="15dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/btn_submit" />


</LinearLayout>

دستورات استفاده شده در xml و جاوا


package ir.mtoosi.helloworld3_acrivity;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.Toast;


public class FormInfo implements View.OnClickListener, CompoundButton.OnCheckedChangeListener {
private Activity activity;
private LinearLayout layoutFormInfo;
private EditText inputName;
private EditText inputPhone;
private EditText inputEmail;
private CheckBox cbSharePhone;
private Button btnSubmit;

public FormInfo(Activity activity, int layoutId) {
this.layoutFormInfo = (LinearLayout) activity.findViewById(layoutId);
this.activity = activity;
init();
}
private void init() {
if(layoutFormInfo == null){
return;
}
inputName = (EditText) layoutFormInfo.findViewById(R.id.input_name);
inputPhone = (EditText) layoutFormInfo.findViewById(R.id.input_phone);
inputEmail = (EditText) layoutFormInfo.findViewById(R.id.input_email);
cbSharePhone = (CheckBox) layoutFormInfo.findViewById(R.id.cb_share_phone);
btnSubmit = (Button) layoutFormInfo.findViewById(R.id.btn_submit);
btnSubmit.setOnClickListener(this);

cbSharePhone.setOnCheckedChangeListener(this);
}
public EditText getInputName() {
return inputName;
}

public EditText getInputPhone() {
return inputPhone;
}
public EditText getInputEmail() {
return inputEmail;
}
public CheckBox getCbSharePhone() {
return cbSharePhone;
}
public Button getBtnSubmit() {
return btnSubmit;
}

@Override
public void onClick(View view) {
if(view.getId() == btnSubmit.getId()){
String email = inputEmail.getText().toString().trim();
String phone = inputPhone.getText().toString().trim();
String name = inputName.getText().toString().trim();
if(isValidInput(name, phone, email)){
Intent intent = new Intent(activity, SecendActivity.class);
intent.putExtra("name" , name);
if(cbSharePhone.isChecked()){
intent.putExtra("phone", phone);
}
intent.putExtra("email", email);
activity.startActivity(intent);
}
}
}

@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
if(compoundButton.getId() == cbSharePhone.getId()){
inputPhone.setEnabled(isChecked);
}
}

public boolean isValidInput(String name, String phone, String email) {
if(name == null)
name = inputName.getText().toString().trim();
if(phone == null)
phone = inputPhone.getText().toString().trim();
if(email == null)
email = inputEmail.getText().toString().trim();

if(name.length() < 3){
Toast.makeText(activity, "name should be at least 3 characters", Toast.LENGTH_SHORT).show();
inputName.requestFocus();
return false;
}

if(!phone.isEmpty() && (phone.length() != 11 || !phone.startsWith("09"))){
Toast.makeText(activity, "Wrong Phone Number", Toast.LENGTH_SHORT).show();
inputPhone.requestFocus();
return false;
}
if( email.lastIndexOf('@') <= 0 || !email.contains(".")
|| email.lastIndexOf('.') < email.lastIndexOf('@')
|| email.split("@").length > 2)
{
Toast.makeText(activity, "Wrong Email Address", Toast.LENGTH_SHORT).show();
inputEmail.requestFocus();
return false;
}
return true;
}
}

دستوراتی که استفاده کرده ام اینا هستن ، دقیقا وقتی که برنامه رو اجرا میکنم ، متوقف میشه
و خطای زیر رو هم میده


02-05 16:27:18.304 1773-1773/ir.mtoosi.helloworld3_acrivity E/AndroidRuntime: FATAL EXCEPTION: main
android.content.ActivityNotFoundException: Unable to find explicit activity class {ir.mtoosi.helloworld3_acrivity/ir.mtoosi.helloworld3_acrivity.FormInfo}; have you declared this activity in your AndroidManifest.xml?
at android.app.Instrumentation.checkStartActivityResu lt(Instrumentation.java:1541)
at android.app.Instrumentation.execStartActivity(Inst rumentation.java:1416)
at android.app.Activity.startActivityForResult(Activi ty.java:3351)
at android.support.v4.app.BaseFragmentActivityApi16.s tartActivityForResult(BaseFragmentActivityApi16.ja va:54)
at android.support.v4.app.FragmentActivity.startActiv ityForResult(FragmentActivity.java:67)
at android.app.Activity.startActivityForResult(Activi ty.java:3312)
at android.support.v4.app.FragmentActivity.startActiv ityForResult(FragmentActivity.java:720)
at android.app.Activity.startActivity(Activity.java:3 522)
at android.app.Activity.startActivity(Activity.java:3 490)
at ir.mtoosi.helloworld3_acrivity.MainActivity$4.onCl ick(MainActivity.java:70)
at android.view.View.performClick(View.java:4084)
at android.view.View$PerformClick.run(View.java:16966 )
at android.os.Handler.handleCallback(Handler.java:615 )
at android.os.Handler.dispatchMessage(Handler.java:92 )
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.jav a:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCa ller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit .java:553)
at dalvik.system.NativeStart.main(Native Method)
02-05 16:27:48.408 1773-1773/? I/Process: Sending signal. PID: 1773 SIG: 9