gpt4 book ai didi

android - 无法在设备上运行应用

转载 作者:行者123 更新时间:2023-12-03 08:49:26 25 4
gpt4 key购买 nike

I ran my app on virtual emulator and it ran fine. However when I tried to run it on a device, the app stops working. 

The manifest file is as follows:

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="false"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Activity2">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".Activity_3">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".Taskplanner" />
<activity android:name=".Activity_4" >
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>

我向 list 文件添加了意图过滤器,但该应用程序仍未运行。在设备上启动应用程序后,应用程序即时关闭,显示消息 应用程序已停止工作
Main_Activity.java- This activity contains a basic info and is linked to 2 other activites Activity2.java and Task.java when the buttons are clicked.

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

}

public void onclick(View view)
{
Intent i=new Intent(this,Activity2.class);
startActivity(i);
}
public void gotoplanner(View view)
{
Intent i=new Intent(this,Taskplanner.class);
startActivity(i);
}

}

Activity2.java- This activity is linked to the mainactivity and Activity3.java through buttons. It passes a message through an intent to Activity3.java.

public class Activity2 extends AppCompatActivity implements AdapterView.OnItemSelectedListener {

String[] citynames={"Ahmedabad","Agra","Amritsar","Bangalore","Bhopal","Bhubaneshwar","Chandigarh","Chennai","Dehradun","Delhi","Gangtok","Goa","Hyderabad","Jaipur","Kochi","Kolkata","Lucknow","Mumbai","Patna","Pune","Shillong","Simla","Srinagar","Trivandrum","Udaipur"};
Spinner spinner;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_2);


//Getting the instance of Spinner and applying OnItemSelectedListener on it

Spinner spinner2 = (Spinner) findViewById(R.id.spinnerto);
spinner2.setOnItemSelectedListener(this);

//Creating the ArrayAdapter instance having the citynames list
ArrayAdapter aa = new ArrayAdapter(this,android.R.layout.simple_spinner_item,citynames);
aa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

ArrayAdapter aa2 = new ArrayAdapter(this,android.R.layout.simple_spinner_item,citynames);
aa2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

//Setting the ArrayAdapter data on the Spinner
spinner2.setAdapter(aa2);
}

@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int position,long id) {
Toast.makeText(getApplicationContext(), citynames[position], Toast.LENGTH_LONG).show();
}

@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub

}
public void gotohome(View view)
{
Intent i=new Intent(this,MainActivity.class);
startActivity(i);
}
public void gotoinfo(View view)
{
spinner=(Spinner) findViewById(R.id.spinnerto);
String spin=spinner.getSelectedItem().toString();
Intent i=new Intent(this,Activity_3.class);
i.putExtra("Message",spin);
startActivity(i);

}
}

Activity3.java-his activity is linked to the Activity2.java and Activity4.java through buttons. It passes a message through an intent to Activity4.java.

public class Activity_3 extends AppCompatActivity {

private ListView listplace;
private DatabaseHelper databaseHelper;
private ArrayAdapter adapter;
String Message;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_3);

databaseHelper= new DatabaseHelper(this);

Bundle data=getIntent().getExtras();
if(data==null)
{
return;
}
Message=data.getString("Message");

Bundle data2=getIntent().getExtras();
if(data2==null)
{
return;
}
Message=data.getString("Message");

Log.d("insert", "inserting data for Place");
//databaseHelper.save(new Place("Agra","Uttar Pradesh","Hindi,Urdu,Punjabi,English","Hot and dry summers along with mild monsoon and mild winters ","The city is famous for the Mughal cuisine. Pethas from Agra are also very famous around the country.","Taj Mahotsav, Ram Barat,Taj Literature Festival,Kailash Fair,Gangaur Fair","Buses, Rickshaws and auto rickshaws. One has to take a Tonga a few kilometres away from Taj Mahal."));
//databaseHelper.save(new Suggestion("Agra","Taj Mahal","Agra Fort","Fatehpur Sikri","Sikandar(Akbar’s Tomb)","Jama Masjid","Mariam’s Tomb","Keetham Lake","Mughal Heritage Walk","Ram Bagh","Mehtab Bagh"));

Log.d("reading", "reading all data");
List<Place> listplace = databaseHelper.findAllp();
for (Place b : listplace) {
Log.d("data", "ID :" + b.getId() + " | City :" + b.getCity() + " | State :" + b.getState() + "Language :" + b.getLanguage() + " \n| Climate :" + b.getWeather() + " \n| Cuisine :" + b.getCuisine() + " \n| Festival and Fair :" + b.getFandf());
}

Log.d("reading", "reading all data");
List<Suggestion> listsuggestion = databaseHelper.findAll();
for (Suggestion b : listsuggestion) {
Log.d("data", "ID :" + b.getId() + " | City :" + b.getCity() + " | Place 1 :" + b.getPlace1());

}


}
public void gotoselect(View view)
{
Intent i=new Intent(this,Activity2.class);
startActivity(i);
}

public void gotoplannerinformation(View view)
{
Intent i=new Intent(this,Activity_4.class);
i.putExtra("City_Name",Message);
startActivity(i);
}

public void onaddinformation(View view)
{

listplace = (ListView) findViewById(R.id.listplace);
Place p = databaseHelper.findOnep(Message);
Suggestion s = databaseHelper.findOne(Message);
String[] ans = {"CITY:\n" + p.getCity(), "STATE:\n" + p.getState(), "LANGUAGE:\n" + p.getLanguage(), "CLIMATE:\n" + p.getWeather(), "CUISINE:\n" + p.getCuisine(), "FESTIVALS AND FAIRS:\n" + p.getFandf(), "TRANSPORT:\n" + p.getTransport(), "PLACES:", s.getPlace1(), s.getPlace2(), s.getPlace3(), s.getPlace4(), s.getPlace5(), s.getPlace6(), s.getPlace7(), s.getPlace8(), s.getPlace9(), s.getPlace10()};
adapter = new ArrayAdapter(getApplicationContext(), R.layout.custom_view, ans);
listplace.setAdapter(adapter);



}
}

Activity4.java:

public class Activity_4 extends AppCompatActivity implements AdapterView.OnItemSelectedListener {

String[] no_of_days= {"2 days","3 days"};
Spinner spinner;
String city_name;
String noofdays;

private DatabaseHelperPlanner databasehelper;
TextView text2;
TextView text3;
TextView text4;
TextView text5;
TextView text6;
TextView text7;
TextView text8;
TextView text9;
TextView text10;
TextView text11;
TextView text12;
TextView text13;
TextView text14;
TextView text15;
TextView text16;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_4);

//Spinner
spinner = (Spinner) findViewById(R.id.days);
spinner.setOnItemSelectedListener(this);
ArrayAdapter aa = new ArrayAdapter(this,android.R.layout.simple_spinner_item,no_of_days);
aa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(aa);

Bundle data=getIntent().getExtras();
if(data==null)
{
return;
}
city_name=data.getString("City_Name");

databasehelper=new DatabaseHelperPlanner(this);

Log.d("insert", "inserting data for Place");
databasehelper.save(new Planner("Ahmedabad","3 days","Day 1:","10 :00 am-Sabarmati Ashram (8:30 am- 6:30 pm)- People usually take 2 hours visiting the Ashram.",
"12:30 pm-Sabarmati River Front (6:00 am-10:00 pm)-People usually spend around half an hour here.","3:00 pm-Adalaj Stepwell (8:00 am– 7:00 pm)- People usually take 30 minutes to 1 hour to visit the Stepwell.","","","Day 2:","9:00 am-Kankaria Lake (9:00 am -10:00 pm)- People usually take an hour to visit the Lake.","11:30 am-Hutheesing Jain Temple (8:00 am -8:00 pm)- People usually take around an hour to visit the temple","2:30 pm-Bhadra Fort(9:00 am-5:00pm)-People usually take an hour to visit the Fort."
,"5:00 pm-Sarkhej Roja(9:00 am-6:00 pm)-People usually take an hour to visit the lake.","7:00 pm-Auto World Vintage Car Museum (8:00 am-9:00pm)- People spend around one to two hours here.","DAY 3:","10:00 am-Calico Museum of Textiles (10:15 am-12:30 pm (Wednesday Closed))-People usually spend two hours here.","5:30 pm- Akshardham Temple (9:30 am – 7:30 pm)-People usually take 2-3 hours to visit the Temple."));

Log.d("reading", "reading all data");
List<Planner> listplann = databasehelper.findAll();
for (Planner b : listplann) {
Log.d("data", "ID :" + b.getId() + " | City :" + b.getCity() + " | Days :" + b.getDay());
}





}

@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int position, long id) {
Toast.makeText(getApplicationContext(), no_of_days[position], Toast.LENGTH_LONG).show();
}

@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub

}

public void gototravelinfo(View view)
{
Intent i=new Intent(this,Activity_3.class);
i.putExtra("Message",city_name);
startActivity(i);
}

public void gotonextpage(View view)
{

noofdays=spinner.getSelectedItem().toString();

Planner planner = databasehelper.findOne(city_name,noofdays);

text2=(TextView)findViewById(R.id.text2);
text3=(TextView)findViewById(R.id.text3);
text4=(TextView)findViewById(R.id.text4);
text5=(TextView)findViewById(R.id.text5);
text6=(TextView)findViewById(R.id.text6);
text7=(TextView)findViewById(R.id.text7);
text8=(TextView)findViewById(R.id.text8);
text9=(TextView)findViewById(R.id.text9);
text10=(TextView)findViewById(R.id.text10);
text11=(TextView)findViewById(R.id.text11);
text12=(TextView)findViewById(R.id.text12);
text13=(TextView)findViewById(R.id.text13);
text14=(TextView)findViewById(R.id.text14);
text15=(TextView)findViewById(R.id.text15);
text16=(TextView)findViewById(R.id.text16);
text2.setText(planner.getOne_view());
text3.setText(planner.getTwo_view());
text4.setText(planner.getThree_view());
text5.setText(planner.getFour_view());
text6.setText(planner.getFive_view());
text7.setText(planner.getSix_view());
text8.setText(planner.getSeven_view());
text9.setText(planner.getEight_view());
text10.setText(planner.getNine_view());
text11.setText(planner.getTen_view());
text12.setText(planner.getEleven_view());
text13.setText(planner.getTwelve_view());
text14.setText(planner.getThirteen_view());
text15.setText(planner.getFourteen_view());
text16.setText(planner.getFifteen_view());
}
}



The logcat shows the following error on running the app on device.



E/FirebaseInstanceId: Failed to resolve target intent service, skipping classname enforcement
E/FirebaseInstanceId: Error while delivering the message: ServiceIntent not found.

在虚拟模拟器上运行同一应用程序时,该应用程序可以正常运行。最初我没有添加意图过滤器,但是即使将它们添加到 list 文件后,该应用也无法在设备上运行

最佳答案

您需要像这样在 list 中定义服务类:

    <service
android:name=".MyFirebaseInstanceIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>

关于android - 无法在设备上运行应用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45126193/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com